How to use an H-bridge with an Arduino
An H-bridge is a handy way to control a motor so that it can be made to go in one direction and the other. You can build an H-bridge from scratch using 4 transistors and 4 switches, but it’s a lot easier to use an integrated circuit H-bridge and Arduino
If you want to understand how the H-bridge works, look at the H-bridge theory section at the end.
It is easy to make a mistake and damage your Arduino. Before turning anything on, double check your circuit or, ideally, ask someone else to check it for you. Don’t tell them what you meant to do, let them check the circuit with no assumptions.
When you do turn on the circuit, place your finger on the H-bridge. If it’s too hot to touch, something is wrong and you should turn it off right away.
H-bridge on a chip
- L293D dual H-bridge datasheet
- Consists of two H-bridges in one chip
- Separate pins for positive voltage (the negative voltages both go to ground):
- logic voltage, which is delivered to the +v pin and must be 5V
- Motor voltage, which can be different (look at the datasheet to see the range allowed)
Controlling the H-bridge with momentary switches
This is a good way to understand what the H-bridge can do for you. The momentary switches will later be replaced by Arduino, but for now you will take the place of the Arduino by pressing the switches yourself.
Note a couple of simplifications in this circuit:
- The Enable pin is permanently tied “high”, i.e. to 5V. This means that the motor is always enabled. Later we will learn that you might want to control this pin. In particular, the Enable pin can be used to modify the speed of the motor.
- +Vmotor, the positive voltage to the motor, is 5V, although it could have been a different voltage. In contrast, the logic voltage, which is delivered to the +v pin, must only be 5V
Now use Arduino instead of the switches. Note that we’ve removed the switches and the resistor switches, and connected the L293D control pins (Enable, In1, and In2) to Arduino pins. The following additional changes have been made:
- The Enable pin is now connected to the Arduino, allowing us to control the speed of the motor
- Vmotor is connected to an external battery, allowing us to provide a different voltage to the motor. In the drawing below it is a 3 volts coming from two AA batteries, but it could have been a different battery, such as a 9V battery. Be very careful to keep the motor voltage separate from the logic voltage, and pay close attention to which is which. Applying 9V to Arduino will probably destroy it.
You will have to write your own program to make the motor turn
- To enable motor to go: Enable = HIGH
- To turn one way: In 1 = HIGH, In 2 = LOW
- To turn the other way: In 1 = LOW, In 2 = HIGH
Using the other half of the H-bridge
To use the other half of the H-bridge, connect a second motor and the rest of the control pins like this:
Note that in this case the motor is controlled by Arduino pins 7, 8, and 9.
Here is a schematic showing both motors. Since there are so many wires, the wires to the right half of the H-bridge have been left off, with labels indicating where they should connect:
In this case the left half of the H-bridge is controlled by pins 6, 7, and 12, while the right half of the H-bridge is controlled by pins 2, 3, and 4.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.