Uln2003 Driver Arduino

Learn how to control bipolar and unipolar stepper motors with an Arduino using drivers like ULN2003, L298N and A4988. In this article I’ll show you all you need to know to get started with stepper motors.

  1. Uln2003 Dc Motor Driver Arduino
  2. Uln2003 Driver Board Arduino
  3. Arduino Driver Stepper Uln2003
  4. Uln2003 Stepper Motor Arduino

Introduction

Relay Driver IC ULN2003. The relay driver uln2003 ic is a high voltage and current darlington array ic, it comprises of 7-open collector darlington pairs with common emitters. A pair of darlington is an arrangement of two bipolar transistors. The ULN2003 Stepper Motor Driver Module is small size & ease to use electronic module, it used ULN2003 Chip to amplify the signal from the micro controller, Input voltage max 15v Logic Control Voltage: 3 to 5.5v Motor Supply Voltage: 5 to 15v Can Sink 500mA from 50v supply,(beter used voltage.

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. Motor Driver ULN2003 BreakOut Connected To Arduino From IN1 - IN4 To D8 - D11 Respectively To Power you Motor, Recommanded to use external Power Supply with 5V-500mA at least, Don't power it directly from arduino Board 5V. Connecting the 28BYJ-48 stepper motor to the ULN2003 driver board. Usually, the 28BYJ-48 stepper motor comes with a 5-pin connector that will fit to the ULN2003 driver board. Connecting the ULN2003 driver board to the Arduino. Connect the ULN2003 driver lN1, lN2, lN3, lN4 to the Arduino digital pins 8, 9, 10, and 11 respectively. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input, and a ULN2003A driver. This chip has a bunch of transistors embedded in a single housing. It allows the connection of devices and components that need much higher current than the ones that the ATMEGA8 from our Arduino board can offer.

Stepper Motors are used in a wide variety of devices ranging from 3D printers and CNC machines to DVD drives, heating ducts and even analog clocks. Yet despite their popularity many experimenters shy away from using stepper motors as they seem to require complex hookups and code.

In this article I hope to dispel that myth by showing you just how easy it is to use a stepper motor with an Arduino. So follow along, I promise to take you through all of this “complex” stepper theory one step at a time!

Stepper Motors

Stepper motors are DC motors that rotate in precise increments or “steps”. They are very useful when you need to position something very accurately. They are used in 3D printers to position the printhead correctly and in CNC machines where their precision is used to position the cutting head. If your digital camera has an autofocus or remote zoom feature chances are a stepper motor is being employed to do that.

Unlike DC motors stepper motors are controlled by applying pulses of DC electricity to their internal coils. Each pulse advances the motor by one step or by a fraction of a step, the latter is known as “microstepping” and will be explained shortly.

Some users confuse stepper motors with servo motors but they are actually two different beasts. A servo motor is unique in that it’s motor shaft can be moved to a precise angle, most servos only rotate 180 or 270 degrees although there are modified servos that can spin a full 360 degrees. A servo motor is “aware” of its position and can be moved to a specific angle even if an external force moves the motor shaft.

Steppers, on the other hand, are “unaware” of their position. They can be moved to an exact position in reference to where they start stepping (i.e 36 degrees clockwise) but unlike servos they can be misaligned if their shaft is moved by an external force. In many applications a servo is first moved to a “homing” or reference position before being controlled, printers commonly do this when they are first initialized.

Because the move in discrete steps a stepper motor is not often used where a smooth continuous rotation is required, However with the use of gearing and microstepping they can approach a smooth rotation and their ability to be very accurately positioned often outweighs the roughness of their movement.

Another advantage stepper motors have over DC motors is the ability to move art very slow speeds without stalling, in fact stalling really isn’t a concept with stepper motors. They also pack a lot of torque into a comparably small package.

How Stepper Motors Work

Stepper motors have a magnetized geared core that is surrounded by a number of coils which act as electromagnets. Despite the number of coils electrically there really are usually only two coils in a stepper motor, divided into a number of small coils.

By precisely controlling the current in the coils the motor shaft can be made to move in discrete steps, as illustrated in the following diagrams:

Uln2003

In the first diagram the coil at the top is energized by applying electricity in the polarity shown. The magnetized shaft is attracted to this coil and then locks into place.

Now look what happens when the electricity is removed from the top coil and applied to the other coil. The shaft is attracted to the second coil and locks into place there.

The jump between the two positions is one step (in this illustration a step is 90 degrees, in actual fact a stepper motor usually steps just a fraction of this. The diagrams are simplified for clarity).

Microstepping

We have seen how the motor shaft moves to lock itself into place in front of an attracting electromagnet, each magnet represents one step. It is, however, possible to move the motor shaft into positions between steps. This is known as “microstepping”.

In order to understand how microstepping works look at the next diagram:

In this illustration the current has been applied to BOTH coils in an equal amount. This causes the motor shaft to lock into place halfway between the two coils. This would be known as a “half step”.

The principle can be extended to include quarter steps, eight steps and even sixteenth steps. This is done by controlling the ratio of the current applied to both coils to attract the motor shaft to a position between the coils but closer to one coil than the other.

By using microstepping it is possible to move the shaft of a stepper motor a fraction of a degree, allowing for extremely precise positioning.

Types of Stepper Motors

Internally there are a number of ways to design a stepper motor, such as Variable Reluctance, Permanent Magnet and Hybrid stepper motors. These design differences primarily deal with the method employed to create the magnetic field within the motor.

For most experimenters these differences will be merely academic but if you are choosing a stepper motor for a very specific design you may want to look into this more.

For most users the main difference between stepper motor design boils down to the way the coils are wired within the motor. There are two methods employed – Bipolar and Unipolar. These two types of stepper motors are not interchangeable (although it is possible to “hack” a Unipolar motor to create a Bipolar motor).

Let’s look at these two types of stepper motors.

Bipolar Stepper Motors

Bipolar stepper motors consist of two coils of wire (electrically, actually split into several physical coils) and generally have four connections, two per coil. The simplified diagrams of stepper operation that you just looked at in the previous section are all bipolar stepper motors.

An advantage of bipolar stepper motors is that they make use of the entire coil winding so they are more efficient. However they require a more complex controller or driver to operate as to reverse direction the polarity of the voltage applied to the coils needs to be reversed.

Unipolar Stepper Motors

A unipolar stepper motor also consists of two coils (electrically) but each coil has a center tap so there are three connections on each coil. This results in six connections, however many unipolar stepper motors have only five connections as the two center taps are internally connected.

In a unipolar stepper motor only half of each coil is used at one time. In most configurations a positive voltage is applied to the center tap and left there. A negative voltage is then applied to one side of the coil to attract the motor shaft, as illustrated below:

As with the bipolar motor the unipolar stepper motor can be made to advance one step when current is removed from the top coil and applied to one side of the second coil:

You can also microstep a unipolar stepper motor by using the same technique that we used with bipolar steppers, applying current to both coils.

Now to reverse the direction of a unipolar motor you don’t need to reverse polarity. Instead the negative voltage is applied to the OTHER side of the coil. This causes the current to flow in the opposite direction within the coil and this in turn moves the motor shaft in the opposite direction.

Unipolar stepper motors are easier to control as there is no requirement to reverse current polarity to change direction. However as the unipolar stepper motor only makes use of half of the coil windings at any given moment they are not as efficient as half of the wiring is essentially wasted.

We will work with both unipolar and bipolar stepper motors in the experiments we are about to do.

It should be noted that there are also stepper motors that can be wired as both bipolar and unipolar. These motors have four coils which can be joined to make either two center tapped coils (for a unipolar configuration) or just two big coils (in a bipolar configuration). These stepper motors will have eight wires, two per coil.

Reading Stepper Motor Specifications

Choosing a stepper motor can be a somewhat daunting task but it doesn’t have to be. Many first time users are scared off by the vast number of specifications included with some stepper motors. In actual fact they are not that difficult to understand.

Here are a few of the key specifications you’ll find included with stepper motors, along with a short definition of them:

Phase: This refers to the groupings of the individual coils in the stepper motor. A stepper motor may have several coils but they are wired together and controlled in phases. Two, Four and Five phase stepper motors are common. There will often be a phase diagram included with a stepper motor that indicates the sequence that the motor phases are driven in.

Step Angle: This is the amount that the shaft of the motor will spin for each individual full step, measured in degrees, In some stepper motors this is referred to as Steps Per Revolution and the two figures are just different ways of expressing the same thing.

As an example a common rating for a stepper motor is a 1.8 degree step angle. As there are 360 degrees in a full rotation this is equivalent to 200 steps per revolution (1.8 x 200 = 360).

Voltage: Simply the voltage rating of the motor coils. It is also a function of the current rating and the coil resistance and you can use Ohm’s Law to calculate one from the other.

Current: The maximum current at the rated voltage. This is a useful specification as it will allow you to select a suitable driver and power supply for your stepper motor.

Resistance: The coil resistance, measure in ohms.

Inductance: The inductance of each motor coils, measured in millihenries. This is an important specification as inductance will limit the maximum speed you’ll be able to efficiently drive your stepper at. Typically unipolar stepper motors have an advantage here as they only use half a coil and thus have lower inductance than their bipolar equivalents.

Holding Torque: This will be the amount of force that is created when the stepper motor is energized.

Detent Torque: This is the amount of holding torque that can be expected when the motor is NOT energized.

Shaft Style: The physical shape of the motor shaft. You will need to know this in order to mate your stepper motor with gears, pulleys and other external connections such as shaft couplers. There are several common shapes used, in addition the shaft length can be important for obvious reasons.

Some common shaft types are as follows:

  • Round Shaft – pretty well says it all!
  • “D” Shaft – a “D-shaped” shaft, useful for mounting gears with set screws.
  • Geared Shaft – a shaft with a gear etched into it.
  • Lead-Screw Shaft – A shaft shaped like a screw, used in constructing linear actuators.

Another obvious specification of a stepper (or any motor) is its physical size. There are a group of stepper motors that have standard sizes, we will look at these now.

NEMA Motor sizes

NEMA is an abbreviation for the National Electrical Manufacturers Association. Although based in the United States this is actually an international standards committee, although being American the specifications were all originally created using the imperial system instead of the metric system.

In 1984 the NEMA committee set out some standards for motor sizes, based upon the face plate size of the motor. This standard is still in use today and results in motors designated “NEMA 17” or “NEMA 23”.

The NEMA 17 sized stepper motor has become extremely popular, especially in the construction of 3D printers. It also creates a lot of confusion as you often hear people refer to a motor simply as a “NEMA 17”, which really only designates the size of the motor and not it’s other specifications such as voltage, current, step angle or even if it is bipolar or unipolar.

The “17” in “NEMA 17” is the face plate size, in the NEMA standard the face plate is the NEMA “number” divided by 10 in inches. So a NEMA 17 motor has a face plate approximately 1.7 inches wide while a NEMA 23 is 2.3 inches wide.

Techref has a good description of NEMA motor sizes.

Experimenting with Stepper Motors

OK enough theory! Time to dig out our Arduino and start experimenting with stepper motors.

There are four experiments we will do today, two of them using a unipolar stepper motor and two of them with the unipolar variety. In addition we will make use of a couple of Arduino libraries, one of which is already included in the Arduino IDE.

Although these experiments have been illustrated using an Arduino Uno any Arduino will work. You can also feel free to change the pin numbers if you need to as there are no special requirements there, just be sure to alter the sketch to reflect those changes if you decide to do that.

Let’s get started!

Demo 1 – 28BYJ-48 Unipolar Stepper with ULN2003

Our first demonstration will make use of an extremely popular stepper motor and driver combination. These motors have been manufactured for decades and are made by the millions so they are very inexpensive, the driver and motor should run you less than five dollars in total.

The 28BYJ-48 is a 5-wire unipolar stepper motor that moves 32 steps per rotation internally but has a gearing system that moves the shaft by a factor of 64. The result is a motor that spins at 2048 steps per rotation. It should be noted that some of these motors may have a different gearing system so the number of steps per rotation of your motor may not be the same. The 28BYJ-48 runs on 5 volts.

The motor is commonly packaged with a tiny driver board based around the ULN2003 darlington transistor array. The board has a connector that mates perfectly with the motor wires so it is very easy to use. There are also connections for four 5-volt digital inputs as well as power supply connections.

On the subject of power supplies one very important thing to note is that you should NEVER use the 5-volt power from your Arduino to power this (or any) stepper motor no matter how tempting it is. Even though the 28BYJ-48 doesn’t draw much current it will induce electrical “noise” onto its power supply lines and this could damage your Arduino. Always use a seperate power supply to power your stepper motors!

We will hookup our motor, driver and Arduino as follows:

Now that we have everything hooked up we will need to program the Arduino. Here is the sketch that we will use to do that:

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
Stepper Motor Demonstration 4
Demonstrates NEMA 17 Bipolar Stepper with A4988 Driver
DroneBot Workshop 2018
*/
// Define Constants
// Connections to A4988
constintstepPin=3;// Step
// Motor steps per rotation
pinMode(stepPin,OUTPUT);
}
digitalWrite(dirPin,HIGH);
// Spin motor one rotation slowly
digitalWrite(stepPin,HIGH);
digitalWrite(stepPin,LOW);
}
// Pause for one second
digitalWrite(dirPin,LOW);
// Spin motor two rotations quickly
digitalWrite(stepPin,HIGH);
digitalWrite(stepPin,LOW);
}
// Pause for one second
}

In this sketch we won’t be using any stepper libraries as all we need to do is send a pulse out to the A4988 and let it do all the “heavy lifting”.

We start by defining constants to represent the pins we have connected the A4988 STEP and DIR pins to. We also define STEPS_PER_REV as we did in the previous sketch, the number of steps our motor needs to complete one rotation. Again you should set this to match your stepper motor specifications.

In the setup we set our two defined A4988 pins as outputs.

Uln2003 Driver Board Arduino

Now to the loop. We will do two things here, spin the motor slowly clockwise one turn and then spin it counterclockwise two turns. We will insert a one second delay between each spin.

To set the direction of the motor we set the DIR pin either HIGH or LOW depending upon which way we want to go. A HIGH here will cause the motor to spin clockwise.

The speed is set by the frequency of the pulses we send on the STEP pin. The pulses are manually generated in a very similar fashion as the Arduino Blink sketch, by bringing the output HIGH, waiting a bit then Bringing it LOW and waiting again. This is repeated as many times as necessary to rotate our motor oin the amount we desire, one full rotation for the first routine and two rotations for the second one.

Of course you can add as many routines as you wish to make your motor move in the speed and direction you like.

As you can see the A4988 makes it very easy to drive a bipolar stepper motor with a minimum of code. You can also get a shield for your Arduino that allows you to drive multiple A4988 modules, which would be great if you are building a CNC machine or a 3D printer.

Conclusion

Hopefully this article and the accompanying video have shown you that stepper motors are not really that hard to work with after all. If you are designing a project that requires you to be able to position something precisely a stepper motor is an ideal choice.

Please let me know in the comments about any problems or observations you encounter using stepper motors. I’d really love to hear how you incorporate them into your own designs.

Now get out there and start building with stepper motors!

Resources

Code for this article – All of the Arduino Sketches used in this article in one ZIP file.

AccelStepper Library – The AccelStepper library is an advanced stepper motor control library for the Arduino.

Arduino Stepper Library – A stepper motor library included in the Arduino IDE.

Stepper Motors – The Wikipedia guide to stepper motors.

What is a Stepper Motor? – An excellent article about stepper motors from Adafruit.

Everything about Stepper Motors – A very detailed article about stepper motor design from Oriental Motors.

Stepper Motors with Arduino – Getting Started with Stepper Motors
Stepper Motors with Arduino - Getting Started with Stepper Motors
Description
Learn to use Stepper Motors with the Arduino. Explore different stepper motor designs and driver options.
Author
DroneBot Workshop
Publisher Logo

The ULN2003 Stepper Motor Driver Module is small size & ease to use electronic module, it used ULN2003 Chip to amplify the signal from the micro controller, Input voltage max 15v

Logic Control Voltage: 3 to 5.5v
Motor Supply Voltage: 5 to 15v
Can Sink 500mA from 50v supply,(beter used voltage driver under 15 volts)
Operating Temperature: -25 degrees Celsius to +90 Degree Celsius

Stepper motor has convert pulse to angle displacement. So if you give stepper driver a certain PWM signal, it will drive step motor to a certain angle. you can control the angle the stepper moved by the number of the pulse.

And you can also control the speed of the stepper rotate by the frequency of the pulse.

Arduino Driver Stepper Uln2003

Controlling the signal to drive a 28BYJ48 stepper to rotate 1/4096 circle.

line12345678
red11111111
orange11000001
yellow01110000
pink00011100
blue00000111

Defined the time series in a array

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
14CORE | ULN2003 STEPPER MOTOR TEST CODE
The time Series to control the stepper
*/
byteCCW[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
byteCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
constintstop_key=14;//stop_button connect to Arduino-A0
bytechange_angle=64;//change the parameter to change the angle of the stepper
voidMotor_CCW()//the stepper move 360/64 angle at Counter Clock wise
for(inti=0;i<8;i++)
for(intj=0;j<8;j++)
if(digitalRead(stop_key)0)
PORTB=0xf0;
}
delay Microseconds(1150);
}
voidMotor_CW()//the steper move 360/64 angle at Clockwise
for(inti=0;i<8;i++)
for(intj=0;j<8;j++)
if(digitalRead(stop_key)0)
PORTB=0xf0;
}
delay Microseconds(1150);
}
voidsetup()
pinMode(stop_key,INPUT);
Serial.begin(57600);
PORTB=0xf0;
{
}
{
Motor_CCW();//make the stepper to anticlockwise rotate
// Motor_LR(); //make the stepper to clockwise rotate

Download the ULN2003_Data_Sheet Here!

How to used ULN2003 Stepper Motor Driver Module in Arduino Tutorial Guide

Related Article: