Overview
We all know Piano is a musical instrument which can be built over Arduino. I build a piano using Arduino. It is very simple and interesting thing to build. It is not piano used by professionals, but one can generate various musical tones over this Piano.
Working
Every note in music has certain frequency. So, to generate various tones using micro-controller, various frequency signals need to be generated.
Eg. ‘Sa’ note has frequency 240 Hz, ‘Re’ has frequency 270 Hz, etc.
To know more about notes and their frequency, you can refer Derivations of Frequencies of 12 notes.
Interfacing Diagram

Piano by interfacing keypad and speaker to Arduino
Play tones on Piano made using Arduino
I built a piano which can be used to play various tones. I generated different 8 frequencies on above two rows of keypad for generating 8 notes i.e. “Sa Re Ga Ma Pa Dha Ni Saa”.
Frequency for 8 Notes are given below,
Notes
Frequency in Hz
To generate signal of different frequency, I used tone () function of Arduino.
tone (pin no, frequency in Hz, duration in milliseconds)
This function generates signal of specified frequency having 50% duty cycle. The duration of the tone in milliseconds is optional parameter. The tone () function generates signal on pin 3 and 11 (PWM output pin).
E.g. tone (11, 240, 150) //240 Hz freq signal with 150 ms duration on pin 11
Here, I used in-built keypad library of Arduino which one can find in Sketch -> Include Library.
You can find complete program in the attachment.