Table of Contents
ToggleHave you ever wanted to directly control a robot arm or servo-driven mechanism with your hands? In this tutorial, you’ll learn how to control a servo motor with joystick and OLED display using an Arduino. By the end, you’ll move two servo motors smoothly with a simple joystick and get real-time feedback on a small OLED screen. This project is beginner-friendly but also expandable for more complex robotics.
Components Needed
Here’s the bill of materials (BOM) for this project:
| Component | Quantity | Notes |
|---|---|---|
| Arduino Uno (or Nano) | 1 | Main microcontroller board |
| Joystick module (XY + SW) | 1 | Two analog axes + push button |
| Servo motor (SG90 or MG90S) | 2 | Small hobby servos |
| OLED Display (SSD1306, I2C) | 1 | 128×64 pixels, 3.3–5 V compatible |
| Breadboard + jumper wires | – | For wiring connections |
| External 5 V power supply | 1 | For stable servo power |
Electrical Diagram and Wiring
| Component | Arduino Pin |
|---|---|
| Joystick VRx | A0 |
| Joystick VRy | A1 |
| Joystick SW | D2 (optional) |
| Servo 1 Signal | D9 |
| Servo 2 Signal | D10 |
| OLED SDA | A4 |
| OLED SCL | A5 |
| Servo +V | External 5 V |
| Servo GND | Common GND |
Programming the Arduino
#include <Servo.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Servo setup
Servo servoX;
Servo servoY;
int joyX = A0;
int joyY = A1;
int servoXPin = 9;
int servoYPin = 10;
void setup() {
servoX.attach(servoXPin);
servoY.attach(servoYPin);
// OLED init
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for(;;); // Halt if display not found
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
int xVal = analogRead(joyX);
int yVal = analogRead(joyY);
int angleX = map(xVal, 0, 1023, 0, 180);
int angleY = map(yVal, 0, 1023, 0, 180);
servoX.write(angleX);
servoY.write(angleY);
// OLED output
display.clearDisplay();
display.setCursor(0,0);
display.print("Servo X: "); display.println(angleX);
display.print("Servo Y: "); display.println(angleY);
display.display();
delay(50); // small debounce
}
Tests
-
-
Move joystick left/right → Servo X moves.
-
Move joystick up/down → Servo Y moves.
-
OLED shows values correctly.
Calibration tip: If servos twitch at idle, add a dead-zone around center joystick values (≈ 480–540).
Troubleshooting checklist:
-
No display? Check SDA/SCL wiring.
-
Servos jitter? Use external 5 V supply.
-
Wrong angles? Swap joystick axis mapping.
-
Conclusion
You’ve built a working system to control a servo motor with joystick and OLED display. This simple setup can be extended into a robot arm, pan-tilt camera mount, or even a mini drawing robot. Share your project results in the comments!
