๐ŸŽฎ๐Ÿ”ฅ 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? ๐Ÿค–๐Ÿ”ฅ

๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply