Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

Fun DIY project – piano using Arduino

Fun DIY project – piano using Arduino

Here is yet another application you can put your Arduino to use. This will be an interesting DIY to make even though you are not very much into music. Though you cannot expect music out of this but still it will be a fun project worth giving a shot, trust me. This piano using Arduino was made out of switch buttons (used as keys), buzzer as sounder generate tones with different frequency.

SCHEMATIC DESIGN OF PIANO USING ARDUINO:

piano-using-arduino-design
The schematic design for this project is pretty straightforward. Five push buttons B1 to B5 were connected to pins A0 to A4 of Arduino. These are assigned as input pins for Arduino. The push buttons were connected in such a way when pressed it will give the Ground input to the pins A0 to A5. A DC buzzer was connected to pin 6 of Arduino. This will act as a sounding element to our piano using Arduino.

MUSICAL NOTES:

Though i don’t have much idea about music i managed to find the frequency of basic notes in a piano here. Here is another list of tone frequencies that was available in official Arduino website. You can use any of those frequency values in your code to produce that specific note.

TONE() SUBROUTINE:

I have used an in built subroutine tone() in my code. The syntax of this subroutine takes the form

tone ( pin number, frequency, duration )

Duration represents the length of each note and each note have their own note like half note quarter note and so. These duration should be used in this subroutine. For example if your selected note was a quarter note then the duration will be in 1000/4 = 250 ms. This value obtained was in Milli seconds. You have to apply 1000/8 and 1000/2 for eighth and half note respectively.

CODE:

#define NOTE_C4  262          //Frequency for each notes
#define NOTE_G3  196
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_A3  220
short int buzzer= 6;
int tone_freq[5]={NOTE_C4, NOTE_B3, NOTE_G3, NOTE_A3, NOTE_C4};
int duration[5]={250,250,125,250,250};    //Duration in terms of ms

void setup() {
 pinMode(6,OUTPUT);
 pinMode(A0, INPUT_PULLUP);
 pinMode(A1, INPUT_PULLUP);
 pinMode(A2, INPUT_PULLUP);
 pinMode(A3, INPUT_PULLUP);
 pinMode(A4, INPUT_PULLUP);
}

void key_tones(int a)
{  
  tone(6,tone_freq[a],duration[a]);       //Calling out the specific note for each input
}

void loop() {
  if(digitalRead(A0)==LOW)               //Detecting key press
  {
  while(digitalRead(A0)==LOW);
  key_tones(0);
  }
  else if(digitalRead(A1)==LOW)
  {
  while(digitalRead(A1)==LOW);  
  key_tones(1);
  }
  else if(digitalRead(A2)==LOW)
  {
  while(digitalRead(A2)==LOW);
  key_tones(2);
  }
  else if(digitalRead(A3)==LOW)
  {
  while(digitalRead(A3)==LOW)
  key_tones(3);
  }
  else if(digitalRead(A4)==LOW)
  {
  while(digitalRead(A4)==LOW);
  key_tones(4);
  }
}

NOTE:

  • As already mentioned you won’t get a pleasant music out of it but using speaker as sounding element will improve the output tone produced.
  • You can substitute push buttons with other switches you desire.

WORKING VIDEO:

Read more Here







Related Pins

Solar LED Light ,20000mah  Li-ion battery , 24V solar panel with MPPT charge Controller
Solar LED Light ,20000mah Li-ion battery , 24V solar panel with MPPT charge Controller
Transfer of TI’s Wi-Fi® Alliance (WFA) Certifications to SimpleLink™ Wi-Fi CC3x00
Transfer of TI’s Wi-Fi® Alliance (WFA) Certifications to SimpleLink™ Wi-Fi CC3x00
DIY USB 5V Solar Power Pack
DIY USB 5V Solar Power Pack
Tutorial: DHT22 sensor with a PICmicro
Tutorial: DHT22 sensor with a PICmicro
BQ24650 Based MPPT li-ion Battery Chage Controller With Software MPPT adjust and 3 Channel LED P ...
BQ24650 Based MPPT li-ion Battery Chage Controller With Software MPPT adjust and 3 Channel LED PWM dimming.
Play beautiful music on an Arduino thumb piano
Play beautiful music on an Arduino thumb piano
Kids can build these circuits
Kids can build these circuits
40 dB attenuator
40 dB attenuator
A multimeter heads-up display with Arduino glasses
A multimeter heads-up display with Arduino glasses
Robotic fish swims under Arduino control
Robotic fish swims under Arduino control
Arduino Xylophone
Arduino Xylophone
MPPT Solar Charger Testing
MPPT Solar Charger Testing
Design and Application Guide of Bootstrap Circuit for High-Voltage Gate-Drive IC
Design and Application Guide of Bootstrap Circuit for High-Voltage Gate-Drive IC
ESLOV is the amazing new IoT invention kit from Arduino
ESLOV is the amazing new IoT invention kit from Arduino
μPC1237 based 2 channel speaker protector
μPC1237 based 2 channel speaker protector
ESP8266 WeatherStation Color
ESP8266 WeatherStation Color
Keyless piano project using Arduino uno
Keyless piano project using Arduino uno
IoT Wardrobe
IoT Wardrobe
Automotive CAN Transceivers
Automotive CAN Transceivers
Restoring a vintage Xerox Alto day 8: it boots!
Restoring a vintage Xerox Alto day 8: it boots!

Top


Shares