Musical Instrument

For this week’s assignment, we wanted to design a mini piano using switch buttons.  Our goal was to make each button have a different note so that when users play the piano they can recreate the sound from the “Happy Birthday” song.  The potentiometer in the circuit regulates the volume of the notes.
To build the circuit we added switch buttons and resistors and connected the wires to the pins. We downloaded pitches from examples→toneKeyboard, each switch button had its own musical note (C5, B4, A4, G4, D5).
int analogValue = analogRead(POTENTIOMETER_PIN);
  if(analogValue > 500){
   while(digitalRead(BUTTON_C) == ACTIVATED)
    digitalWrite(PIEZO, HIGH);
We struggled a bit with adding potentiometer and piezo buzzer to our circuit with piano buttons, however we managed to solve the problems and understand the process.
At the beginning we initialized the piano buttons, buzzer and potentiometer. Next, we went on to add the code for the buzzer and potentiometer. We wrote code to read the input on the analog pin and turn the piezo buzzer on and off. Also, we set a tone for each button and activated it.
Full Code:

Final result:


Leave a Reply