PROJECT - CONTROLLING A MOTOR - FORWARD AND REVERSE SWITCHING

Objective: drive a small motor in forward and reverse directions without relays

You will need: Arduino UNO (or similar), a suitable DC motor, Texas Instruments L293D H-bridge IC, breadboard and male-male breadboard patch cables.

INTRODUCTION

Picture of small DC motor

This project will show you how to control the rotational direction of a small motor without using any mechanical relays. The Texas Instruments L293D dual H-bridge IC has two separate control circuits and can control two conventional DC motors or one stepper motor. In this project we use one half of the IC to drive a single DC motor.

The Arduino sketch controls the motor by setting the voltage on two of its output pins. These in turn connect to the inputs of the L293D, which controls the motor. With the two output signals from the Arduino there are four possible values:

Fritzing diagram of connections

I have tried to avoid the temptation to use forwards and reverse because these words are too prescriptive and the direction of the motor clearly depends on how you have connected it up and how you define true forward and reverse for your application. The connections between the Arduino, breadboard, IC and motor are shown here. You can find the specification for the L293D IC on the Texas Instruments website. For a more precise diagram on exactly how to connect the L293D, please have a look at here.

In some circuits you will see the +5V and Enable pins connected together. This is not recommended because the output is always enabled and there could be circumstances when the IC shorts out the +5V and 0V when it switches the output polarity. It is good practice to keep the Enable pin separate so that the sequence is: disable output; switch polarity; enable output. Another reason to keep the Enable pin separate is that it operates on logic voltages of typically +5V while the supply voltage for the motor can be up to 36V.

Exclamation mark

If you are driving a motor with significant inertia, you may find that you need to switch off the motor and allow it to stop before reversing its direction, otherwise it can act as a generator and possibly damage the IC.

You can download the Arduino sketch from here.

By taking a copy of the sketch and modifying it, you can create a more useful program that controls one or more motors in response to a variety of input conditions.

Happy motoring!

Do this with a Raspberry Pi.

NEXT STEPS

As an improvement to this circuit, you can control the speed of the motor by using a PWM output pin to control the enable/disable input to the L293D. You could control the speed manually using a potentiometer and even have a reverse feature. This type of circuit is described in the book Exploring Arduino: Tools and Techniques for Engineering Wizardry by Jeremy Blum - details on the books page.