Wednesday, July 23, 2014

Robot - Motor Driver

This post is the first in a series of posts outlining the components needed to get a tank chassis robot up and running.

A motor driver is needed for the Arduino to control the robot's DC motors, because the Arduino is not capable of supplying the current necessary to drive two DC motors. We used the TB6612FNG. The motor driver and the motors are powered by 5 AA batteries.

Parts Needed

  1. Arduino
  2. TB6612FNG (or any motor driver)
  3. Two DC motors
  4. 5 AA batteries (or any power source up to 15 V)

Putting It Together

For now, power the Arduino over USB, and connect the following motor driver pins:

PWMA --> Arduino pin 5 (PWM)
AIN2 --> Arduino pin 8
AIN1 --> Arduino pin 7
STBY --> Arduino pin 3
BIN1 --> Arduino pin 12
BIN2 --> Arduino pin 4
PWMB --> Arduino pin 6 (PWM)

VM  --> 5 AA batteries +
VCC --> Arduino 5V
GND --> 5 AA batteries -
A01 --> Motor A +
A02 --> Motor A -
B01 --> Motor B +
B02 --> Motor B -

Note: You must use PWM pins 5 and 6 on the Arduino if you plan on using the VirtualWire library. VirtualWire does not use any timers associated with PWM pins 5 and 6.

A useful schematic can be found here. Note that some of the digital pins differ. My code is written to reflect the above pin configuration, not the schematic.

Motor Driver Pins

Here's a brief explanation of what the motor driver pins do, and how manipulating them with the Arduino will change motor speed and direction.

Pins PWMA and PWMB control their respective motor's speed. They take values from 0-255. Use the analogWrite function to output a pulse-width modulation signal. The higher the frequency, the higher the motor speed.

Pins AIN1, AIN2 control the direction of motor A. Using the digitalWrite function and setting one pin to HIGH and the other to LOW will spin the motor in a particular direction. To change direction, reverse the pin settings. Pins BIN1, BIN2 operate the same way but control motor B.

The STBY pin is the "go" signal for the motors. After setting the speed and direction of the motors, set STBY to HIGH. To stop, set STBY to LOW.