Bring old toys back to life with Arduino

Chipped Out

Of course, building your own H bridge from scratch for each motor is impractical. First, you'd need a massive breadboard to make them all fit. Then what? Have Robosapien drag it around in a cart? Second, the chance of getting something wrong is immense. Third, it would use so much power, what with leakage and all, that you wouldn't have enough to run the motors.

No, there's a better way, and that's getting hold of some H-bridge-on-a-chip chips. The L293D (Figure 13) family of chips implements two H bridges on each chip (see the "Chips on the Breadboard" box). They cost literally cents and are so common, you can buy them from any electronic component store. These are your best bet to drive a motor and control its speed and direction.

Chips on the Breadboard

I didn't realize this when I started this project, but the legs on chips of the L293D and the MCP23017 I am using for this project are incredibly fragile. You must plug them into the breadboard with the utmost care, making sure that the legs are aligned perfectly with the holes.

Extracting a chip with your fingers will bend the legs, and bent legs will break when you try to straighten them. To get them out with some guarantee of re-using them, you will need something called a chip puller, which you can probably buy for about a dollar from the same place you bought your chips.

That said, the best advice is to make sure you plug your chips into the breadboard only when and where you need them and leave them in place for the duration of the project.

Figure 13: An L293D motor driver chip implements two H bridges – one on each side – that you can use to control two motors.

This setup would look something like that shown in Figure 14, with 5V connected to the outermost legs, the controlling inputs from pins 9 and 10 connected to the second set of pins moving inward, and, moving inward again, the next pair of legs connected to the motor. Finally, the innermost legs connect to GND.

Figure 14: The setup for a DC motor connected to an L293D motor driver chip.

To run a second motor, you would do the same on the other side of the chip and connect two other PWD pins (e.g., 11 and 12) to the chip.

The sketch to try out something like this is exactly the same as that used for the hand-made H bridge (Listing 4).

Moving Forward

Having reached this point, you might have noticed a scalability problem with the current setup. As mentioned at the beginning of this article, the Robosapien has seven motors and each must be spun forward and backward to walk, move its arms, and open and close its claws. That means that each motor needs the input from two PWM pins. That's 14 pins. However, most Arduinos only have 13 pins, and I haven't even started to consider feedback from Robo's sensors or controlling the LEDs and speaker. If I just plow on, I'm going to run out of pins really, really soon.

Don't fret, I'll tackle this problem in the next issue, when I show you how to use a chip as a port expander and how this affects the way you program the robot. I will also show you how to read from Robosapien's default sensors, and how you can mod your robot on the cheap to make it a bit more aware of its environment.

Until next time, have fun.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Bring old toys back to life with Arduino: Part II

    Robotics are all the rage, and those old high-tech toys you might have lying around are ideal candidates for the Frankenstein/Arduino treatment.

  • Digital – Analog – Mechanical

    As innovative companies consistently push the envelope of progress, antiquated hardware nearly two years old falls by the wayside. We take an old iPad, an Arduino Mega, and various other materials to create an in-dash climate control app.

  • Managing solar power systems with SunAir boards

    A successful solar power project requires data analysis and the ability to modify the system to take advantage of prevailing weather conditions.

  • Control your littleBits projects with a homemade wireless remote

    Make a custom handheld wireless remote control with littleBits Wireless Transmitter and Receiver bits and slider, knob, button, or toggle bits.

  • Infinite Possibilities

    The open hardware movement continues to add, improve, and reinvent itself. No sooner did the Raspberry Pi Model B+ come on the scene, than the Raspberry Pi 2 debuted, adding a "1" to the name of all Rasp Pis that came before. Faster, smaller, and smarter devices appear almost daily, inspiring makers as they address ever more diverse real-world problems.