Build a Mechanical Piano Art Robot!
Little robot fingers press the keys, a string of LEDs lights up in time with every note, and a screen shows what's playing — music and light working together, built by you.
📋 What's inside this project
🧰 What You'll Need
Gather these parts before you start — most are common hobby-electronics components.
Arduino Uno (1x)
The brain that plays the song and controls everything.
SG90 micro servos (8x)
One per key — each presses a single note.
Small keyboard or 8 key levers
A toy keyboard works great, or build simple lever keys yourself.
WS2812 addressable LED strip (8+ pixels)
Lights up in sync with the notes being played.
16x2 I2C LCD
Displays the name of the song that's playing.
Small piezo buzzer
Plays the actual musical notes.
Push button (1x)
Starts the performance.
5–6V external power supply
Powers all 8 servos without overloading the Arduino.
Wooden frame or box
Holds the servos above the keys, like the model in the photo.
⚙️ How Does It Work?
Each of the 8 keys has its own tiny servo motor perched above it. When the Arduino wants to play a note, it tells that key's servo to swing its little arm down, tap the key, and lift back up — just like a finger.
At the very same moment, the matching LED on the strip lights up in colour, and the buzzer sounds the note's pitch. Because all three things — the key press, the light, and the sound — are triggered together in the code, the light show always stays perfectly in time with the music.
The LCD screen simply displays the name of the song, so anyone watching knows exactly what the robot is performing.
🔌 The Circuit Diagram
Servos have their own built-in driver, so each one connects straight to an Arduino pin — no extra motor driver board needed.
| Connection | Goes to | Notes |
|---|---|---|
| Arduino digital pins 2–9 | Signal wire of each of the 8 servos | One pin per key servo |
| External 5–6V supply | All servo power (+) wires | Keeps the Arduino's own 5V rail free |
| Supply GND | Arduino GND | Common ground — required for signals to work |
| Arduino pin 10 | WS2812 LED strip data-in | Add a 300–500Ω resistor on the data line if flickery |
| Arduino A4 / A5 | LCD SDA / SCL | Standard I2C connection |
| Arduino pin 11 | Buzzer (+) | Plays each note's pitch |
| Arduino pin 12 | Push button | Use `INPUT_PULLUP`, button to GND |
🛠️ Let's Build It — Step by Step
Prepare the keyboard
Use a small toy keyboard, or build 8 simple lever "keys" from craft sticks that can be pressed down.
Mount the servos
Fix a servo above each key so its horn arm can swing down and tap the key when it turns.
Wire the servos
Connect each servo's signal wire to its own Arduino pin, and power all eight from the external 5–6V supply with a shared ground.
Attach the LED strip
Mount the WS2812 strip where it's easy to see, and connect its data pin, 5V, and ground.
Add the LCD, buzzer, and button
Wire the LCD over I2C, the buzzer to a digital pin, and the push button with a pull-up resistor.
Upload the code
Flash the sketch from the next section using the Arduino IDE, with the required libraries installed.
Calibrate each key
Test one servo at a time and adjust its press angle until it taps its key firmly but gently.
Press play!
Push the button and watch your robot perform — keys pressing, lights dancing, and music playing all together.
💻 Time to Code!
This sketch moves each key's servo, lights its matching LED, and sounds its note — all at once, in time with the song.
Install the Servo, Adafruit NeoPixel, and LiquidCrystal I2C libraries from the Library Manager, then upload this sketch to your Arduino Uno.
// Mechanical Piano Art Robot // Presses keys with servos, lights LEDs, and plays notes together #include <Servo.h> #include <Adafruit_NeoPixel.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #define NUM_KEYS 8 #define LED_PIN 10 #define BUZZER_PIN 11 #define BUTTON_PIN 12 Servo keyServo[NUM_KEYS]; const int servoPins[NUM_KEYS] = {2,3,4,5,6,7,8,9}; Adafruit_NeoPixel strip(NUM_KEYS, LED_PIN, NEO_GRB + NEO_KHZ800); LiquidCrystal_I2C lcd(0x27, 16, 2); const int restAngle = 90; // key resting position const int pressAngle = 60; // key pressed position const int noteFreq[NUM_KEYS] = {262,294,330,349,392,440,494,523}; // C4–C5 // Which key to press, and how long each note lasts (ms) struct Note { int key; int duration; }; Note song[] = { {0,400},{0,400},{4,400},{4,400}, {5,400},{5,400},{4,800}, {3,400},{3,400},{2,400},{2,400}, {1,400},{1,400},{0,800} }; const int songLength = sizeof(song) / sizeof(song[0]); void setup() { for (int i = 0; i < NUM_KEYS; i++) { keyServo[i].attach(servoPins[i]); keyServo[i].write(restAngle); } strip.begin(); strip.show(); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Press button"); lcd.setCursor(0, 1); lcd.print("to play song"); pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { if (digitalRead(BUTTON_PIN) == LOW) { playSong(); } } void playSong() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Now Playing:"); lcd.setCursor(0, 1); lcd.print("Twinkle Star"); for (int i = 0; i < songLength; i++) { playNote(song[i].key, song[i].duration); } strip.clear(); strip.show(); } void playNote(int key, int duration) { tone(BUZZER_PIN, noteFreq[key], duration); // sound the note strip.clear(); strip.setPixelColor(key, strip.Color(0, 150, 255)); // light the matching LED strip.show(); keyServo[key].write(pressAngle); // press the key delay(duration); keyServo[key].write(restAngle); // release the key delay(50); }
pressAngle in small steps until each key is tapped firmly without straining the servo.🛡️ Safety First
Keep it safe while you build and perform:
- Ask an adult to help with wiring and setting up the power supply.
- Keep fingers away from the keys while the robot is playing — the servo arms move quickly.
- Use a power supply sized for 8 servos, and never let the LED strip or servos share power with the Arduino's own 5V pin.
- Always connect the external supply's ground to the Arduino's ground.
- Turn off power before changing any wiring or servo mounting.
✨ Fun Piano Facts
A little history to enjoy while your robot performs.
Self-playing "player pianos" that used punched paper rolls were popular over a century ago.
Turning sound into light is called audio-visualisation, and artists use it in concerts worldwide.
A full-size piano has 88 keys — your 8-key robot plays one octave of notes.
Robots that make music sit at the crossroads of engineering, coding, and art.
❓ Frequently Asked Questions
How does a mechanical piano robot press its own keys?
A small servo motor sits above each key. When the Arduino sends it a command, it swings an arm down to press the key, then lifts back up — just like a tiny mechanical finger.
Do I need a motor driver board for the servos?
No. Hobby servos have their own built-in driver and only need a signal wire connected directly to the Arduino, plus power and ground. A board like an L298N is only needed for plain DC motors, not servos.
What makes the LEDs match the music?
Every time the code presses a key, it lights the matching LED at the same moment, so the light pattern always stays in sync with the notes.
Is this project safe for kids to build?
Yes, with adult supervision for wiring and the power supply. Fingers should stay clear of the keys while the robot is playing.

Comments
Post a Comment