Arduino Based Piano Using Push Buttons | Arduino mini projects

Hey geeks, welcome back to Techatronic. Are you searching for the procedure to make an electric piano? Well if so then you are in the right place. In this article, we are going to make a Piano Arduino-based mini-project. For making this project we are using a buzzer to obtain the output sound and an Arduino UNO development board. We can play different notes by pressing the pushbuttons. In this, there are only five pushbuttons but you can extend them according to your choice. If you are adding some more buttons, please modify the provided code so the piano can work correctly. You can check out some more projects based on Arduino and our E-book on Arduino which contains 10+ projects with well-explained codes. You have to complete the connections first and then upload the code provided below to the Arduino.

How Does Piano Arduino-based mini project work?

This project will produce a sound of fixed frequency when we press the push buttons. The frequency is predefined for all the keys in the code. We are using the tone function here to produce the sound of the desired frequency. While using this function you have to specify the pin number of the buzzer and the frequency. For turning off the buzzer we are using none function. Here are some pictures of the project given below. We developed the code in such a way that there is a unique tone for each push button. If you are not familiar with the working of a push button with Arduino then go through it first.

Piano Arduino based mini project

Piano Arduino based mini project

Components Required

  • Arduino UNO
  • Five pushbuttons
  • Breadboard
  • Jumper wires
  • Piezo buzzer
  • USB cable for uploading the code

Circuit Diagram for Piano Arduino based mini project

arduino based piano

Complete the connections with the help of the diagram which is given above. First of all place all the five push buttons on the breadboard in such a way that the adjacent two pins complete the circuit when we press the button and break the circuit when released. Then connect the GND pin of the Arduino to the negative rail of the breadboard. From the negative rail connect a wire to a pin of each pushbutton as shown. Join the digital-6 pin of the Arduino with the other pin of the first push button. Repeat this for the second, third, fourth, and fifth buttons and connect their pin with the digital-7, digital-8, digital-9, and digital-10 pins of the Arduino. Connect the positive wire of the buzzer to the digital-11 pin of the Arduino and the negative wire to the GND pin of the Arduino.

PCBWay PCB Prototyping  service

I have assembled the whole circuit on a breadboard. As you know breadboard assembly is not effective for this type of projects. So, PCBWay offers Rapid PCB Prototyping for Your Research Work. I personally, recommend PCBWay because you can get your first-try boards right in 24 hours!

PCBWay website

The prototyping stage is the most critical period of time for engineers, students, and hobbyists. PCBWay not only makes your boards quick but also makes your job right as well as cost-effective. This greatly reduces your cost and shortens the time for developing your electronic products.

PCBWay can provide 2 Layer PCBs to highly advanced HDI and flex boards. Even though the PCBs they produce differ a lot regarding functionality and areas of use. I am impressed with the quality of the boards, the delivery time, and the cost-effectiveness.

Code for the Project

NOTE: Please upload the given code to the Arduino as it is.

 //Techatronic.com  
 #define NOTE_C 262  
 #define NOTE_D 294  
 #define NOTE_E 330  
 #define NOTE_A 440  
 #define NOTE_B 493  
 #define ACTIVATED LOW   
 const int PIEZO = 11;  
 const int BUTTON_C = 10;  
 const int BUTTON_D = 9;  
 const int BUTTON_E = 6;  
 const int BUTTON_A = 5;  
 const int BUTTON_B = 4;  
 void setup()  
 {  
  pinMode(BUTTON_C, INPUT);  
  digitalWrite(BUTTON_C,HIGH);  
  pinMode(BUTTON_D, INPUT);  
  digitalWrite(BUTTON_D,HIGH);  
  pinMode(BUTTON_E, INPUT);  
  digitalWrite(BUTTON_E,HIGH);  
  pinMode(BUTTON_A, INPUT);  
  digitalWrite(BUTTON_A,HIGH);  
  pinMode(BUTTON_B, INPUT);  
  digitalWrite(BUTTON_B,HIGH);  
 }  
 void loop()  
 {  
  while(digitalRead(BUTTON_C) == ACTIVATED)  
  {  
   tone(PIEZO,NOTE_C);  
  }  
  while(digitalRead(BUTTON_D) == ACTIVATED)  
  {  
   tone(PIEZO,NOTE_D);  
  }  
  while(digitalRead(BUTTON_E) == ACTIVATED)  
  {  
   tone(PIEZO,NOTE_E);  
  }  
  while(digitalRead(BUTTON_A) == ACTIVATED)  
  {  
   tone(PIEZO,NOTE_A);  
  }  
  while(digitalRead(BUTTON_B) == ACTIVATED)  
  {  
   tone(PIEZO,NOTE_B);  
  }  
  noTone(PIEZO);  
 }  

We hope that you understand how to make an Arduino based piano mini project and now please try to make it on your own. If you are facing any errors while making this project then use the comments section below to inform us. Also, check tutorials on Arduino and Raspberry Pi written by us.

HAPPY LEARNING!