Connecting a DC motor using an H-bridge and Arduino

The next step is to add a bit more functionality with a new type of chip, an H-bridge. An H-bridge is a fairly simple device. It basically consists of a set of switches and adds the additional functionality of allowing the direction of the current to be reversed so that the motor can either be run in the forward or the reverse direction.

Let's start this example by building the H-bridge circuit and controlling just one motor. To do this, you'll need an H-bridge. One of the most common is the L293 dual H-bridge chip. This chip will allow you to control the direction of the DC motors. These are available at most electronics stores or online. You'll also need a capacitor; you can use the 1 microfarad capacitor from the previous example, if you'd like. The capacitor limits the fast changes in the signals that are sent to the motor. Once you have your H-bridge, build the following circuit with Arduino and a breadboard:

Connecting a DC motor using an H-bridge and Arduino

The following table shows Arduino and H-bridge pins and you should connect the pins on Arduino to the pins on the H-bridge:

Arduino pin

H-bridge pin

9

1

4

2

3

7

Once you have the connections, you can test the system. To do that, you'll need to add some code to the code you typed in for example 1.

Using Arduino code to control the direction of the DC motor

Open the Arduino IDE and type in the following code:

Using Arduino code to control the direction of the DC motor

This code sets up the three pins 3, 4, and 9 to enable the chip and control the direction of the motor. As you did earlier, you can navigate to Tools | Serial Monitor to send data to the program. Sending a value of 0 sets pin 3 to HIGH and pin 4 to LOW, causing the motor to spin in one direction. Sending a value of 1 sets pin 3 to LOW and pin 4 to HIGH, causing the motor to spin in the other direction.

Now, you know how to build circuits to control both the speed and the direction of DC motors. However, instead of procuring all the parts and building the circuits yourself, you can buy a DC motor control shield.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.199.112