Dc Motor Driver Circuit Using Uln2003

In general, while designing electronics projects the loads are controlled (switched ON or OFF) using microcontroller block. But, for this purpose the circuit requires relays, acting as controlled switches (for different circuits different types of relays are used). Depending on the signals received from the microcontroller or other control circuits the relay controls the load. The relay consists of continuous power supply and whenever it gets driven or gets control signal then the relay gets activated and loads can be turned ON or OFF. But, primarily we must know what is a relay driver circuit.

Jul 01, 2020 PIC Microcontroller 5 Relay Driver circuit using ULN2003 Stepper motor driver using parallel port. This is an easy to build stepper motor driver that will allow you to precisely control a unipolar stepper motor through your computer’s parallel port. With a stepper motor you can build a lot of interesting gadgets such as robots, elevator, PCB. If we want to control a DC motor using Arduino, we have to go for some kinds of drivers such as ULN2803 or L293DNE. I had already published one blog on controlling a DC motor using L293D and Arduino. Controlling a DC motor using ULN2803 is pretty simple. But the problem is, we cannot change the direction of rotation of motor by this circuit. Relay driver circuit using ULN2003 ULN2003 is a very famous relay driver integrated circuit. Relay driver IC uln2003 is high voltage and high current integrated IC which used Darlington array. Its contains seven Darlington pair of a transistor which have high voltage and high current carrying capability. The ULN2003 Driver Board. The motor usually comes with a ULN2003 based driver board. The ULN2003 is one of the most common motor driver ICs, consisting of an array of 7 Darlington transistor pairs, each pair is capable of driving loads of up to 500mA and 50V. Four out of seven pairs are used on this board. The ULN2003 stepper motor driver board allows you to easily control the 28BYJ-48 stepper motor from a microcontroller, like the Arduino Uno. One side of the board side has a 5 wire socket where the cable from the stepper motor hooks up and 4 LEDs to indicate which coil is currently powered. The motor cable only goes in one way, which always helps.

Relay Driver Circuit

The circuit used for driving a relay can be termed as a relay driver circuit and it can be designed using various integrated circuits. These relays are needed to be driven for activating or to turn ON. So, relays require some driver circuitry to turn ON or OFF (based on the requirement).The relay driver circuit can be realized using different integrated circuits such as ULN2003, CS1107, MAX4896, FAN3240, A2550, and so on. Here, in this article let us discuss about relay driver circuit using ULN2003. Before discussing in detail about a relay driver circuit, let us know about IC ULN2003.


Relay Driver IC ULN2003

The IC ULN2003A is a Darlington transistor array which deals with high-voltage and high-current. There are various types of relay driver ICs such as a high side toggle switch, low side toggle switch, bipolar NPN transistor, Darlington transistor, N-channel MOSFET, ULN2003 driver IC.

The pin diagram of IC ULN2003A is shown in the above figure which consists of 16 pins. The IC ULN2003A comprises of 7-NPN Darlington pairs as shown in the internal schematic diagram and is typically used to switch inductive loads (dissipates voltage spikes if any using suppression diode) and to drive stepper motors.

Relay Driver Circuit using ULN2003

It is difficult to use a number of relays with transistors, so, relay driver IC ULN2003A can be used for availing more relays. We can use seven relays with relay driver circuit using ULN2003 and the relay driver circuit using ULN2803 enables to use eight relays. The above circuit represents the interfacing of PIC microcontroller (PIC16F877A) with relays using a relay driver circuit with ULN2003. The clamp diodes are built in these relays driver ICs and which eliminates the usage of freewheeling diodes.

The program that can be used for turning the relays ON and OFF is given below with delay time of one second.


void main()
{
TRISD = 0x00; //PORT D is made as output
do
{
PORTD.R1 = 1; //Relay 1 turns ON
PORTD.R2 = 1; //Relay 2 turns ON
PORTD.R3 = 1; //Relay 3 turns ON
PORTD.R4 = 1; //Relay 4 turns ON
PORTD.R5 = 1; //Relay 5 turns ON
PORTD.R6 = 1; //Relay 6 turns ON
PORTD.R7 = 1; //Relay 7 turns ON…and so on.
Delay_ms(1000); // 1 second Delay
PORTD.R1 = 0; //Relay 1 turns OFF
PORTD.R2 = 0; //Relay 2 turns OFF
PORTD.R3 = 0; //Relay 3 turns OFF
PORTD.R4 = 0; //Relay 4 turns OFF
PORTD.R5 = 0; //Relay 5 turns OFF
PORTD.R6 = 0; //Relay 6 turns OFF
PORTD.R7 = 0; //Relay 7 turns OFF
Delay_ms(1000); //1 second Delay
}
while(1);
}

Based on the signals received from the microcontroller the relay driver circuit drives the relay or relays ON and OFF, such that controlling the operation of loads connected to these relays.

Practical Implementation of Relay Driver Circuit

This is an innovative electrical engineering project that eliminates the power supply interruptions by auto power supply from (integrating and controlling) the four different electric power sources such as solar power, mains power supply, generator, and inverter. This project utilizes microcontroller of 8051 family which is interfaced with four switches (these switches or selection keys are assumed to be four different power sources mentioned above). Thus, the absence or failure of specific power source can be represented by pressing a particular switch or key.

The project consists of different block such as microcontroller block, power supply block, relay driver, relays, LCD display, and load (here a lamp is used for demonstration purpose) as shown in the block diagram. The input signals to the microcontroller are given using these press switches. Thus, the microcontroller generates the appropriate output signal and is fed to the relay driver circuit using ULN2003. Hence, the relay driver circuit drives the appropriate relay based on the control signals received from the microcontroller. So, the load gets turned ON by utilizing the available power source. The source that is used for turning ON loads can be displayed on the LCD display.

Do you know other practical applications of relay driver circuit using ULN2003? Then, share your views, comments, ideas, and suggestions by posting in the comments section below.

Related Content

Stepper motors are great motors for position control. They are a special type of brushless motors that divides a full rotation into a number of equal “steps”. They are usually found in desktop printers, 3D printers, CNC milling machines, and anything else that requires precise positioning control.

One of the inexpensive way to learn about stepper motors is to use 28BYJ-48 stepper motors. They usually come with a ULN2003 based driver board which makes them super easy to use.

Dc Motor Driver Circuit Using Uln2003

Do you know how these stepper motors work?

These stepper motors use a cogged wheel (having 32 teeth) and four electromagnets to rotate the wheel one ‘step’ at a time.

Each HIGH pulse sent, energizes the coil, attracts the nearest teeth of the cogged wheel and drives the motor one step.

The way you pulse these coils greatly affects the behavior of the motor.

  • The sequence of pulses determines the spinning direction of the motor.
  • The frequency of the pulses determines the speed of the motor.
  • The number of pulses determines how far the motor will turn.

The 28BYJ-48 Stepper Motor

The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5 volts.

The interesting thing about this motor is that people have been using it in countless applications over the last few decades. It is used in air-conditioner, vending machines and many other applications.

One of the best things about these motors is that they can be positioned accurately, one ‘step’ at a time.

The other advantage is that they are relatively precise in their movement and they are quite reliable since the motor does not use contact brushes.

They generally give good torque even in the stand-still state which is maintained as long as power is supplied to the motor.

The only downside is that they are a bit hungry for power and consume power even when they are not moving.

28BYJ-48 Gear Reduction Ratio

According to the data sheet, when the 28BYJ-48 motor runs in full step mode, each step corresponds to a rotation of 11.25°. That means there are 32 steps per revolution (360°/11.25° = 32).

In addition, the motor has a 1/64 reduction gear set. (Actually its 1/63.68395 but for most purposes 1/64 is a good enough approximation)

What this means is that there are actually 32*63.68395 steps per revolution = 2037.8864 ~ 2038 steps!

28BYJ-48 Power Consumption

The power consumption of the motor is around 240mA.

Because the motor draws too much power, it is best to power it directly from an external 5V power supply rather than drawing that power from the Arduino.

The motor consumes power, even in the stand still state, to maintain its position.

The ULN2003 Driver Board

The motor usually comes with a ULN2003 based driver board.

The ULN2003 is one of the most common motor driver ICs, consisting of an array of 7 Darlington transistor pairs, each pair is capable of driving loads of up to 500mA and 50V. Four out of seven pairs are used on this board.

The board has a connector that mates the motor wires perfectly which makes it very easy to connect the motor to the board. There are also connections for four control inputs as well as power supply connections.

The board has four LEDs that show activity on the four control input lines (to indicate stepping state). They provide a nice visual when stepping.

The board also comes with an ON/OFF jumper to isolate power to the stepper Motor.

ULN2003 Stepper Driver Board Pinout

The pinouts of the ULN2003 stepper driver board are as follows:

IN1 – IN4 pins are used to drive the motor. Connect them to a digital output pins on the Arduino.

GND is a common ground pin.

VDD pin supplies power for the motor. Connect it to an external 5V power supply. Because the motor draws too much power, you should NEVER use the 5V power from your Arduino to power this stepper motor.

Motor Connector This is where the motor plugs into. The connector is keyed, so it only goes in one way.

Wiring 28BYJ-48 Stepper Motor and ULN2003 Driver to Arduino

Now that we know everything about the motor, we can begin hooking it up to our Arduino!

Start by connecting the power supply up to the ULN2003 driver.

Note that it is possible to directly power the stepper motor from the Arduino. However, this is not recommended; as the motor may induce electrical noise onto its power supply lines and this could damage the Arduino.

So, use a separate 5V power supply to power your stepper motors.

Next connect the ground from that power supply to the arduino’s ground. This is very important so that we establish the same voltage reference between the two.

Now connect the driver board’s IN1, IN2, IN3, IN4 to the Arduino digital pins 8, 9, 10, and 11 respectively.

Finally, hook the motor cable from the stepper motor up to the driver board.

When you’re done you should have something that looks similar to the illustration shown below.

Arduino Code – Using Built-in Stepper Library

For our first experiment we will make use of the Arduino Stepper Library which comes packaged with your Arduino IDE.

The stepper library takes care of the stepping sequence and makes it straight forward to control a wide variety of stepper motors, both unipolar and bipolar.

Here’s the simple sketch that moves the stepper motor clockwise slowly and then counterclockwise quickly.

Code Explanation:

The sketch starts with including the Arduino Stepper Library.

Next, we define a constant stepsPerRevolution which holds the number of ‘steps’ that the motor will take to complete one revolution. In our case, it’s 2038.

The 28BYJ-48 Unipolar stepper motor has a step sequence of IN1-IN3-IN2-IN4. We will use this information to drive the motor by creating an instance of stepper library called myStepper with the pin sequence of 8, 10, 9, 11.

Make sure you get this right or the motor will not operate properly.

There is nothing to set in the setup function as the Stepper library internally sets the four I/O pins as outputs.

In the loop function, we use the setSpeed() function to set the speed that we wish the stepper motor to move and subsequently use the step() function to tell it how many steps to rotate. Passing a negative number to the step() function reverses the spinning direction of the motor.

First code snippet will turn the motor clockwise very slowly. And the second will turn the motor counterclockwise at a much faster speed.

Arduino Code – Using AccelStepper library

The Arduino Stepper Library is perfectly adequate for simple, single motor applications. But when you want to control multiple steppers, you’ll need a better library.

So, for our next experiment we will make use of an advanced stepper motor library called AccelStepper library. It significantly improves on the standard Arduino Stepper library in several ways:

  • It supports acceleration and deceleration.
  • It supports half-step driving.
  • It supports multiple simultaneous steppers, with independent concurrent stepping on each stepper.

This library is not included in the Arduino IDE, so you will need to install it first.

Library Installation

To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.

Filter your search by typing ‘accelstepper’. Click on the first entry, and then select Install.

Arduino Code

Dc Motor Driver Circuit Using Uln2003 System

Here’s the simple sketch that accelerates the stepper motor in one direction and then decelerates to come to rest. Once the motor makes one revolution, it changes the spinning direction. And it keeps doing that over and over again.

Code Explanation:

We start off by including the newly installed AccelStepper library.

Now as we are going to drive our motor at full steps, we will define a constant for this. If you want to drive the motor at half steps, set the constant to 8.

Next, we create an instance of stepper library called myStepper with the pin sequence of 8, 10, 9, 11 (Remember the step sequence for these motors is IN1-IN3-IN2-IN4).

Again, make sure you get this right or the motor will not operate properly.

In the setup function we first set the maximum speed of the motor to a thousand which is about as fast as these motors can go. We then set an acceleration factor for the motor to add acceleration and deceleration to the movements of the stepper motor.

Next we set the regular speed of 200 and the number of steps we’re going to move it to i.e. 2038 (as you recall the 28BYJ-48 with its gearing will move 2038 steps per revolution).

In the loop function, we use an If statement to check how far the motor needs to travel (by reading the distanceToGo property) until it reaches the target position (set by moveTo). Once distanceToGo reaches zero we will move the motor in the opposite direction by changing the moveTo position to the negative of its current position.

Now at the bottom of the loop you’ll notice we have called a run() function. This is the most important function, because the stepper will not run until this function is executed.

Control Two 28BYJ-48 Stepper Motors Simultaneously

For our next experiment, we will add a second 28BYJ-48 stepper and ULN2003 driver set to our Arduino to drive two motors simultaneously.

Wiring

Leave the connections you made earlier as they are and wire the new devices as follows:

Once again we will use the separate 5V power supply to supply power to the ULN2003 driver board.

Now connect the second driver board’s IN1, IN2, IN3, IN4 to the Arduino digital pins 4, 5, 6, and 7 respectively.

The following illustration shows the wiring.

Arduino Code

Here’s the sketch that drives one motor at full steps and the second one at half steps. When the motors make one revolution their spinning direction will change. There’s some acceleration and deceleration involved as well.

Code Explanation:

We begin by including the AccelStepper Library.

Now as we are going to drive one motor at full steps and the second one at half steps. We will define two constants for that.

Next, we create two motor objects, one for each motor. We use our pin definitions and the step definitions to set these up.

In the setup function we first set the maximum speed of the stepper1 to a thousand. We then set an acceleration factor for the motor to add acceleration and deceleration to the movements of the stepper motor.

Next we set the regular speed of 200 and the number of steps we’re going to move it to i.e. 2038 (as you recall the 28BYJ-48 with its gearing will move 2038 steps per revolution).

Dc Motor Driver

We’re going to do exactly the same thing for stepper2 except we’ll instruct it to move to -2038 because we want it to move counterclockwise.

Dc Motor Driver Circuit Using Uln2003 Usb

In the loop function, we use two If statements, one for each motor, to check how far the motors need to travel (by reading the distanceToGo property) until they reach their target positions (set by moveTo). Once distanceToGo reaches zero, we will change their moveTo position to the negative of their current position, so that they start moving in the opposite direction.

Dc Motor Driver Circuit Using Uln2003 Cable

Finally we set them into motion by calling the run() function.