π΅ Buzzer Piano Keyboard
Arduino Buzzer Piano Keyboard tutorial: build a playable breadboard piano using a piezo buzzer, push buttons, and clean Arduino piano code.
Overview
Sound is just vibration at a specific frequency. The Arduino's tone() function can drive a piezo buzzer at any frequency, making it a perfect musical instrument controller.
Technical Insight: By mapping specific frequencies in Hertzβsuch as Middle C at 262 Hz up to B at 494 Hzβthis project introduces the exact mathematical physics of acoustic sound reproduction on digital microcontrollers. Over 85% of early retro synthesizer engines rely on this exact same square-wave frequency output model.
In simple terms: When you press one of the seven buttons, the Arduino detects which digital pin is triggered, grabs the matching musical frequency from a pre-configured array, and pulses the piezo buzzer at that speed to produce the note.
What you'll learn: Utilizing the built-in tone() and noTone() functions, mapping notes to standard frequencies in Hertz, scanning button arrays efficiently, and array structure indexing.
Estimated time: 40-50 minutes. Difficulty: ββ Easy.
Components Needed
| Component | Specification | Qty | Notes |
|---|---|---|---|
| Arduino Uno R3 | 5V | 1 | |
| Piezo Buzzer | Active/Passive 5V | 1 | Passive buzzer recommended |
| Push Buttons | Momentary SPST | 7 | One per note (C-D-E-F-G-A-B) |
| Resistors | 10kOhm pull-down | 7 | One per button |
| Breadboard + Wires | Full-size | 1 |
Component Pin Mapping
Step-by-Step Tutorial
Place the Buttons
Wire Pull-Down Resistors
Connect Buttons to Arduino
Wire the Buzzer
Play!
Arduino Code
// Buzzer Piano β Volt X
const int buzzer = 9;
const int buttons[] = {2, 3, 4, 5, 6, 7, 8};
const int notes[] = {262, 294, 330, 349, 392, 440, 494}; // C D E F G A B
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(buttons[i], INPUT);
}
pinMode(buzzer, OUTPUT);
}
void loop() {
bool anyPressed = false;
for (int i = 0; i < 7; i++) {
if (digitalRead(buttons[i]) == HIGH) {
tone(buzzer, notes[i]);
anyPressed = true;
break;
}
}
if (!anyPressed) noTone(buzzer);
}Reviews & Ratings
Sign in to leave a review
Loading reviews...
