Lesson 107-1: Start and Stop the 28BYJ-48 Stepper Motor with Direction Set in Code

Video thumbnail for Using 28BYJ-48 Stepper Motor Push button Speed with 8 projects: Ultimate Video Tutorial Lesson 107

Lesson 107-1: Start and Stop the 28BYJ-48 Stepper Motor with Direction Set in Code

Project 1: Basic Motor Control – 28BYJ-48 Stepper Motor

This article is part of a comprehensive video tutorial that demonstrates 8 practical projects using the 28BYJ-48 stepper motor. Each project highlights a different method of controlling the motor, from simple logic to serial communication and user interfaces. The source code and wiring diagrams for each project are provided below this article for your reference and implementation.

🔧 Introduction

The 28BYJ-48 stepper motor is a popular, low-cost motor often used in embedded systems, IoT projects, and automation tasks. This first project provides a foundation by demonstrating basic motor control: how to rotate the stepper motor forward and backward using Arduino code.

This serves as the building block for more advanced projects covered in the series.


⚙️ Wiring Diagram

The wiring for Project 1 is straightforward. The 28BYJ-48 stepper motor is connected to the ULN2003 driver board, which then interfaces with an Arduino Uno as follows:

  • IN1 → Arduino pin 8

  • IN2 → Arduino pin 9

  • IN3 → Arduino pin 10

  • IN4 → Arduino pin 11

  • 5V and GND from Arduino to ULN2003

Caption: Wiring diagram for Project 1: Basic Motor Control using ULN2003 driver.


💻 Code Explanation

This project uses the Stepper library included with the Arduino IDE. The core logic is as follows:

  1. Library Import and Constants:

#include <Stepper.h>
const int stepsPerRevolution = 2048;
  1. Stepper Object Initialization:

Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

Note the pin order matches the motor coil sequence for smooth operation.

  1. Setup Function:

void setup() {
  myStepper.setSpeed(10);
  Serial.begin(9600);
}
  • Sets speed to 10 RPM.

  • Starts the serial monitor for debugging.

  1. Loop Function:

void loop() {
  myStepper.step(stepsPerRevolution); // Forward rotation
  delay(1000);
  myStepper.step(-stepsPerRevolution); // Reverse rotation
  delay(1000);
}
  • The motor turns one full revolution forward, then backward.

This simple control logic helps verify motor operation and wiring integrity.


🎬 Timestamps from Full Video

For in-depth visual guidance, refer to the following points in the full video:

  • 00:00 – Start

  • 02:03 – Introduction to stepper motor

  • 07:40 – How motor is controlled

  • 13:08 – Wiring explained

  • 15:43 – Project 1 code

  • 20:12 – Project 1 demonstration


📁 Download Section

Links to the complete source code and wiring diagrams for this project are provided below this article.

Stay tuned for [Project 2: Controlling Stepper Motor via Serial Monitor] where we expand functionality through user interaction in the Arduino Serial Monitor.


Code Snippets

Comments will be displayed here.