Making a Piano using Arduino is a very interesting and easy project to make. It is not going to be a conventional profession Piano but is very close to the one that you might love to play. Here, we will be making a piano that can be used for playing the basic song tones. For this project you don’t need to be a professional musician but a Maker is enough for making this.

Components Required :

  • Arduino Uno
  • Keypad
  • Speaker(small toy speaker) 1W /Piezo Buzzer
  • Few Jumper cables

Connection:

Arduino’s Pin
Keypad (From Left to Right)
2
Pin1
3
Pin2
4
Pin3
5
Pin4
6
Pin5
7
Pin6
8
Pin7
9
Pin8
Speaker / Buzzer’s
11
One terminal
Gnd
Other terminal

 

Code Section:

 

Note that: you need to connect the speaker or Buzzer to only PWM pin. Here, we have connected it to Pin 11, which is a PWM pin.

#define c3 9
#define c2 8
#define c1 7
#define c0 6
#define r3 5
#define r2 4
#define r1 3
#define r0 2

void setup() {
  Serial.begin(9600);
 pinMode(c0,INPUT_PULLUP); 
 pinMode(c1,INPUT_PULLUP);
 pinMode(c2,INPUT_PULLUP);
 pinMode(c3,INPUT_PULLUP);
 pinMode(r0,OUTPUT);
 pinMode(r1,OUTPUT);
 pinMode(r2,OUTPUT);
 pinMode(r3,OUTPUT);
 pinMode(11,OUTPUT);
}

void loop()
{digitalWrite(r0,LOW);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=119;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=106;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=94;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=89;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}

digitalWrite(r0,HIGH);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=79;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=71;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=63;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=59;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=25;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=20;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if (digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=10;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}

digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
if(digitalRead(c0)==LOW){

TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
}

 

 

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here