๐ฎ๐ฅ 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!
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 Wire
ULN2003 Pin
Red
VCC (5V)
Blue
IN1
Pink
IN2
Yellow
IN3
Orange
IN4
Black
GND
๐ธ ULN2003 Driver to Arduino
ULN2003 Pin
Arduino Pin
IN1
8
IN2
9
IN3
10
IN4
11
VCC
5V
GND
GND
๐ธ SG90 Servo to Arduino
Servo Pin
Arduino Pin
VCC (Red)
5V
GND (Brown/Black)
GND
Signal (Orange)
Pin 6
๐ธ Joystick to Arduino
Joystick Pin
Arduino Pin
VCC
5V
GND
GND
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.