Arduino — Music Box
Press the button, hear a complete melody. Arrays + delays = music.
Arduino
Buzzer
tone()
Array
Music
Melody
What you will learn
- How to store a sequence of numbers in an int array
- How tone(pin, frequency, duration) plays one note for a fixed time
- How delay() creates the pause between notes (so the melody does not blur into one long tone)
- How a button press triggers a single, complete song — like a real music box
What you will need
| Component |
|---|
| 1× Arduino Uno R3 |
| 1× pushbutton |
| 1× buzzer (piezo) |
| 1× 100Ω resistor (for the buzzer) |
| 1× breadboard |
| 5× jumper wires |
Step by step
Take it further
- Change the melody to "Happy Birthday" or "Mary Had a Little Lamb" — just change the two arrays.
- Add a second button: one plays Twinkle Twinkle, the other plays Happy Birthday.
- Add an LED that blinks ON for each note (use the durations array for the blink timing).
- Print each note to Serial as it plays: Serial.println(notes[i]) — watch the array walk by.
- Try changing the SPEED: replace 400 with 200 (twice as fast) or 800 (twice as slow).
Practise it before you build it
Wire this circuit in the ThinkEdge Learn simulator first. The simulator runs a real Arduino sketch against a modified-nodal-analysis solver, so the LED on screen actually lights when the current is right — no hardware, no burnt components, and a class can try it in a browser.
Related projects
Arduino — Button + Buzzer DoorbellPress the button, hear a tone. The classic Arduino starter.
Arduino Nano — 4-Note Mini PianoFour buttons, four notes, one tiny piano that fits in your pocket
Arduino — Potentiometer Tone ControlTurn the knob, hear the pitch change in real time
Police SirenAlternating red + blue LEDs with a wailing 600–1500 Hz buzzer
Ultrasonic — Reverse Parking SensorBeep faster as you get closer
Simon Says — Memory GameRepeat the pattern, level by level
Where this project sits
It is also part of these lists, which is how a class usually finds it.
Arduino push button projects for beginners14 projects in this list
Arduino buzzer and tone projects19 projects in this list
Try the full simulator with your class
103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. One licence covers a whole school.