Post Top Ad

Sunday, February 11, 2024

28BYJ-48 stepper motor controlled by ULN2003 and ESP8266.


28BYJ-48 stepper motor controlled by ULN2003 and ESP8266.

Within this tutorial, you will acquire the skills needed to manage a stepper motor using the ESP8266 NodeMCU board. Our approach entails employing the 28BYJ-48 unipolar stepper motor coupled with the ULN2003 motor driver. The programming aspect involves harnessing the Arduino IDE to interact with the ESP8266 board.


To follow this tutorial, you need the following parts:


28BYJ-48 Stepper Motor

ULN2003 Motor Driver

ESP8266

Jumper Wires

5V Power Supply

A stepper motor represents a brushless DC electric motor that segments a complete rotation into discrete steps. With each step being of identical magnitude, the motor advances one step at a time. This precise movement allows the motor to be rotated by a specific angle, achieving a precise position. The stepper motor’s rotation can occur in either a clockwise or counterclockwise direction.


The accompanying image showcases a pair of 28BYJ-48 stepper motors.


Stepper motors encompass internal coils that induce stepwise motion of the motor shaft in either direction when electric current is applied to the coils in a defined manner.


Two variants of stepper motors exist: unipolar and bipolar stepper motors.


In this article, we won’t delve into the intricate details of how stepper motors are constructed and their internal operations. For an in-depth understanding of their functioning and the distinctions between the different types of stepper motors, we recommend perusing the article provided by the DroneBotWorkshop blog.

  Overview of the 28BYJ-48 Stepper Motor

Stepper motors come with various specifications tailored to their unique functionalities. This guide centers around the widely employed 28BYJ-48 unipolar stepper motor, paired harmoniously with the ULN2003 motor driver.


Prominent Features of the 28BYJ-48 Stepper Motor

For a comprehensive grasp of the stepper motor’s defining characteristics, consult the datasheet:


Rated voltage: 5V DC

Number of phases: 4

Speed variation ratio: 1/64

Stride angle: 5.625º/64

Frequency: 100Hz

The 28BYJ-48 stepper motor comprises four coils in total. These coils are linked at one end to the motor’s red wire, connected to a 5V source. The opposite ends of these coils correspond to wires tinted in blue, pink, yellow, and orange. Activating the coils sequentially generates a step-by-step motion of the motor in either direction.

In half-step mode, the 28BYJ-48 Stepper Motor upholds a stride angle of 5.625°/64. This translates to the requirement of 64 steps (360º/5.625º = 64 steps) to complete a full revolution in half-step mode. When operating in full-step mode, this count decreases to 32 steps, resulting in one complete rotation.


However, an integral gear ratio of 64:1 influences the output shaft. This implies that for every 64 revolutions executed by the internal motor, the external shaft accomplishes a single revolution. Consequently, the motor must execute 32×64 = 2048 steps to realize a full rotation of the external shaft. This level of precision corresponds to a step angle of 360º/2048 steps = 0.18º/step.


To sum up:

Total steps per revolution = 2048 steps

Step angle = 0.18º/step

If you’re utilizing a distinct stepper motor, we recommend consulting the pertinent datasheet for a comprehensive understanding.

To establish a connection between the ESP8266 NodeMCU board and the stepper motor, we will employ the ULN2003 motor driver, depicted in the diagram below. Notably, the 28BYJ-48 stepper motor is frequently bundled with the ULN2003 motor driver.


This module features a convenient connector that simplifies the process of linking the motor to the module. The module incorporates four input pins dedicated to controlling the coils responsible for the stepper motor’s motion. Additionally, the inclusion of four LEDs offers a visual representation of the coils’ operational status.


The module includes pins designated for connecting VCC and GND, alongside a jumper cap that functions as an ON/OFF switch for powering the stepper motor. Removing the jumper effectively cuts off the power supply to the motor. For those desiring manual control, these pins can serve as connections for a physical switch.

This section outlines the steps to connect the stepper motor to the ESP8266 using the ULN2003 motor driver.


To achieve this, we will link IN1, IN2, IN3, and IN4 to GPIO pins 5, 4, 14, and 12 respectively. If needed, you have the flexibility to choose other appropriate digital pins by referring to our ESP8266 pinout reference guide.


For a clearer understanding of the process, please refer to the schematic diagram provided below.

To effectively control stepper motors using a microcontroller, we will employ the AccelStepper library. This library serves as a valuable tool for our purpose of controlling the stepper motor with the ESP8266. It simplifies tasks such as defining the motor's movement in terms of steps, setting speed and acceleration parameters, and more.


The library is well-documented nted, offering clear explanations of its various methods. You can access the detailed documentation here.


To integrate the AccelStepper library into your Arduino IDE, proceed with the following steps:


Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries…

  In the Library Manager, search for “accelstepper”.

  Locate and install the AccelStepper library developed by Mike McCauley. We will be using version 1.61.0 for this purpose.

Controlling the Stepper Motor With ESP8266 – Code

To implement stepper motor control using the ESP8266, copy the following code into your Arduino IDE. This example demonstrates continuous clockwise and counterclockwise rotations of the motor.


28BYJ-48 stepper motor controlled by ULN2003 and ESP8266.

Within this tutorial, you will acquire the skills needed to manage a stepper motor using the ESP8266 NodeMCU board. Our approach entails employing the 28BYJ-48 unipolar stepper motor coupled with the ULN2003 motor driver. The programming aspect involves harnessing the Arduino IDE to interact with the ESP8266 board.


To follow this tutorial, you need the following parts:


28BYJ-48 Stepper Motor

ULN2003 Motor Driver

ESP8266

Jumper Wires

5V Power Supply

A stepper motor represents a brushless DC electric motor that segments a complete rotation into discrete steps. With each step being of identical magnitude, the motor advances one step at a time. This precise movement allows the motor to be rotated by a specific angle, achieving a precise position. The stepper motor’s rotation can occur in either a clockwise or counterclockwise direction.


The accompanying image showcases a pair of 28BYJ-48 stepper motors.


Stepper motors encompass internal coils that induce stepwise motion of the motor shaft in either direction when electric current is applied to the coils in a defined manner.


Two variants of stepper motors exist: unipolar and bipolar stepper motors.


In this article, we won’t delve into the intricate details of how stepper motors are constructed and their internal operations. For an in-depth understanding of their functioning and the distinctions between the different types of stepper motors, we recommend perusing the article provided by the DroneBotWorkshop blog.

  Overview of the 28BYJ-48 Stepper Motor

Stepper motors come with various specifications tailored to their unique functionalities. This guide centers around the widely employed 28BYJ-48 unipolar stepper motor, paired harmoniously with the ULN2003 motor driver.


Prominent Features of the 28BYJ-48 Stepper Motor

For a comprehensive grasp of the stepper motor’s defining characteristics, consult the datasheet:


Rated voltage: 5V DC

Number of phases: 4

Speed variation ratio: 1/64

Stride angle: 5.625º/64

Frequency: 100Hz

The 28BYJ-48 stepper motor comprises four coils in total. These coils are linked at one end to the motor’s red wire, connected to a 5V source. The opposite ends of these coils correspond to wires tinted in blue, pink, yellow, and orange. Activating the coils sequentially generates a step-by-step motion of the motor in either direction.

In half-step mode, the 28BYJ-48 Stepper Motor upholds a stride angle of 5.625°/64. This translates to the requirement of 64 steps (360º/5.625º = 64 steps) to complete a full revolution in half-step mode. When operating in full-step mode, this count decreases to 32 steps, resulting in one complete rotation.


However, an integral gear ratio of 64:1 influences the output shaft. This implies that for every 64 revolutions executed by the internal motor, the external shaft accomplishes a single revolution. Consequently, the motor must execute 32×64 = 2048 steps to realize a full rotation of the external shaft. This level of precision corresponds to a step angle of 360º/2048 steps = 0.18º/step.


To sum up:

Total steps per revolution = 2048 steps

Step angle = 0.18º/step

If you’re utilizing a distinct stepper motor, we recommend consulting the pertinent datasheet for a comprehensive understanding.

To establish a connection between the ESP8266 NodeMCU board and the stepper motor, we will employ the ULN2003 motor driver, depicted in the diagram below. Notably, the 28BYJ-48 stepper motor is frequently bundled with the ULN2003 motor driver.


This module features a convenient connector that simplifies the process of linking the motor to the module. The module incorporates four input pins dedicated to controlling the coils responsible for the stepper motor’s motion. Additionally, the inclusion of four LEDs offers a visual representation of the coils’ operational status.


The module includes pins designated for connecting VCC and GND, alongside a jumper cap that functions as an ON/OFF switch for powering the stepper motor. Removing the jumper effectively cuts off the power supply to the motor. For those desiring manual control, these pins can serve as connections for a physical switch.

This section outlines the steps to connect the stepper motor to the ESP8266 using the ULN2003 motor driver.


To achieve this, we will link IN1, IN2, IN3, and IN4 to GPIO pins 5, 4, 14, and 12 respectively. If needed, you have the flexibility to choose other appropriate digital pins by referring to our ESP8266 pinout reference guide.


For a clearer understanding of the process, please refer to the schematic diagram provided below.

To effectively control stepper motors using a microcontroller, we will employ the AccelStepper library. This library serves as a valuable tool for our purpose of controlling the stepper motor with the ESP8266. It simplifies tasks such as defining the motor's movement in terms of steps, setting speed and acceleration parameters, and more.


The library is well-documented nted, offering clear explanations of its various methods. You can access the detailed documentation here.


To integrate the AccelStepper library into your Arduino IDE, proceed with the following steps:


Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries…

  In the Library Manager, search for “accelstepper”.

  Locate and install the AccelStepper library developed by Mike McCauley. We will be using version 1.61.0 for this purpose.

Controlling the Stepper Motor With ESP8266 – Code

To implement stepper motor control using the ESP8266, copy the following code into your Arduino IDE. This example demonstrates continuous clockwise and counterclockwise rotations of the motor.

No comments:

Post a Comment

Post Top Ad

Pages