Introduction: Keyboard Instrument With Arduino (from Arduino Book)

Here is a tutorial for how to create keyboard instrument with Arduino. It only takes 6 steps, which is easy for beginners to get started with Arduino.The result of the project sounds more like a percussion instrument than a strings. There are 4 notes included: C, D, E, and F.

Step 1: Supplies

Here is the supplies list for this project:

- an Arduino Uno

- a Breadboard (size does not matter, and does not have to be attached to the Arduino)

- a Piezo

- 4 Push Buttons

- 4 Resistors

- 2 10k Ohms Resistor (brown, black, orange)

- a 220 Ohms Resistor (red, red, brown)

- a 1M Ohms Resistor (brown, black, green)

- 9 Wires (length does not matter, the shorter wires that can fit, the neater the board looks)

Plus: - an adapter that can help to upload the codes from the computer/laptop to the Arduino

Step 2: Circuit

After all the supplies are prepared, we can move onto create the circuit. Here are two pictures of the circuit. One is the schematic, and the other is the actual look of the board. They are both right. It's fine to follow either way to create the circuit, although the actual look one is a bit more straight forward.

(In this project all the components do not have polarity, which means it should work in both way the legs are inserted to the board)

Step 3: Codes

Here is the codes for this project:

int buttons[0];

int notes[] = {262, 294, 330, 349};

void setup() { Serial.begin(9600); }

void loop() {

int keyVal = analogRead(A0);


if(keyVal == 1023){ tone(8, notes [0]); }

else if(keyVal >=990 && keyVal <= 1010){ tone(8,notes[1]); }

else if(keyVal >=505 && keyVal <= 515){ tone(8,notes[2]); }

else if(keyVal >=5 && keyVal <= 10){ tone(8,notes[3]); }

else { noTone(8); }


(things to notice: do not forget to put semicolon after each line; after all the codes are done verify it by click the check mark on the top left corner, after click it, it requires you to save it; after the codes are being verified, go to Tools, here are two things underneath this content that should be done: 1. Board, select "Arduino/Genuino Uno"; Port, select the only option there,***this is really important)

Step 4: Upload the Codes

To upload the codes from computer/laptop to the Arduino, the adapter is needed, it has one side that connects to the Arduino, and the other side is the USB connector.

(the adapter should always be included from Arduino kit.)

Step 5: Troubleshoot

If everything have been done from step 1~ step 4, but the it does not work, here is the list of things can be done:

- double check all the connections to see if they are tightly connected or not, include wires, buttons, resistors, and the piezo

- double check the codes if they have been uploaded or not

- if batteries are involved, when it has been connected to the Arduino, but there is no light lights up on the Arduino board, it means it is running out of battery

Step 6: Small Tip

After troubleshoot, and the mistakes have been found out, changes can be made. If the changes are about the connections or polarity(not in this project), which have nothing to do with the code, we can always press this reset button on the Arduino board. In that way, we do not have to reupload the codes after every time we make changes to the connections.