How-To #7: Assemble an H-bridge Circuit Board Making a DC motor turn is relatively easy: simply connect the motor's terminals to a power supply. But what if the motor is to be controlled by an Arduino, and what if that motor requires more current at a higher voltage than the Arduino can deliver? For this we use the H-bridge, a device under the control of two digital pins that can turn a motor on and off and set its direction. Further, if one of these pins is capable of pulse-width modulation, the H-bridge can also control the speed of that motor. In this How-To we assemble an H-bridge that brings the ability to control two DC motors to the Motor Controller Shield of How-To #3, simply by plugging it in. Figure HT7-1. H-bridge circuit board HT Background: The DC motors this H-bridge can control are common, inexpensive, and extremely useful. They are "brushed" motors, meaning each is composed of a coil of wire inside a magnet. When electrical current is run through the wire a magnetic field is created that opposes the field of the permanent magnet, causing the coil to move. How such a motor works is described and illustrated on Wikipedia at https://en.wikipedia.org/wiki/brushed_dc_electric_motor#simple_two-pole_dc_motor. An Arduino can directly control such a motor, provided the motor requires about 5 volts and very little current. Most useful motors, however, are designed for higher voltages and currents. The motors used in the lessons in this book and the companion website (LearnCSE.com), for example, run best at six volts and draw between 0.15 and 0.4 amps, depending on how much work they are attempting. An H-bridge connects a DC motor to an appropriate power supply but does it in such a way that a pair of Arduino digital pins can turn that power on and off, and set the polarity, thus setting the spin direction. How-To #7 Assemble an H-bridge Circuit Board 257
Figure HT7-2. H-bridge control of a DC motor The values of the Arduino pins turn the DC motor on or off and set the directions, as shown in Table HT7-1. Table HT7-1. Motor direction as a function of inputs to MC pins MC1 MC2 Motor HIGH HIGH Stopped HIGH LOW Spins one direction LOW HIGH Spins reverse direction LOW LOW Stopped 258 Learn to Program in Arduino TM C: 18 Lessons, from setup() to robots
Description: The heart of the H-bridge circuit board built here is the L293 integrated circuit. The pinout for these is in Figure HT7-3. HT Figure HT7-3. Pinout of L293 integrated circuit Notice how each side of this integrated circuit controls one motor from a pair of Arduino pins. Pins 1 and 9 can be used to enable and disable their respective motors. For this circuit board we permanently enable both motors by connecting these pins to +5 volts. Important The notch at the top indicates the end of the integrated circuit close to pin 1. Use this notch to orient the circuit with the circuit board. Reversing it will result in an H-bridge circuit board that cannot function. Building or Buying the Circuit Board The raw circuit board used here is double-sided. It has been designed for ease of assembly by using large traces for easy soldering. It can be obtained in the following ways: 1. Buy it directly from LearnCSE.com. The board can be purchased by itself or as part of a kit containing all the other necessary components. 2. Do-It-Yourself fabrication. The Fritzing (www.fritzing.org) project file is available for download from LearnCSE.com. The Fritzing application can print accurately scaled masks for each side of the board. 3. Have the board commercially made by a board fabricator such as OSH Park. Instructions for submitting a Fritzing-designed board to OSH Park can be found on LearnCSE.com. How-To #7 Assemble an H-bridge Circuit Board 259
Procedure: Where to get the parts Begin by assembling the materials. Among the options for finding these parts are: 1. Buy a kit of parts directly from the LearnCSE.com store. If you are also purchasing the prefabricated circuit board, both the board and the parts can be purchased as a kit. 2. Purchase each part from various suppliers. Look up each item in the LearnCSE.com Parts Catalog via the catalog number in the Materials table. The catalog provides a source and, usually, the source's part number. Materials: Quantity 1 Arduino Uno 1 USB Cable Part Image Notes Single-board computer. This board is delicate and should be handled with care. When you are not using it, keep it in a box or plastic bag. This is a standard USB adapter cable with a flat connector on one end and a square connector on the other. Catalog Number 3102 2301 1 Circuit board Purchase from LearnCSE. com or DIY. PCB505 1 H-bridge integrated circuit, L293 Dual-inline pin. UI 1307 2 Resistor, 220 ohm (red-red-brown) R1, R2 0102 2 Screw Terminal 2 position, J2, J3 4108 260 Learn to Program in Arduino TM C: 18 Lessons, from setup() to robots
Quantity Part Image Notes Catalog Number 2 Red / Green bi-color LED 2 lead, LED1, LED2 1310 1 Male header, 12 pin J1. 2204 Steps 1. Familiarize yourself with the parts. Be sure you recognize each part and know where it goes on the circuit board. In the image on the materials list, the circuit board is green, but the actual color will depend on where the board itself was made. Still, the white outlines and lettering are always the same. HT Important All parts are inserted on the top of the raw board and soldered on the bottom except the male header. It is inserted from the bottom of the board and soldered on the top. 2. Begin by placing the integrated circuit on the top of the circuit board, taking care to align the notch on the top of the board to the gap in the white rectangle drawn on the board, as shown in Figure HT7-4. Solder the integrated circuit in place from the bottom. Figure HT7-4. Pin soldered to integrated circuit How-To #7 Assemble an H-bridge Circuit Board 261
3. Insert and solder the two 220 ohm resistors. Trim excees leads from the bottom. Figure HT7-5. Resistors soldered 4. Insert and solder the two screw terminals. Figure HT7-6. Screw terminals soldered 5. Prepare a 12-pin male header as shown in HT7-7. Figure HT7-7. 12-pin male header 262 Learn to Program in Arduino TM C: 18 Lessons, from setup() to robots
6. Insert the male header through the bottom of the circuit board and solder on the top. HT Figure HT7-8. Header inserted into circuit board, then soldered The H-bridge, as shown in HT7-9, is now complete. Check for good solder connections and remove any solder that bridges connections. Figure HT7-9. Complete H-bridge How-To #7 Assemble an H-bridge Circuit Board 263
264 Learn to Program in Arduino TM C: 18 Lessons, from setup() to robots