To control a 28BYJ-48 stepper motor using a joystick and Arduino Nano, follow these steps:
Components Required
- Arduino Nano
- 28BYJ-48 Stepper Motor
- ULN2003 Stepper Motor Driver Module
- Joystick Module
- Jumper Wires
- Breadboard
- Power Source (USB or 5V external)
Connections
Joystick Module:
- VCC → 5V on Arduino Nano
- GND → GND on Arduino Nano
- VRx (Horizontal) → A0 on Arduino Nano
- VRy (Vertical) → A1 on Arduino Nano (optional for additional control)
ULN2003 Driver:
- IN1 → D2 on Arduino Nano
- IN2 → D3 on Arduino Nano
- IN3 → D4 on Arduino Nano
- IN4 → D5 on Arduino Nano
- GND → GND on Arduino Nano
- VCC → External 5V power supply or Arduino 5V
Stepper Motor:
- Connect the stepper motor to the ULN2003 driver module (dedicated 5-pin connector).
Circuit Diagram
Video Link: - Click Here For Video
How To Control a 28BYJ-48 Stepper Motor with a Joystick DIY Project WTC Zone simple Circuit: -
How To Control a 28BYJ-48 Stepper Motor with a Joystick DIY Project WTC Zone Arduino Programming: -
Arduino IDE Program
Code for a 28BYJ-48 Stepper Motor with a Joystick DIY Project WTC Zone
#include <Stepper.h>
// Define the number of steps per revolution for the 28BYJ-48 motorconst int stepsPerRevolution = 2048; // 28BYJ-48 has 2048 steps/rev in full-step mode
// Initialize the stepper motorStepper myStepper(stepsPerRevolution, 2, 4, 3, 5); // IN1, IN3, IN2, IN4 (order matters)
// Joystick pinconst int joystickPin = A0; // Horizontal axis (VRx)
// Variables for joystick controlint joystickValue = 0;int stepSpeed = 0;const int deadZone = 50; // Define a dead zone around the center value
void setup() { // Set the motor speed (RPM) myStepper.setSpeed(10); // Initial speed Serial.begin(9600); // Start Serial Monitor for debugging}
void loop() { // Read joystick value (0-1023) joystickValue = analogRead(joystickPin);
// Map joystick value to speed range (-10 to +10 RPM) stepSpeed = map(joystickValue, 0, 1023, -10, 10);
// Apply the dead zone if (abs(stepSpeed) < deadZone / 10) { stepSpeed = 0; // Stop motor if within the dead zone }
// Print joystick and speed for debugging Serial.print("Joystick Value: "); Serial.print(joystickValue); Serial.print(" | Step Speed: "); Serial.println(stepSpeed);
// Rotate the stepper motor based on the speed if (stepSpeed > 0) { myStepper.setSpeed(stepSpeed); myStepper.step(stepsPerRevolution / 100); // Small step forward } else if (stepSpeed < 0) { myStepper.setSpeed(-stepSpeed); myStepper.step(-stepsPerRevolution / 100); // Small step backward } else { // Stop the motor if joystick is centered delay(10); }}
Share, Support, and Subscribe!!! 1. PRO KAM EXPLAINED 2. Knowledge KAM 3. PRO KAM Follow us on 1. Facebook 2. Instagram 3. Pinterest 4. Blogspot 5 Twitter If you have any other ideas to make me design, you can describe them in the comment section and if I can, I will make a designing video on it. So I am waiting #prokam #wtc #Arduino #ideas #projects #diy #how #to #ArduinoProjects #UltrasonicSensor #HeightMeasurement #TechDIY #WeTechCreators #wtczo
0 Comments