Motor driver decisions
There are so many types of motor driver to choose from. The easiest decision was whether it was a DC motor driver or a stepper motor driver. I am using the cheap Chinese yellow DC motors, so DC motor driver it is. In my part box I had several motor drivers at my disposal.
- L293D
- L298N
- Cytron 10A 5-30V Dual Channel DC Motor Driver
- Dagu Arduino Mini Driver Board
I ruled out the Cytron controller, this is large and way over spec’ed for the motors I’m using. It is a very nice driver though. We have used it in the Ipswich Makerspace PiWars entry for the past three years. I ruled out the L298N driver, these are nice and little, easy to use, but the pin out is hard to use with strip board. The Dagu controller was interesting, this is what came with the robot chassis I’ve stripped down. It is an Arduino compatible board complete with built in motor driver. I was very tempted to use this, but documentation is hard to come by. I eventually decided not to use this. I did not want to be messing about trying to understand how this worked, I’d rather deal with stuff I’ve used before and understood. I’m sure I’m gong to get stuck many times on this journey, but I did not want to be wasting time just trying to get this board working.
So I chose to use the humble L293D. I’ve used this before and understand it well, it was also ideally suited to the motors I’m using and it’s nice and small.
How to drive the L293D?
The L293D is a dual H bridge driver. It has the following connections
- Power for logic - 5v
- Power for motors, I’m using 7.2v - 9v
- Ground
- 2 x H bridge, both of which have the following connections
- Enable
- Input A
- Input B
- Output A
- Output B
The motor is connected to the outputs and the inputs are driven by a micro controller. To drive a motor, one input must be high and the other must be low. Also the enable pin must be high. To reverse the motor just switch the inputs, so low becomes high and high becomes low.
To control the speed of the motor, the high input pin can be a PWM signal, again if reversing the motor the other input pin needs a PWM signal. So to drive two motors both at variable speeds with the enable pins permanently wired to 5v, only four PWM pins are needed.
The Arduino Pro mini does not have many PWM pins, so I’m going to use it slightly differently. It will take six pins but will only need two PWM pins. To do this I will drive the enable pins with PWM signal to control the speed of the motors. The direction will be controlled with the two input pins, by setting them either high or low.
Here is my setup of the L293D motor driver and Arduino.