ESP8266 NodeMCU – Controling Stepper Motor with ULN2003 Driver

In this tutorial you will learn how to use the UNL2003 driver to control a simple stepper motor. To make precise movements with control distance, such as 3D printers, then you should totally follow this tutorial.

Parts Required

The Stepper Motor and ULN2003 Driver

Figure 1

A stepper motor converts electronic signals into mechanical movement each time an incoming pulse is applied to the motor. Each pulse moves the shaft in fixed increments. If the stepper motor has a 1.8° step resolution, then in order for shaft to rotate one complete revolution, in full step operation, the stepper motor would need to receive 200 pulses, 360° ÷ 1.8 = 200.

For that to happen, we need to use stepper drives, which control how a stepper motor operates. There are three commonly used excitation modes for stepper motors: full step, half step and microstepping. These excitation modes have an effect on both the running properties and torque the motor delivers. In our case, is half step excitation mode and it is a 28BYJ-48 – 5V Stepper Motor.

So, half step excitation mode is a combination of one phase on and two phase. This results in half the basic step angle. This smaller step angle provides smoother operation due the increased resolution of the angle. We can see an example in figure 2.

Figure 2

It is not recomended to directly power the stepper motor from the output of the NodeMCU board. When the stepper motor draws too much current you can damage the Board.

In order to be able to deliver all the current to the stepper motor we will use the ULN2003 driver board. The ULN2003 is a high-voltage, high-current darlington drivers comprised of seven NPN darlington pairs. This board only uses 4. All units feature integral clamp diodes for switching inductive loads.

In figure 3 you can observe the internal transistor of one channel.

Figue 3


Figure 4

Since the voltage output of the ESP8266 NodeMCU board is 3.3V, and hence insufficient to power our stepper motor, a 9V battery was used, along with a LM7805 voltage regulator in order to feed the ULN2003 driver with the desired 5V. Connect the IN pins on the ULN2003A driver to pins on NodeMCU board:

  • IN1 pin on the ULN2003A driver to pin D1 on NodeMCU board
  • IN2 pin on the ULN2003A driver to pin D2 on NodeMCU board
  • IN3 pin on the ULN2003A driver to pin D3 on NodeMCU board
  • IN4 pin on the ULN2003A driver to pin D4 on NodeMCU board

Instaling Libraries For VS1838B

To get our stepper motor up and running, we first need to install a library to control its driver, which is the AccelStepper library. Although the Arduino IDE already includes a library for stepper motors (, this library introduces some significant improvements, such as acceleration and deceleration support, capability to control multiple simultaneous stepper motors and many more.

To install it, go to Sketch > Include Library > Manage Libraries… and then type in the research box “accelstepper”. Look for AccelStepper by Mike McCauley, click on that entry and then select Install, as shown in figure 1. This way, we are ready to start coding!

Figure 5


In this tutorial, we simply want to make the stepper motor to go back and forward in 90 and 180 degree angles and then go back to the original position (0 degrees), over and over again.

We think that, with this code, you are able to understand how to control the stepper motor, so now you just need to apply this knowledge to your future applications. Enjoy!




1 thought on “ESP8266 NodeMCU – Controling Stepper Motor with ULN2003 Driver

  1. Hi, I do think this is a great blog. I stumbledupon it 😉
    I am going to come back yet again since I saved as
    a favorite it. Money and freedom is the greatest way to change, may you be rich and
    continue to help others.

Leave a Reply

Your email address will not be published. Required fields are marked *