DIY INTERMEDIATE PROJECT NO.3 (MINI ELECTRONIC PIANO)

INTERMEDIATE PROJECT

MINI ELECTRONIC PIANO

USING ARDUINO, PUSH BUTTONS & BUZZER

A fun Arduino piano using pushbuttons and a buzzer to play different musical notes and create simple tunes!

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.

Students can press different buttons to play eight musical notes and create simple melodies.

02. KIDS WILL LEARN

How an electronic piano works
How to connect push buttons to Arduino
How INPUT_PULLUP works
How Arduino detects button presses
How a buzzer produces sound
How different frequencies create musical notes
How to use the tone() function
How electronics and music work together

03. MATERIALS PROVIDED

1. Arduino UNO – 1 (Main Controller)
2. Breadboard – 1 (Circuit Connections)
3. Push Buttons – 8 (Piano Keys)
4. Buzzer – 1 (Sound Output)
5. Jumper Wires – Few (Connections)
NOTE: External pull-up resistors are not required because Arduino’s internal pull-up resistors are enabled using INPUT_PULLUP.

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 1D4C4 (Do)
Button 2D5D4 (Re)
Button 3D6E4 (Mi)
Button 4D7F4 (Fa)
Button 5D9G4 (Sol)
Button 6D10A4 (La)
Button 7D11B4 (Ti)
Button 8D12C5 (Do)
IMPORTANT: All eight buttons share the Arduino GND connection. Connect the buttons across the center gap of the breadboard and use the correct opposite-side terminals.

Buzzer Connections

Buzzer Terminal Arduino UNO
Positive (+)D8
Negative (–)GND
TIP: Use a passive buzzer or piezo sounder that can produce different frequencies with Arduino’s tone() function.

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.

TIP: Keep equal spacing between the buttons to make the piano easy to play.
ALTERNATIVE: Mount the buttons on a cardboard or plastic piano-shaped body.

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.

TIP: INPUT_PULLUP allows the circuit to work without external pull-up resistors.

STEP 3: CONNECT THE BUZZER

● Connect the positive buzzer terminal to Arduino D8.

● Connect the negative buzzer terminal to Arduino GND.

TIP: Check the positive and negative markings before connecting the buzzer.

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.

TIP: The pitches.h file helps Arduino recognize note names such as NOTE_C4, NOTE_D4, and NOTE_C5.

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.

TIP: Ensure the pitches.h tab is saved in the same sketch before compiling.

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.

CHALLENGE: Try playing a simple tune using different combinations of notes.

07. WORKING PRINCIPLE

01. Arduino activates its internal pull-up resistors.
02. Each unpressed button reads HIGH.
03. Pressing a button connects its input to GND.
04. Arduino detects the LOW signal.
05. Arduino identifies the matching musical note.
06. The tone() function sends the note frequency to the buzzer.
07. The buzzer produces the selected musical sound.
08. When all buttons are released, noTone() stops the sound.

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

Mini Electronic Piano 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

★ The mini electronic piano works using eight push buttons.
★ Each button produces a different musical note.
★ Arduino detects button presses and controls the buzzer.
★ The buzzer produces notes from C4 to C5.
★ Students can play simple tunes using the push buttons.
★ The project combines electronics, coding, and music.

11. APPLICATIONS

1. Electronic Musical Instruments
2. Music Learning Toys
3. Educational Arduino Projects
4. Sound Generation Systems
5. Interactive Music Games
6. Digital Piano Prototypes

12. SAMPLE OUTPUT

Mini Electronic Piano Sample Output

Example Musical Output:

Button Note Frequency
1C4262 Hz
2D4294 Hz
3E4330 Hz
4F4349 Hz
5G4392 Hz
6A4440 Hz
7B4494 Hz
8C5523 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.

IGNITING THE PASSION FOR ROBOTICS IN KIDS

Leave A Comment

Your email address will not be published. Required fields are marked *