TABLE OF CONTENTS
01. AIM & OBJECTIVE
AIM:
To design and build a mini electronic piano using Arduino Uno, eight push buttons, and a buzzer that produces different musical notes when the buttons are pressed.
OBJECTIVE:
This project helps students understand how push buttons work as digital inputs, how Arduino processes button signals, and how a buzzer produces musical notes.
02. KIDS WILL LEARN
03. MATERIALS PROVIDED
04. CIRCUIT DESIGN CONCEPT
The electronic piano uses eight push buttons as musical keys. Each button is connected to a separate Arduino digital pin.
When a button is pressed, Arduino detects the signal and sends a matching musical frequency to the buzzer.
01. Button Input
A push button connects its Arduino input pin to GND when pressed, changing the input signal from HIGH to LOW.
02. Musical Output
Arduino uses the tone() function to make the buzzer play the selected musical note at its correct frequency.
05. CIRCUIT CONNECTIONS
Push Button Connections
Connect one side of each button to its assigned Arduino pin and the other side to GND.
| Push Button | Arduino Pin | Musical Note |
|---|---|---|
| Button 1 | D4 | C4 (Do) |
| Button 2 | D5 | D4 (Re) |
| Button 3 | D6 | E4 (Mi) |
| Button 4 | D7 | F4 (Fa) |
| Button 5 | D9 | G4 (Sol) |
| Button 6 | D10 | A4 (La) |
| Button 7 | D11 | B4 (Ti) |
| Button 8 | D12 | C5 (Do) |
Buzzer Connections
| Buzzer Terminal | Arduino UNO |
|---|---|
| Positive (+) | D8 |
| Negative (–) | GND |
06. PROCEDURE
STEP 1: PREPARE THE BASE
● Place the Arduino UNO and breadboard on a flat surface.
● Arrange the eight buttons in a single row like piano keys.
STEP 2: CONNECT THE PUSH BUTTONS
● Place all eight buttons on the breadboard.
● Connect the buttons to pins D4, D5, D6, D7, D9, D10, D11, and D12.
● Connect the other terminal of each button to GND.
STEP 3: CONNECT THE BUZZER
● Connect the positive buzzer terminal to Arduino D8.
● Connect the negative buzzer terminal to Arduino GND.
STEP 4: ADD THE MUSICAL NOTES
● Open Arduino IDE.
● Create a new sketch.
● Create a new tab named pitches.h.
● Add the eight musical note frequencies.
STEP 5: UPLOAD THE CODE
● Connect Arduino to your computer using a USB cable.
● Select Arduino UNO and the correct COM port.
● Upload the electronic piano program.
STEP 6: TEST THE MINI PIANO
● Press the first button and listen to the C note.
● Press the remaining buttons one by one.
● Observe how every button produces a different note.
● Release all the buttons to stop the sound.
07. WORKING PRINCIPLE
08. SAMPLE CODE
Arduino Main Code
Copy this code into the main Arduino sketch.
#include "pitches.h"
#define SPEAKER_PIN 8
void setup() {
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
if (digitalRead(4) == LOW)
tone(SPEAKER_PIN, NOTE_C4);
else if (digitalRead(5) == LOW)
tone(SPEAKER_PIN, NOTE_D4);
else if (digitalRead(6) == LOW)
tone(SPEAKER_PIN, NOTE_E4);
else if (digitalRead(7) == LOW)
tone(SPEAKER_PIN, NOTE_F4);
else if (digitalRead(9) == LOW)
tone(SPEAKER_PIN, NOTE_G4);
else if (digitalRead(10) == LOW)
tone(SPEAKER_PIN, NOTE_A4);
else if (digitalRead(11) == LOW)
tone(SPEAKER_PIN, NOTE_B4);
else if (digitalRead(12) == LOW)
tone(SPEAKER_PIN, NOTE_C5);
else
noTone(SPEAKER_PIN);
}
Musical Notes File – pitches.h
Create a new tab in Arduino IDE named pitches.h and add the following note definitions.
#ifndef PITCHES_H
#define PITCHES_H
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
#endif
CODE EXPLANATION:
➔ INPUT_PULLUP keeps the input HIGH when the button is not pressed.
➔ digitalRead() checks whether the button is pressed.
➔ tone() makes the buzzer produce the selected musical frequency.
➔ noTone() stops the buzzer when no button is pressed.
➔ The if-else chain gives priority to the first pressed button if multiple buttons are pressed.
09. CIRCUIT DIAGRAM
CIRCUIT CONNECTION SUMMARY:
➔ Eight push buttons connect to Arduino D4, D5, D6, D7, D9, D10, D11, and D12.
➔ All button ground terminals connect to Arduino GND.
➔ Buzzer positive connects to D8.
➔ Buzzer negative connects to GND.
10. FINAL RESULT
11. APPLICATIONS
12. SAMPLE OUTPUT
Example Musical Output:
| Button | Note | Frequency |
|---|---|---|
| 1 | C4 | 262 Hz |
| 2 | D4 | 294 Hz |
| 3 | E4 | 330 Hz |
| 4 | F4 | 349 Hz |
| 5 | G4 | 392 Hz |
| 6 | A4 | 440 Hz |
| 7 | B4 | 494 Hz |
| 8 | C5 | 523 Hz |
Each musical note has a different frequency. Higher frequencies produce higher-pitched sounds.
When the buttons are pressed in sequence, the buzzer plays the notes: C – D – E – F – G – A – B – C.
13. ADDITIONAL NOTES
● SAFETY:
➔ Turn OFF the power before changing connections.
➔ Do not short-circuit Arduino pins.
➔ Check the buzzer polarity before connecting it.
➔ Avoid loose jumper wire connections.
➔ Keep the buzzer volume at a comfortable level.
● GAME / ACTIVITY CHALLENGE:
➔ Press all eight buttons one by one.
➔ Identify which button produces the highest note.
➔ Try playing a simple melody.
➔ Ask a friend to guess the musical note.
➔ Try playing the notes forward and backward.
● CREATIVITY EXTENSION:
➔ Design a piano-shaped cardboard model.
➔ Add colorful piano keys.
➔ Add LEDs that glow when buttons are pressed.
➔ Create a musical keyboard game.
➔ Add more musical notes using extra inputs.
➔ Program your own simple melody.

