Arduino Keyboard Piano

(CLICK TITLE FOR MORE)

Another project again. This time it'll be about music. For each button I press, it will play a note on the piezo speaker. I've used:

Arduino Uno
Piezo Speaker

1K Ohm Resistor

Jumper Wires
to make it work! Below here is the sketch of the project:





int serial_in;

void setup()
{
  pinMode(8,OUTPUT);                          // pin 8 connected to the piezo speaker
  Serial.begin(9600);       
}

void loop()
{
  if(Serial.available()){                             // see if there is anything incoming 
    serial_in=Serial.read();          
    Serial.println(serial_in,BYTE);          // print in the incoming bytes
  }
  switch(serial_in){
    case '1':
    tone(8,523);        // DO
    break;
    case '2': 
    tone(8,587);       // RE
    break;
    case '3':
    tone(8,622);       // MI
    break;
    case '4':
    tone(8,698);      // FA
    break;
    case '5':
    tone(8,783);      // SO
    break;
    case '7':
    tone(8,830);      // LA
    break;
    case '8':
    tone(8,932);      // TI
    break;
    case '9':
    tone(8,1046);    // DO
    break;
    case '0':
    noTone(8);       // no note played
    break;
  }
  
}


And here's how it works! Enjoy!




by Weng Fei

4 Responses so far.

  1. Interesting and. It important information is really beneficial for us. Thanks

  2. Wow, nice post,there are many person searching about that now they will find enough resources by your post

Leave a Reply

Popular Posts