28BYJ-48 stepper motor

We have added the 28BYJ-48 Stepper motor to the Arduino IO Simulator and through this guide, you will learn how to use it properly. To energize the four coils of the stepper motor we are using the digital pins 8, 10, 9 and 11. The driver module (ULN2003) is processed in the simulator.

The stepper motor module has 4 LED provided that shows which coil is being energized at any given time.

In this guide, we will write the Arduino stepper motor code (example -> stepper). The program will get a value from the Simulator and will rotate the stepper motor to the value given by the simulator after clicking on a start button. The complete program can be found in the examples list of the Arduino IO Simulator Drag & Draw.

Inputs

The simulator stepper motor has 2 input fields:

  • - Sim_SPEED
  • - Sim_STEP
Stepper motor

Steps = 1 to 2048 (360°)

Speed = 1 to 200

Note: Make sure you click on the 'enter' key after adding the value for Sim_SPEED and Sim_STEP

The simulator has 2 feedback fields that show you when the Arduino received the value.

Stepper Library

The original library has been changed so that it works together with the simulator ‘Stepper_Sim.zip’.

You can find it on this directory:

C:\Program Files (x86)\ArduinoSimulator\Library or C:\Program Files\ArduinoSimulator\Library

With the Arduino IDE, you use ‘Include library’ and select ‘Add .Zip' Library to install the library ‘Stepper_Sim.zip’. You can also always download the library here.

In your Arduino sketch write #include Stepper_Sim.h to add the stepper library to your project.

Calculate the Steps per Revolution for the stepper motor

It's important to know how to calculate the steps per revolution for the stepper motor because only then you can program it effectively. In the simulator, we will be operating the motor in 4-step sequence so the stride angle will be 11.25° since it is 5.625° for 8 step sequence it will be 11.25° (5.625 * 2 = 11.25). You can also choose for a 2-step sequence but you will need to change the coil pins in the sketch. -> Stepper stepper (STEPS, 8, 10);

Steps per revolution = 360/step angle

360/11.25 = 32 steps per revolution

The number of steps per revolution for our stepper motor was calculated at 32; therefore we enter this as shown in the line below:

#define STEPS 32

Next, you have to create instances in which we specify the pins to which we have connected the stepper motor.

4 coil wires: Stepper stepper (STEPS, 8, 10, 9, 11);

2 coil wires: Stepper stepper (STEPS, 8, 10);

Stepper motor

Note: The pins number are disordered as 8, 10, 9, 11 on purpose. You have to follow the same pattern even if you change the pins to which your motor is connected.

Since we are using the Arduino stepper library, we can set the speed of the motor using the below line. The speed can range between 0 to 200 for the 28-BYJ48 stepper motor.

stepper.setSpeed(200);

To make the motor move one step we can use the following line.

stepper.step(val);

The number of steps to be moved will be provided by the variable 'val'. Since we have 32 steps and 64 as the gear ratio we need to move 2048 (32*64=2048), to make one complete rotation. The value of the variable 'val' can be entered by the user using the serial monitor.

Coil wires: 2 or 4:

Stepper motor
MotorControl

To adjust the speed of the motor you can use the provided slider and select a pin from A0-A5.

Stepper motor

Arduino code:

Stepper motor

To adjust the steps of the motor you can use the provided slider and select a pin from A0-A5.

Stepper motor

Arduino code:

Stepper motor

Note: If you can't start the stepper motor, you can click on the reset button in the simulator and it will send all the start values again. Disconnect the coil (2 or 4) and then reconnect it again.