28BYJ-48 12 V Stepper Motor Test

Stepper Series— NaveTECH & UNIR Series — Episode # 12

J3
Jungletronics

--

Hello! Prepare your setup with a 28BYJ-48 stepper motor and a DRV8825 Driver. Arrange your protoboard in the following configuration:

See the connections schema for your convenience. CAUTION: When probing the pins, if a circuit is inadvertently closed, it can cause the driver to burn out. So, please be cautious!👀💥

To test the 28BYJ-48 12V stepper motor with your Arduino UNO board, you can use the following code. First, ensure you have the necessary connections set up correctly:

  • Connect the stepper motor’s control pins (MS1, MS2, MS3, STEP, and DIR) to the corresponding digital pins on your Arduino UNO.
  • Make sure the stepper motor is powered appropriately (12V DC like this).
  • Upload the code to your Arduino UNO board using the Arduino IDE or your preferred Arduino programming environment.
Controlling 28BYJ-48 12V stepper motor without any library 👌. You got it!

See repeated code? In the next version let’s make a funtions (DRY principle, remember?)

This Arduino code controls a stepper motor, specifically the 28BYJ-48 stepper motor, which is a commonly used stepper motor for hobbyist projects. Let’s break down the code:

  1. Variable Declarations: ms1Pin, ms2Pin, ms3Pin: These variables represent the pins connected to the MS1, MS2, and MS3 pins of the stepper motor driver (Stepstick). These pins control the micro-stepping mode of the stepper motor; stepPin, dirPin: These variables represent the pins connected to the STEP and DIR pins of the stepper motor driver. The STEP pin controls the stepping action, while the DIR pin controls the direction of rotation; numSteps: This variable represents the number of steps required for a complete revolution of the stepper motor; rotations: This variable represents the number of rotations the stepper motor will perform for each mode ; delay1, delay2: These variables represent the delays between steps and between subsequent rotations, respectively; i: This variable is used as a counter in the for loops.
  2. Setup Function: Initializes serial communication for debugging purposes; Sets the specified pins as output pins;
  3. Loop Function: The main part of the code that controls the stepper motor operation; The loop consists of three sections, each corresponding to a different microstepping mode: Full step, half step, and quarter, eighth, and sixteenth steps. The other microstepping mode ( thirty-second steps) are commented out but can be enabled if needed; For each microstepping mode, the direction of rotation is set, and the appropriate MS1, MS2, and MS3 pins are set accordingly to configure the microstepping mode; Inside each loop, the stepper motor is rotated for the specified number of steps and rotations. The delay between steps allows time for the stepper motor to respond; The process repeats for each micro-stepping mode.
  4. Serial Output: The code includes debug statements that print the current micro-stepping mode to the serial monitor.
  5. Commented Out Code: The code for additional micro-stepping modes (thirty-second step) is included but commented out. We tested it on our hardware, but there was no response. We assumed that this resolution may not be compatible with this type of hardware. If you have tested it and it worked, please comment on this section so that we can see if there are any configuration mistakes we made.

Overall, this code allows you to control the 28BYJ-48 stepper motor in different micro-stepping modes (full, half, quarter, eighth, sixteenth steps, and optionally thirty-second steps) with adjustable delays and rotations.

👉Important Note:

Please, let me explain this line:

int numSteps = 680; //720;

What is the Number of steps variable?

Let’s break down the explanation of the 28BYJ-48 12V stepper motor.

Configurations:

Step Angle The 28BYJ-48 stepper motor has a step angle of 5.625 degrees per step. This means that for every pulse sent to the motor, it rotates by 5.625 degrees (for more info see this post);

Gear Ratio The motor includes a gear reduction mechanism that reduces the rotation of the output shaft. The gear ratio for this motor is 64:1;

Calculating the Effective Step AngleTo find the effective step angle after considering the gear reduction, we divide the original step angle by the gear ratio:

5.625 degrees / 64 = 0.08789 degrees per step

Number of Steps for 360-Degree RotationTo complete a full 360-degree rotation, we need to divide the total degrees in a circle (360 degrees) by the effective step angle:

360 degrees / 0.08789 degrees per step ≈ 4096.899 steps ∴
1 rotation (360°) ≈ 4096.899 steps

2 rotations (720°) ≈ 8192.1 steps ∴
→ 0.08789 * 8192.1 / 2 = 360.0018345°

Adjustment for Smooth MotionIn practice, achieving a smooth motion may require a slightly different number of steps. In this case, the code sets the numSteps variable to 680, which has been determined experimentally for smoother operation.

In summary, the 28BYJ-48 stepper motor achieves motion by rotating in discrete steps, with each step typically corresponding to 5.625 degrees. However, due to the gear reduction mechanism, the effective step angle is smaller, resulting in finer control and smoother motion. The specific number of steps required for a full 360-degree rotation may vary based on experimental tuning and requirements for smooth operation.

That’s all folks!

👉GitHub (Projects #44)

Detail of the stepper motor connections and DRV8825 driver. See 2 pins are left disconnected…
Details of my setup. We achieved this setup after considerable effort, so please be considerate when providing comments or feedback…🤗
Crono the time ⏱ : Full (5.23s) — Half (8.88s) — Quarter (17.00s) — Eighth (32.35s) — Sixteenth (66.91s) — Thirty-second (No); please compare with the NEMA 17 on the previous episode #12.
Error — when measuring the pot voltage, I mistakenly set the voltmeter to AC instead of DC. The reading on the potentiometer is 1.568 volts. When idle, it reads 13 volts in each pin. When activated, each pin reads between 6.50 and 7.60 volts, dynamically.
This is the wall adapter that is plugged into the Arduino VIN pin using a 5.4 mm barrel connector.🙌.

Related Post:

13#Episode — NEMA 17 Stepper Motor Test — Stepper Series — NaveTECH & UNIR Series

Credits & References:

09#-basicTronics — DRV8825 Driver & Stepper Motor 24BYJ48 — Operation & Theory.

51#ArduSerie — Stepper Motors — Precise Position Control — The Great Benefit of Stepper Motors — No-H-Bridge or Closed Loop Needed.

Stepper Motor — 28BYJ-48 By Achim Pieters

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!