DC motor control (reverse engineering that old toy pt.2)

Since I had the electronics worked out the last time it was now time take this thing one step further and add some control to it. I first made sure the software in the Arduino controlling the DC motors was able to listen to its serial port for incomming commands and afterwards control the motors according to the command that it received. I made sure I had a second Arduino board available and by using XBee modules I could now send commands from my pc wireless over the ZigBee network to my remote Arduino controlling the DC motors.

Next I found myself a XBOX 360 controller and because it has dual joysticks it can control both DC motors, one joystick for each motor. This one I hooked up to my laptop and next I wrote a small interfacing program in Java that translates the XBOX360 code into commands that are being accepted by my Arduino program controlling the motors.

The result:

 

DSC05979Sketch:

sketch_final

Advertisements

DC motor control (reverse engineering that old toy pt.1)

Since my return home I’ve been doing some paperwork and other ridiculous stuff, catching up the last 6 months and off course going to the 10 day festival that is yearly organised in my Belgian home town. But then I stumbled upon one of my first electronic kid toys ever, a Raccoon RC car that was in really bad condition. It has 6 tires/wheels of which only 4 are left over and off course the remote control is missing too. So no fun, unless… And so I decided to revive this toy, not because I like RC cars that much, just because off having something to do during the day-hours of the festival (and to recover from parties the day before).

Because of the remote control missing I had to reverse engineer the current circuit board inside the car. Unfortunately, the toy is like 30 years old and so off course the toy is based upon analogic components instead of digital ones, and off course with the datasheets of some components are missing. Great! Though it did not hold me back to start measuring around and understanding what kind of voltage and current levels are involved in driving the motors, because when you get that there is not much more holding you back from throwing in an Arduino or Raspberry Pi for example to do the rest of the task.

The car architecture is as following: the car has/had 6 wheels, 3 on each side and each side of wheels is driven by one DC motor, so there are 2 motors in total. The car has no wheel that can turn so the only way of making corners is by having different speed on the wheels for each side. If the left wheels are turning slower than those on the right, the car will turn left. Off course!

DSC05950

From my measurements I found the motor control circuit to look something like this:

h-bridge_schematics_old
(click to enlarge)

The two horizontal resistors central in the picture are the motors M1 and M2. From my first drawing things looked way too complicated, but after reading up a bit about DC motor control through H-bridge NPN and PNP transistor configurations I noticed they did exactly the same thing in this circuit. If you’re not common with H-bridge configurations read up a bit:
http://www.instructables.com/id/H-Bridge-on-a-Breadboard/step2/H-Bridge-Theory/

What is so different here to most schematics is that 2 motors are driven from the same circuit. For one motor you need 4 NPN transistors (or 2 NPN + 2 PNP transisotors: http://letsmakerobots.com/node/9450) and probable you would repeat the same configuration for adding a second motor. But the above on is also working, but you must keep in mind two things:
1) both of your motors should always go into the same direction. You can’t make M1 turn your left wheels to the front and make M2 drive your right wheels in the opposite direction because then both transistor in the middle of the schematic (Q7 and Q10) will be made conductive and so you will create a short between Vcc and ground resulting in white smoke and popped transistors!
2) The transistors in the middle need to conduct both the current from M1 and M2 when both motors are used, make sure that the transistors are rated for the expected amount of current. So far example, if you want to drive forward one should make Q6 and Q8 conducting and also Q10 in the middle. While Q6 and Q8 handle the current for their motor only, the current comes together at returns leads from each motor and is than flowing into Q10 which should so be able to handle both currents together.

As far as 1) goes, that is something I can handle in software (Arduino). For 2) I made sure to reuse the original design in some way but adapt it to my own needs. The transistors were rated good enough for the old circuit so they should be good enough now too. Also note in the above schematic the potentiometer on top which allows one to correct the differences in motors speed as one motor will never be exactly the same as the other one.

h-bridge_schematics_new
(click to enlarge)

The main setup didn’t change much, overall the NPN transistor H-bridge remained but now the transistor are controlled by Arduino pins. For each pin I first had 22k resistors connected to the transistor base but later I swapped these to 1k resistors as the transistors that I have never came to conduct. A breadboard sketch would look like this:

sketch

I however soldered mine because my breadboard is still in use for some other project. Note that in the image above the transistor has the base as the center pin. This is however different to the C3279 transistors I’m using where pin 2 is the collector. Also note that the Fritzing drawing tool does not support a socket for 3 batteries so that’s why there are 4 here. In real life 4 batteries would however result in 5,33~6 Volts depending on the batteries you choose resulting in more power from the motors (and more current through the transistors).