Electronic – arduino – Motor control with an Arduino Uno… Is it possible (and safe)

arduinodc motormobile robotroboticsservo

I have an Arduino Uno and an inexpensive RC jeep with a functional DC motor and front-wheel turning servo, but I don't have an Ardumoto shield to control it (yet).

I'd really like to learn if it's possible and safe for my Arduino Uno (from back-EMF) to build a circuit to control it with the Arduino Uno, using some switching mechanism to power the motor separately from the Arduino Uno's 5 V.

I discovered the motor takes (I believe) a maximum of 6.8 V by connecting it to a 9 V battery (its label says it takes 9.6 V for the entire vehicle, including the front wheel servo and some LEDs). I connected the battery via my breadboard with an SPST mini switch and read the voltage with my meter. The motor has 8 ohms of resistance, so I figure it's pulling 0.85 A / 5.78 W.

I have some 741 and LM324 op-amps, some 1N4001 and Zener diodes, a variety of NPN and PNP transistors, including some TIP120 Darlington transistors, and several capacitors.

Could I use some combination of them to power the motor and servo while protecting the Arduino Uno from back-EMF? If not, I will order the Ardumoto.

If it helps, pictures of the jeep with tagged closeups of the stock motor/servo controller are here:

http://www.flickr.com/photos/tommytwoeyes/sets/72157627827980121/

I've googled this extensively and also asked about it on Reddit. No disrespect to those guys, because their answers were awesome. But there was so much information between various sites and different posts on the subreddit, that it was a bit overwhelming and occasionally conflicting. I am just trying to learn and identify the best solution.

Best Answer

Given that you can replace the arduino for under $30 (or for about $5-6 if the atmega chip is socketed, or a mere $3.50 for a blank atmega you can initialize on a breadboard using the arduinoISP sketch before you fry the current one), if you are more interested in learning about things, I'd say go ahead and build some driving circuits. On the other hand, if you just want to "make it go" buy someone's driver shield or serial-controlled driver module.

As an aside, "9v" batteries have very little current capacity and are not intended for motors - using one with a motor will cause it's voltage to sag severely, and it will run down quickly. Most of the components in your toy are connected in parallel - the 9.6v battery (probably consisting of 8 AA-size NiCd or NiMH cells) probably powers the drive motor directly, and the servo and perhaps electronics through a voltage regulator of about 5 volts (at least if they are standard parts). You should probably keep that scheme.

There are some things you can do to "protect" the arduino such as using opto-isolators (essentially an LED and a phototransistor molded in an IC-like package - you can make your own with discrete parts and heat shrink tubing) to transfer signals between the arduino (or radio receiver) and the servo and drive motor without their being any electrical connection between the two - each in that case requiring its own battery. However, most budget equipment simply relies on careful design and filters to suppress spikes, supply noise, and RFI. Amongst things you will see in R/C vehicles:

  • small capacitors across the terminals of motors, and/or between each terminal and the motor case

  • if the motor is unidirectional, a reversed diode across the terminals, if it is bidirectional four reversed diodes between the two motor terminals and two battery terminals.

Most likely you can work out a solution running everything off the same battery if you power the motor directly, run the servo off of its own 5v regulator, and run the arduino off of its on-board 5v regulator. Alternatively, you can give the arduino its own battery (perhaps 3 AAA's if you bypass the regulator) and establish a common ground connection between that and the motor/servo battery.

In terms of driver circuits for the main motor, the big question is if you are okay with forward only, or if you need forward and reverse. Related questions are PWM duty cycle speed control, electronic braking, and efficiency.

For a small toy with forward-only, you can simply use an medium sized NPN transistor as a switch in the negative lead (emitter to battery -, collector to motor -), with the base connected via a resistor to an arduino pin. A pragmatic approach would be to start with a large resistor such as 10K ohms and reduce the resistance just until the voltage drop across the transistor is reduced to about .6v - implying it is fully "on" and most of the battery voltage is available to the motor.

Doing forward-reverse control is more complicated - typically accomplished with an "H bridge driver" in which each leg of the motor can be connected to the negative battery terminal via an NPN transistor or the positive terminal via a PNP. Two control pins are required - 01 is one direction of rotation, 10 the other, while 00 and 11 both stop the motor. Building H bridges is a bit tricky - you have to be sure that the biasing is such that the NPN and PNP transistor on a side can't both be on at once and short out the power supply, but there are packaged solutions such as the L293 and L298 (which handles two motors).

Bipolar transistors do have substantial loss at low voltages, so higher performance vehicles typically use MOSFETs, but these are trickier to work with (especially in an H bridge configuration) and handle (they are subject to damage from static or overvoltage).