Introduction: Arduino Piano With Sharp

These are the materials required to create this Arduino piano

Supplies

13 pushbutton

14 resistors

1 piezo buzzer

1 Arduino Uno

Step 1: Wiring/coding Tutorial

This video should be able to help you with the wiring and coding that you need to make this piano work!

Step 2: Code

int c = 261; // frequency fr note c

int d = 294; // frequency for note d int e = 329; // frequency for note e int f = 349; // frequency for note f int g = 392; // frequency for note g int a = 440; // frequency for note a int b = 493; // frequency for note b int C = 523; // frequency for note C (next octave) int Cs = 277; // frequency for note c sharp int Ds = 311; // frequency for note d sharp int Fs = 370; // frequency for note f sharp int Gs = 415; // frequency for note g sharp int As = 466; // frequency for note a sharp

int buzzerPin = 5; // buzzer pin is 5 int myNotes[13] = {c, d, e, f, g, a, b, C, Cs, Ds, Fs, Gs, As}; // array for the notes

void setup() { pinMode(13, INPUT); // pin 13 in a input pinMode(12, INPUT); // pin 12 is an input pinMode(11, INPUT); // pin 11 is an input pinMode(10, INPUT); // pin 10 is an input pinMode(9, INPUT); // pin 9 is an input pinMode(8, INPUT); // pin 8 is an input pinMode(7, INPUT); // pin 7 is an input pinMode(6, INPUT); // pin 6 is an input pinMode(4, INPUT); // pin 4 is an input pinMode(3, INPUT); // pin 3 is an input pinMode(2, INPUT); // pin 2 is an input pinMode(A0, INPUT); // pin A0 is an input pinMode(A1, INPUT); // pin A1 is an input pinMode(buzzerPin, OUTPUT); // pin 5 the buzzer is an output Serial.begin(9600); // starting the serial monitor }

void loop() { if (digitalRead(13)) { // if button 13 is pressed tone(buzzerPin, myNotes[0]);// then play note c } else if (digitalRead(12)) { // if button 12 is pressed tone(buzzerPin, myNotes[1]); // then play note d } else if (digitalRead(11)) { // if button 11 is pressed tone(buzzerPin, myNotes[2]); // then play note e } else if (digitalRead(10)) { // if button 10 is pressed tone(buzzerPin, myNotes[3]); // then play note f } else if (digitalRead(9)) { // if button 9 is pressed tone(buzzerPin, myNotes[4]); // then play note g } else if (digitalRead(8)) { // if button 8 is pressed tone(buzzerPin, myNotes[5]); // then play note a } else if (digitalRead(7)) { // if button 7 is pressed tone(buzzerPin, myNotes[6]); // then play note b } else if (digitalRead(6)) { // if button 6 is pressed tone(buzzerPin, myNotes[7]); // then play note C } //---------SHARPS------------------------------ else if (digitalRead(4)) { // if button 4 is pressed tone(buzzerPin, myNotes[8]); //then play c sharp } else if (digitalRead(3)) { // if button 3 is pressed tone(buzzerPin, myNotes[9]); // then play d sharp } else if (digitalRead(2)) { // if button 2 is pressed tone(buzzerPin, myNotes[10]); // then play f sharp } else if (digitalRead(A0)) { // if button A0 is pressed tone(buzzerPin, myNotes[11]); // then play g sharp } else if (digitalRead(A1)) { // if button A1 is pressed tone(buzzerPin, myNotes[12]); // then play a sharp } else { // else then noTone(buzzerPin); // no music } }