Stepper Motor Control - Precise Rotation Control
Objective: Control a stepper motor to rotate in both clockwise and counter-clockwise directions with precise steps.
This project demonstrates motor control using the Stepper library for applications requiring precise positioning and movement control.
Required Components:
- Arduino Uno/Nano
- 28BYJ-48 Stepper Motor or similar
- ULN2003 Motor Driver Board
- External Power Supply (5V recommended)
- Jumper wires
- Breadboard (optional)
#include
const int spr=4;
Stepper steper (spr, 8, 9, 10,11) ;
void setup () {
steper.setSpeed (10);
Serial.begin (9600);
}
void loop () {
steper.step (40) ;
delay (1) ;
steper.step(-40);
delay (1) ;
}
How it works:
- Stepper Library: Arduino's built-in library for controlling stepper motors.
- SPR (Steps Per Revolution): Set to 4 for this motor configuration.
- Pin Configuration: Uses pins 8, 9, 10, 11 for motor control signals.
- setSpeed(10): Sets motor speed to 10 RPM for smooth operation.
- step(40): Rotates motor 40 steps clockwise.
- step(-40): Rotates motor 40 steps counter-clockwise.
- Continuous Loop: Creates oscillating back-and-forth movement.
Circuit Connection (ULN2003 Driver):
- IN1 → Arduino Pin 8
- IN2 → Arduino Pin 9
- IN3 → Arduino Pin 10
- IN4 → Arduino Pin 11
- VCC → 5V Power Supply
- GND → Ground (Common with Arduino)
- Motor pins to stepper motor connector
Applications:
- Camera pan/tilt systems
- 3D printer axis control
- Robotic arm joints
- Automated blinds/curtains
- CNC machine positioning