Using a ULN2803A to control a DC motor

Introduction

In this short tutorial, we will learn how to use the ULN2803A IC to control a DC motor, using an Arduino board.

Driving high current loads with microcontrollers

Many times, when creating an electronic design, we want our microcontroller to drive loads that draw a considerable amount of current, such as relays, motors or high power LEDs, amongst many other possibilities.

Nevertheless, the digital pins of a microcontroller can normally provide only a limited amount of current, in the order of the dozens of milliamps. For example, Arduino Uno has a recommended value of 20 mA for continuous operation of its digital pins, with a maximum tolerable value of 40 mA before causing damage to the device [1]. The ESP8266 (the new IoT trend for makers) can only provide a maximum of 12 mA [2].

From those values, it’s easy to conclude that driving, for example, a DC motor that consumes 100 mA is not possible by directly connecting it to an IO pin of the microcontroller. So, we need some kind of circuit that can be controlled by an IO pin of a microcontroller, and still be able to provide a considerable amount of current to the device to control.

The ULN2803A

Although there are many solutions for the problem mentioned before, such as directly using transistors, we will explain how to use a ULN2803A, which is an easy to use IC.

The ULN2803A is an array of  Darlington transistors, which is a configuration of two transistors (shown in figure 1) that allow for a very high current amplification. This means that, by drawing only a very small amount of current from the input (in this case, the IO pin), the device can provide a much larger amount of current, which is drawn from an external voltage source, and not from the IO pin. In the case of the ULN2803A, each channel can provide a maximum of 500 mA [3].

Darlington pair electric schematic.

Figure 1 – Darlington pair configuration of a ULN2803A channel. Taken from [3].

Controlling a motor with an Arduino

Using an ULN2803A to control a motor with an Arduino is very simple, as shown in figure 2. This example uses a regular 5V DC motor.

Keep in mind that each ULN channel will work as a switch, turning on and off the connection of the motor to GND, depending on the voltage of the input pin (which is connected to the output pin of the microcontroller).

If the digital pin of the Arduino is High (5 V), then current will flow through the circuit and the motor will operate. If the digital pin is Low (0 V), then the connection to GND will be off, and there will be no current flowing through the circuit.

Electric diagram on how to use the Arduino and an ULN2803A to control a DC motor.

Figure 2 – Connection diagram to control a motor using an Arduino and an ULN2803A.

It’s important to take into account that the ULN cuts the connection to GND when using it, for example, to drive LEDs, in order to avoid connecting them the wrong way. In the case of a regular DC motor, changing the terminals will only change the rotation direction of the motor.

The Arduino code to make this circuit work is even more simple: just use a digitalWrite to turn the digital pin on and watch the motor spin.

Controlling the speed of the motor

Using this exact same configuration, we can use the arduino PWM capabilities to control the speed of the motor. We jut need to change the digitalWrite function by the analogWrite function to activate the pin, and set it to values between 0 and 255 to watch the speed change.

Related Posts

References

[1] https://www.arduino.cc/en/Main/ArduinoBoardUno

[2] https://www.adafruit.com/images/product-files/2471/0A-ESP8266__Datasheet__EN_v4.3.pdf

[3] http://www.ti.com/lit/ds/symlink/uln2803a.pdf

3 thoughts on “Using a ULN2803A to control a DC motor”

  1. Pingback: ESP8266: Controlling a motor with the ULN2803A | techtutorialsx

  2. Pingback: ESP8266: Controlling a motor with the ULN2803A | techtutorialsx

  3. Pingback: Buying cheap electronics at eBay: part 3 | techtutorialsx

  4. Pingback: Buying cheap electronics at eBay: part 3 | techtutorialsx

  5. Pingback: ESP8266: Controlling a LED matrix with the 74HC595 ICs | techtutorialsx

  6. Pingback: ESP8266: Controlling a LED matrix with the 74HC595 ICs | techtutorialsx

Leave a Reply

Discover more from techtutorialsx

Subscribe now to keep reading and get access to the full archive.

Continue reading