Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

How To Control a 28BYJ-48 Stepper Motor with a Joystick DIY Project using Arduino NANO & 28BYJ-48 Stepper Motor by WTC Zone

 

To control a 28BYJ-48 stepper motor using a joystick and Arduino Nano, follow these steps:


Components Required

  1. Arduino Nano
  2. 28BYJ-48 Stepper Motor
  3. ULN2003 Stepper Motor Driver Module
  4. Joystick Module
  5. Jumper Wires
  6. Breadboard
  7. Power Source (USB or 5V external)

Connections

  1. Joystick Module:

    • VCC5V on Arduino Nano
    • GNDGND on Arduino Nano
    • VRx (Horizontal)A0 on Arduino Nano
    • VRy (Vertical)A1 on Arduino Nano (optional for additional control)
  2. ULN2003 Driver:

    • IN1D2 on Arduino Nano
    • IN2D3 on Arduino Nano
    • IN3D4 on Arduino Nano
    • IN4D5 on Arduino Nano
    • GNDGND on Arduino Nano
    • VCC → External 5V power supply or Arduino 5V
  3. 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 motor
const int stepsPerRevolution = 2048; // 28BYJ-48 has 2048 steps/rev in full-step mode

// Initialize the stepper motor
Stepper myStepper(stepsPerRevolution, 2, 4, 3, 5); // IN1, IN3, IN2, IN4 (order matters)

// Joystick pin
const int joystickPin = A0; // Horizontal axis (VRx)

// Variables for joystick control
int 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);
  }
}
 
----------------------------------------------------------------------

Working Explanation

  1. Joystick Control:

    • The joystick's horizontal axis (VRx) is read on pin A0.
    • The analog value (0-1023) is mapped to a speed range of -10 to +10 RPM, where:
      • Negative values → Motor rotates counterclockwise.
      • Positive values → Motor rotates clockwise.
      • Zero value → Motor stops.
  2. Stepper Motor Control:

    • The Stepper library controls the motor's steps based on the mapped speed.
    • Small steps are taken in each loop to allow smooth joystick control.
  3. Serial Monitor:

    • Prints joystick values and motor speed for debugging.

Tips

  1. Power Supply:

    • Use an external 5V power supply for the ULN2003 driver if the motor stalls or doesn't move smoothly.
  2. Speed Adjustment:

    • Modify the map() function to adjust the speed range, e.g., map(joystickValue, 0, 1023, -20, 20) for a faster response.
  3. Dual-Axis Control:

    • Use the joystick's vertical axis (VRy on A1) for additional features, such as controlling another stepper motor or other functions.

Test the setup, and let me know if it works or if you need additional modifications! 😊


This setup and code will create a fun and responsive digital dice using your 7-segment servo display. Let me know if you encounter any issue.

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

Post a Comment

0 Comments

Ad Code

Responsive Advertisement