🎮🔥 How to control both the SG90 servo and the 28BYJ-48 stepper motor with the joystick. This is a great setup for a robotic arm or a turret-like system!


🔹 How It Will Work

  • Joystick X-axis → Controls the stepper motor (left/right rotation).
  • Joystick Y-axis → Controls the servo motor (up/down movement).

🔹 Components Needed

Arduino (Uno/Nano/etc.)
SG90 Servo Motor
28BYJ-48 Stepper Motor + ULN2003 Driver
Joystick Module (KY-023 or similar)
Jumper Wires & Breadboard


🔹 Circuit Connections

🔸 28BYJ-48 Stepper to ULN2003 Driver

Stepper WireULN2003 Pin
RedVCC (5V)
BlueIN1
PinkIN2
YellowIN3
OrangeIN4
BlackGND

🔸 ULN2003 Driver to Arduino

ULN2003 PinArduino Pin
IN18
IN29
IN310
IN411
VCC5V
GNDGND

🔸 SG90 Servo to Arduino

Servo PinArduino Pin
VCC (Red)5V
GND (Brown/Black)GND
Signal (Orange)Pin 6

🔸 Joystick to Arduino

Joystick PinArduino Pin
VCC5V
GNDGND
VRX (X-axis)A0
VRY (Y-axis)A1

🔹 Arduino Code (Joystick Control for Both Motors)

#include <Servo.h>
#include <Stepper.h>

const int stepsPerRevolution = 2048;  // Steps per full rotation for 28BYJ-48
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);  // Stepper connected to pins 8,9,10,11

Servo myServo;  // Servo object

int joyX = A0;  // Joystick X-axis
int joyY = A1;  // Joystick Y-axis

void setup() {
    myStepper.setSpeed(10);  // Set stepper speed (adjustable)
    myServo.attach(6);  // Attach servo to Pin 6
}

void loop() {
    int xValue = analogRead(joyX);  // Read joystick X-axis (0-1023)
    int yValue = analogRead(joyY);  // Read joystick Y-axis (0-1023)

    // Control Stepper Motor (Left/Right Movement)
    if (xValue < 400) {  
        myStepper.step(-10);  // Move stepper left
    } 
    else if (xValue > 600) {  
        myStepper.step(10);  // Move stepper right
    }

    // Control Servo Motor (Up/Down Movement)
    int servoAngle = map(yValue, 0, 1023, 0, 180);  // Convert joystick value to 0-180°
    myServo.write(servoAngle);
}

🔹 How It Works

  • Move joystick left/right → The stepper rotates left/right.
  • Move joystick up/down → The servo tilts up/down.
  • When centered, both motors stay in their current positions.

🔹 Next Steps & Enhancements

🔥 Smooth Stepper Movement: Instead of step(-10) or step(10), try map(xValue, 0, 1023, -50, 50).
🔥 Button Control: Add a button to reset both motors to their default position.
🔥 Speed Control: Use joystick press (SW pin) to switch between fast and slow movement.


🚀 What’s Next?

Would you like to add another servo for a robotic arm? 🤖🔥

Leave a Reply