Stepper motors are widely used to control many common devices we see every day. From blinds, 3D printers and DVD players to security cameras and CNC machines, stepper motors are closer to our lives than you might think.The first step in exploring stepper motors is to use the 28BYJ-48 stepper motor. They usually come with a ULN2003 based driver board which makes them very easy to use.
Do you know how these stepper motors work?
These stepper motors use a toothed wheel (which has 32 teeth) and four electromagnets that form a ring around the wheel.
Each high pulse sent energizes the coil, attracting the teeth closest to the gear and rotating the motor in precise and fixed angular increments called stepping.
The way you send pulses to these coils greatly affects the behavior of the motor.
● The pulse train determines the direction of rotation of the motor.
● The frequency of the pulse determines the speed of the motor.
● The number of pulses determines how far the motor will turn.
28BYJ-48 stepper motor
The 28BYJ-48 is a 5-wire unipolar stepper motor that operates at 5V.
The biggest advantage of this motor is that it can position exactly one step at a time. It performs well in projects that require precise positioning, such as opening and closing vents.
Another advantage is that its movement is relatively precise and very reliable since the motor does not use contact brushes.
Considering its size, the motor delivers a decent 34.3mN.m of torque at around 15RPM. It delivers good torque even at standstill, which can be maintained as long as power is supplied to the motor. The only downside is that it’s a bit power hungry, even when it’s not moving.
Pinout
28BYJ-48 is a 5-wire stepper motor. The pinout is as follows:
The 28BYJ-48 consists of two coils, each with a center tap. The two center taps are connected internally and brought out as a 5th wire (red wire).
One end of the coil and the center tap together form a phase. Therefore, 28BYJ-48 has a total of 4 phases.
The red line is always high. When the other lead is pulled low, that phase is energized.
A stepper motor only rotates when the phases are energized in a logical sequence called a step sequence.
Gear reduction ratio
According to the datasheet, when the 28BYJ-48 motor is running in full-step mode, each step corresponds to 11.25° of rotation. This means there are 32 steps per revolution (360°/11.25° = 32).
In addition to this, the motor has a 1/64 reduction gear set. (Actually it’s 1/63.68395, but 1/64 is a good enough approximation for most uses)
This means that there are actually 2038 steps (32*63.68395 steps per revolution = 2037.8864 about 2038 steps).
Power consumption
The 28BYJ-48 typically consumes about 240mA.
Since the motor draws a lot of current, it’s best to power it directly from an external 5V supply, rather than drawing power from the Arduino.
Note that even at standstill, the motor consumes power to maintain its position.
Technical Specifications
Here are the full specs:
Operating Voltage
|
5VDC
|
Working current
|
240mA (typ.)
|
Phase
|
4
|
Gear reduction ratio
|
64:1
|
step angle
|
5.625°/64
|
frequency
|
100Hz
|
traction torque
|
>34.3mN.m(120Hz)
|
self-aligning torque
|
>34.3mN.m
|
friction torque
|
600-1200 gf.cm
|
pull-in torque
|
300 gf.cm
|
For more information on this motor, see the following data sheet: 28BYJ-48 data sheet .
ULN2003 driver board
Since the 28BYJ-48 stepper motor consumes high current, a microcontroller like Arduino cannot directly control the motor. It needs a driver IC like ULN2003 to control the motor, so this motor usually comes with a ULN2003 based driver board.
Known for its high current and high voltage capability, the ULN2003 provides higher current gain than a single transistor and enables the microcontroller’s low voltage, low current output to drive high current stepper motors.
The ULN2003 consists of a set of seven Darlington transistor pairs, each capable of driving loads up to 500mA and 50V. Four of the seven pairs are used on this driver board.
The board has a molex connector that perfectly connects the motor wires, making it very easy to connect the motor to the board. There are four control inputs and a power connection.
The driver board has four LEDs showing activity on the four control input lines (to indicate stepper status). They provide good directions when not going in. The board also comes with an on/off jumper to isolate the power to the stepper motors.
ULN2003 stepper driver board pinout
The pins of the ULN2003 stepper driver board are as follows:
IN1 – IN4 pins are used to drive the motor. Connect them to the digital output pins on the Arduino.
GND is the common ground pin.
The VDD pin powers the motor. Connect it to an external 5V power supply. Never use the Arduino’s 5V power supply to drive this stepper motor because the motor will draw a lot of current.
Motor Connector This is where the motor plugs into. The connector is keyed, so it has only one connection.
Connect the 28BYJ-48 stepper motor and ULN2003 driver to the Arduino board
Now that we know everything about the motor, we can start connecting it to the Arduino.
First connect the power supply to the ULN2003 driver. Use a separate 5V power supply to power the stepper motors.
After that, connect the ground of this power supply to the ground of the Arduino. This is very important so that we can have the same voltage reference between the two.
Now connect IN1, IN2, IN3, IN4 of the driver board to Arduino digital pins 8, 9, 10 and 11 respectively. Finally connect the motor cable from the stepper motor to the driver board.
Connect all components as shown below.
Arduino code – using built-in Stepper library
For the first experiment, we will use the Arduino Stepper library installed with the Arduino IDE .
The Stepper library handles the step sequence and makes it easy to control a variety of stepper motors, both unipolar and bipolar.
Below is a simple sketch to make a stepper motor rotate slowly clockwise and then quickly counterclockwise.
- //Includes the Arduino Stepper Library
- #include <Stepper.h>
- // Defines the number of steps per rotation
- const int stepsPerRevolution = 2038;
- // Creates an instance of stepper class
- // Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
- Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
- void setup() {
- // Nothing to do (Stepper Library sets pins as outputs)
- }
- void loop() {
- // Rotate CW slowly at 5 RPM
- myStepper.setSpeed(5);
- myStepper.step(stepsPerRevolution);
- delay(1000);
- // Rotate CCW quickly at 10 RPM
- myStepper.setSpeed(10);
- myStepper.step(-stepsPerRevolution);
- delay(1000);
- }
code description
Start by including the built-in Stepper library in your sketch code.
Next, we define a constant stepsPerRevolution that holds the number of steps the motor takes to complete one revolution. In the example, its value is 2038.
- const int stepsPerRevolution = 2038;
The step sequence of 28BYJ-48 unipolar stepper motor is IN1-IN3-IN2-IN4. We’ll use this information to drive the motor by creating an instance called myStepper with the pin order 8, 10, 9, 11.
Make sure you do it right or the motor won’t work properly.
- Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
There is nothing to set up in the setup() function because 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 at which we want the stepper motor to move, and then use the step() function to tell it how many steps to rotate. Passing a negative number to the step() function reverses the direction of rotation of the motor.
The first code snippet makes the motor spin clockwise very slowly. The other makes the motor spin counterclockwise at a very high speed.
- void loop() {
- // Rotate CW slowly at 5 RPM
- myStepper.setSpeed(5);
- myStepper.step(stepsPerRevolution);
- delay(1000);
- // Rotate CCW quickly at 10 RPM
- myStepper.setSpeed(10);
- myStepper.step(-stepsPerRevolution);
- delay(1000);
- }
|
Thank you for your shening. I am worried that I lack creative ideas. It is your enticle that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/en/register?ref=P9L9FQKY
I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Outstanding work!
Hey very cool web site!! Man .. Excellent .. Amazing .. I’ll bookmark your web site and take the feeds also厈I am happy to find a lot of useful information here in the post, we need develop more techniques in this regard, thanks for sharing. . . . . .
I like what you guys are up also. Such intelligent work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my site 🙂