Skip to content

Motor x4 TinyShield (OBSOLETE) Tutorial

The TinyShield Motor x4 Board lets a 4 DC brushed motors be driven from your project. You can also use this to drive other loads, like a stepper motor, solenoids or relays.

For this tutorial, we will be driving a single motor with varying direction and speed.

To learn more about the TinyDuino Platform, click here


Technical Details

Written description of what the board does, typically links back to product page somehow.

To see what other TinyShields are compatible with this TinySheild, see the TinyShield Compatibility Matrix

Technical Details Pins Used
  • External High Current Connections:
    • VM: Motor Voltage Input - This supplies the voltage to the motor and can range from 1.8 to 11 Volts.
    • GND: Ground Connection - This is the Ground return for the motors. It is also connected to the ground for the TinyDuino logic.
    • Motor1: Motor 1 Connection - These are the Motor 1 output driver connections, connect these two pins to the two sides of the motor winding. The pin with the square pad is the O1 output and the other is the O2 output.
    • Motor2: Motor 2 Connection - These are the Motor 2 output driver connections, connect these two pins to the two sides of the motor winding. The pin with the square pad is the O1 output and the other is the O2 output.
    • Motor3: Motor 3 Connection - These are the Motor 3 output driver connections, connect these two pins to the two sides of the motor winding. The pin with the square pad is the O1 output and the other is the O2 output.
    • Motor4: Motor 4 Connection - These are the Motor 4 output driver connections, connect these two pins to the two sides of the motor winding. The pin with the square pad is the O1 output and the other is the O2 output.
  • TinyShield Signals:
    • A3: Sleep Input - This signal can put the motor controller into a low-power “Sleep Mode”. A logic-low “0″ will put the motor controller into sleep mode, a logic-high “1″ will put the motor controller into normal operating mode. If sleep mode is not needed, set A3 to HIGH to allow normal operation.
    • 2: Motor1 Dir - This signal controls the Motor 1 Output 2 driver. A logic-low “0″ will set Output 2 to low, a logic-high “1″ will set Output 2 to high. For motor speed control, we recommend using this as the direction speed control signal, and 3 as the motor speed control signal.
    • 3: Motor1 PWM - This signal controls the Motor 1 Output 1 driver. A logic-low “0″ will set Output 1 to low, a logic-high “1″ will set Output 1 to high. For motor speed control, we recommend using this as the motor speed control signal (Using a PWM signal), and 2 as the motor direction signal.
    • 4: Motor2 Dir - This signal controls the Motor 2 Output 2 driver. A logic-low “0″ will set Output 2 to low, a logic-high “1″ will set Output 2 to high. For motor speed control, we recommend using this as the direction speed control signal, and 5 as the motor speed control signal.
    • 5: Motor2 PWM - This signal controls the Motor 2 Output 1 driver. A logic-low “0″ will set Output 1 to low, a logic-high “1″ will set Output 1 to high. For motor speed control, we recommend using this as the motor speed control signal (Using a PWM signal), and 4 as the motor direction signal.
    • 7: Motor3 Dir - This signal controls the Motor 3 Output 2 driver. A logic-low “0″ will set Output 2 to low, a logic-high “1″ will set Output 2 to high. For motor speed control, we recommend using this as the direction speed control signal, and 6 as the motor speed control signal.
    • 6: Motor3 PWM - This signal controls the Motor 3 Output 1 driver. A logic-low “0″ will set Output 1 to low, a logic-high “1″ will set Output 1 to high. For motor speed control, we recommend using this as the motor speed control signal (Using a PWM signal), and 7 as the motor direction signal.
    • 8: Motor4 Dir - This signal controls the Motor 4 Output 2 driver. A logic-low “0″ will set Output 2 to low, a logic-high “1″ will set Output 2 to high. For motor speed control, we recommend using this as the direction speed control signal, and 9 as the motor speed control signal.
    • 9: Motor4 PWM - This signal controls the Motor 4 Output 1 driver. A logic-low “0″ will set Output 1 to low, a logic-high “1″ will set Output 1 to high. For motor speed control, we recommend using this as the motor speed control signal (Using a PWM signal), and 8 as the motor direction signal.

Notes

  • Warning: Be sure that your power supply is sufficient to operate these motors as well as your logic – batteries are the best. If you are running both the motors and the logic off of one power supply, we recommend avoid using a switching power supply as the transients caused can potentially damage items connected to the logic side.

Materials

Hardware

Software


Hardware Assembly

For our battery to power the motor, we’ll be using three AAA alkaline batteries (which will give us an operating voltage range of 3 – 4.5 Volts). The batteries will supply the voltage to both the motor power supply (VM) and the logic power supply (VCC).

In this set up, the TinyDuino processor will be able to control the motor speed on digital pin #3 by using the Arduino analogWrite() command. This will send a PWM signal to the IN1 signal on the motor controller for the speed control. Direction is controlled by digital pin #2 on the Arduino and is connected to IN2 on the motor controller.

WARNING: Before continuing, note that your batteries should not be hooked up to your circuit while the USB cable is plugged into the computer from the USB TinyShield. This is to avoid damage to both your computer and TinyDuino.

First, connect up the TinyDuino, USB TinyShield, and Motor x4 TinyShield. Next, add a wire between the GND pin on the Motor x4 TinyShield to the negative terminal on the battery holder. Then add a wire between the VM pin on the Motor x4 TinyShield to the positive terminal on the battery holder. Now add a wire between the positive connection on the battery holder and the ‘+’ hole on the TinyDuino processor Board. This will connect the VM and VCC power supplies together. Finally, add two wires from the MOTOR1 terminals to two sides of the motor.

Plug a MicroUSB cable into the micro USB port (or USB shield) and then plug the cable into an available USB port on your computer. Make sure the processor is switched on. Now you're ready to upload the code!


Software Setup

Upload Program

After uploading the following code, disconnect the USB cable from the USB TinyShield and put the batteries into the holder.

Code
int motorDirPin = 2;      // Motor direction connected to digital pin 2
int motorSpeedPin = 3;    // Motor speed connected to digital pin 3
int motorSleepPin = A3;      // Motor sleep to analog pin 3

void setup()
{
  pinMode(motorDirPin, OUTPUT);       // sets the pin as output
  pinMode(motorSpeedPin, OUTPUT);     // sets the pin as output
  pinMode(motorSleepPin , OUTPUT);     // sets the pin as output

  digitalWrite(motorDirPin, LOW);     // sets the default dir to be forward
  digitalWrite(motorSpeedPin, LOW);   // sets the default speed to be off
  digitalWrite(motorSleepPin , HIGH);   // sets the sleep mode to be off
}

void loop()
{
  // Set the motor direction to forward
  digitalWrite(motorDirPin, LOW);     

  // Ramp the motor speed up
  analogWrite(motorSpeedPin, 0);    // Min speed forward (motor off)
  delay(50);  
  analogWrite(motorSpeedPin, 63);   
  delay(50);  
  analogWrite(motorSpeedPin, 127);   
  delay(50); 
  analogWrite(motorSpeedPin, 191);   
  delay(50); 
  analogWrite(motorSpeedPin, 255);   // Max speed forward
  delay(50); 

  // Ramp the motor speed down
  analogWrite(motorSpeedPin, 191);   
  delay(50);  
  analogWrite(motorSpeedPin, 127);   
  delay(50);  
  analogWrite(motorSpeedPin, 63);   
  delay(50); 
  analogWrite(motorSpeedPin, 0);     // Min speed forward (motor off)
  delay(50); 


  // Set the motor direction to reverse
  digitalWrite(motorDirPin, HIGH);   

  // Ramp the motor speed up
  analogWrite(motorSpeedPin, 255);    // Min speed reverse (motor off)
  delay(50); 
  analogWrite(motorSpeedPin, 191);   
  delay(50);  
  analogWrite(motorSpeedPin, 127);   
  delay(50);  
  analogWrite(motorSpeedPin, 63);   
  delay(50); 
  analogWrite(motorSpeedPin, 0);      // Max speed reverse
  delay(50); 

  // Ramp the motor speed down
  analogWrite(motorSpeedPin, 63);   
  delay(50);  
  analogWrite(motorSpeedPin, 127);   
  delay(50); 
  analogWrite(motorSpeedPin, 191);   
  delay(50); 
  analogWrite(motorSpeedPin, 255);    // Min speed reverse (motor off)
  delay(50); 
}

This example shown below will cause the motor to ramp up speed, then ramp down speed, and change direction.

NOTE: When in the forward direction, the slowest speed is set with an analogWrite() value of 0 and a max speed with a value of 255, when in the reverse direction, the slowest speed is set with an analogWrite() value of 255 and the max speed with a value of 0.


Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads