We will learn how to control 28BYJ-48 Stepper Motor with LEDs and Arduino board.
Tag: Project 004b 28BYJ-48 Stepper Motor with LEDs. Acoptex.lt
- The Stepper library included in Adruino IDE program which installed in your PC. You can also download it – libraries;
Other attachments: None.
In this project, you needed these parts :
1.Arduino Uno R3 (you can also use the other version of Arduino)
2.28BYJ 48 Stepper Motor
3.Arduino IDE ( you can download it from here )
5.ULN2003 stepper motor driver board
6. LEDs 3 pcs (1 Blue, 1 Green, 1 Red)
7. Resistors 3 pcs (220 Om each)
Understanding the stepper motors
A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.
This design allows for very precise control of the motor: by proper pulsing, it can be turned in very accurate steps of set degree increments (for example, two-degree increments, half-degree increments, etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is necessary.
There are two basic types of stepper motors, unipolar steppers and bipolar steppers.
Unipolar Stepper Motors
The unipolar stepper motor has five or six wires and four coils (actually two coils divided by center connections on each coil). The center connections of the coils are tied together and used as the power connection. They are called unipolar steppers because power always comes in on this one pole.
Bipolar stepper motors
The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. You can distinguish them from unipolar steppers by measuring the resistance between the wires. You should find two pairs of wires with equal resistance. If you’ve got the leads of your meter connected to two wires that are not connected (i.e. not attached to the same coil), you should see infinite resistance (or no continuity).
Like other motors, stepper motors require more power than a microcontroller can give them, so you’ll need a separate power supply for it. Ideally you’ll know the voltage from the manufacturer, but if not, get a variable DC power supply, apply the minimum voltage (hopefully 3V or so), apply voltage across two wires of a coil (e.g. 1 to 2 or 3 to 4) and slowly raise the voltage until the motor is difficult to turn. It is possible to damage a motor this way, so don’t go too far. Typical voltages for a stepper might be 5V, 9V, 12V, 24V. Higher than 24V is less common for small steppers, and frankly, above that level it’s best not to guess.
To control the stepper, apply voltage to each of the coils in a specific sequence. The sequence would go like this:
|Step||wire 1||wire 2||wire 3||wire 4|
To control a unipolar stepper, you use a Darlington Transistor Array. The stepping sequence is as shown above. Wires 5 and 6 are wired to the supply voltage.
To control a bipolar stepper motor, you give the coils current using to the same steps as for a unipolar stepper motor. However, instead of using four coils, you use the both poles of the two coils, and reverse the polarity of the current.
The easiest way to reverse the polarity in the coils is to use a pair of H-bridges. The L293D dual H-bridge has two H-bridges in the chip, so it will work nicely for this purpose.
Once you have the motor stepping in one direction, stepping in the other direction is simply a matter of doing the steps in reverse order.
Knowing the position is a matter of knowing how many degrees per step, and counting the steps and multiplying by that many degrees. So for examples, if you have a 1.8-degree stepper, and it’s turned 200 steps, then it’s turned 1.8 x 200 degrees, or 360 degrees, or one full revolution.
In every step of the sequence, two wires are always set to opposite polarities. Because of this, it’s possible to control steppers with only two wires instead of four, with a slightly more complex circuit. The stepping sequence is the same as it is for the two middle wires of the sequence above:
|Step||wire 1||wire 2|
The circuits for two-wire stepping are as follows:
Unipolar stepper two-wire circuit:
Biolar stepper two-wire circuit:
Because both unipolar and bipolar stepper motors are controlled by the same stepping sequence, we can use the same microcontroller code to control either one. In the code examples below, connect either the Darlington transistor array (for unipolar steppers) or the dual H-bridge (for bipolar steppers) to the pins of your microcontroller as described in each example. There is a switch attached to the microcontroller as well. When the switch is high, the motor turns one direction. When it’s low, it turns the other direction.
Understanding the 28BYJ-48 Stepper motor
We will use unipolar stepper motor 28BYJ-48 for this project. The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5 volts. Its used in air-conditioner, vending machines and many other applications. One of the best things about unipolar stepper motors is that they can be positioned accurately, one step at a time. They are quite precise in their movement, reliable since the motor does not use contact brushes, give good torque even in the stand-still state which is maintained as long as power is supplied to the motor. The downside of them is that they are consuming power even when they are not moving.
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.
There are many types of drivers – L293, ULN2003, A3967SLB and more. The 28BYJ-48 even comes with breakout using ULN2003 as a motor driver chip.
Datasheet can be found here.
Understanding the ULN2003 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).
The board also comes with an ON/OFF jumper to isolate power to the stepper Motor.
Signals and connections of the ULN2003 driver board
- IN1 – IN4 – used to drive the motor. Connect them to a digital output pins on the Arduino.
- GND – ground pin.
- VDD – 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 – where the motor plugs into. The connector is keyed, so it only goes in one way.
Signals and connections of the 28BYJ-48 Stepper motor
Note: if you want to use L293 instead of ULN2003 you will need to leave Red wire No connection.
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.
See the video here: https://youtu.be/E_C5ZcgGxL0
Step by Step instruction
- Do wiring.
- Open Arduino IDE.
- Plug your Arduino Uno board into your PC USB port.
- Select the correct board and COM port in the Arduino IDE.
- You must take something in consider: 28BYJ-48 has a gear ratio of 64 and stride angle 5.625 so this motor has a 4096 Steps. Number of Steps in one revolution= 360/stride angle=360/5.625=64. Steps =Number of steps in One Revolution * Gear ratio. Steps= (360/5.625)*64 = 64 * 64 =4096 – this value will substitute it in the arduino sketch.
- For Adafruit Stepper Motor the stride angle 7.5 and gear ratio is 16. So number of steps in 1 revolution will be : steps in One Revolution = 360 / 7.5 = 48. Steps= 48 * 16 = 768. It will be different depending on what motor you are using so check the datasheet for your stepper motor to calibrate these values.
- Verify and upload the the sketch to your Adruino Uno.
We have learnt how to control 28BYJ-48 Stepper Motor with LEDs and Arduino board.
Check for more DIY projects here.