The Arduino Piano Project is a fun and interactive way to explore the basics of electronics, sound generation, and programming. In this project, you’ll build a simple electronic piano using an Arduino board, a breadboard, push buttons, and a buzzer. Each button represents a musical note, and when pressed, it plays a different sound through the buzzer—just like playing a piano!
This activity helps learners understand how digital input (button press) can be used to control output (sound) using code. It’s a perfect beginner-level project that combines creativity with STEM concepts like frequency, tone generation, and circuit building. Whether you're a student, hobbyist, or educator, this project offers a hands-on experience in making music with electronics!
Arduino Uno
Breadboard
8 Push Buttons
Jumper Wires
1 Buzzer or Speaker
USB cable (for uploading code)
Computer with Arduino IDE installed
Connect Buttons:
Place 8 push buttons on the breadboard.
Connect one leg of each button to Arduino digital pins:
Button 1 → D12, Button 2 → D11, Button 3 → D10, Button 4 → D9
Button 5 → D7, Button 6 → D6, Button 7 → D5, Button 8 → D4
Connect the other leg of all buttons to GND.
Internal pull-up resistors are enabled in the code, so no need for external resistors.
Connect the Buzzer:
Connect the positive leg of the buzzer to pin D8.
Connect the negative leg to GND.
Power the Board:
Connect the Arduino to your computer using the USB cable
Open Arduino IDE.
Make sure you have the pitches.h file in the same folder. It defines the musical note frequencies.
Copy and paste your provided code into the IDE.
Select the correct board and port from Tools > Board and Tools > Port.
Click Upload.
When you press a button, it pulls the input pin LOW.
The code detects which button is pressed and plays the corresponding musical note through the buzzer using the tone() function.
When no button is pressed, the tone stops.
Add colored caps or labels to the buttons for each note.
Place the buttons in a piano key layout.
Add LEDs to light up with each note for a visual effect.
Piano project code:
/**
Mini piano for Arduino.
You can control the colorful buttons with your keyboard:
After starting the simulation, click anywhere in the diagram to focus it.
Then press any key between 1 and 8 to play the piano (1 is the lowest note,
8 is the highest).
Copyright (C) 2021, Uri Shaked. Released under the MIT License.
*/
#include "pitches.h"
#define SPEAKER_PIN 8
const uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };
const int buttonTones[] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
const int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);
void setup() {
for (uint8_t i = 0; i < numTones; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
int pitch = 0;
for (uint8_t i = 0; i < numTones; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
pitch = buttonTones[i];
}
}
if (pitch) {
tone(SPEAKER_PIN, pitch);
} else {
noTone(SPEAKER_PIN);
}
}