Introduction: Arduino Piano

How to make an Arduino Piano.

Step 1: What You'll Need

Here's what you'll need to make the Arduino Piano:

Arduino + USB cable

Breadboard + wires + resistors (see Arduino layout below)

Arduino Speaker

4x or 8x Arduino Buttons

A box to put the Arduino in

Step 2: Arduino Layout

Follow this layout to setup the Arduino wiring.

Step 3: Arduino Code

int button_C = 2;
int button_D = 3;
int button_E = 4;

int button_F = 5;

int button_G = 6;

int button_A = 7;

int button_B = 8;

int button_Cup = 9;

int speaker = 13;

int buttonstate_C = 0;

int buttonstate_D = 0;

int buttonstate_E = 0;

int buttonstate_F = 0;

int buttonstate_G = 0;

int buttonstate_A = 0;

int buttonstate_B = 0;

int buttonstate_Cup = 0;

//NOTES 'c' , 'd', 'e', 'f', 'g', 'a', 'b', 'C'

int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; //freq

int Cur_tone = 0;

void setup()

{

pinMode(button_C, INPUT);

pinMode(button_D, INPUT);

pinMode(button_E, INPUT);

pinMode(button_F, INPUT);

pinMode(button_G, INPUT);

pinMode(button_A, INPUT);

pinMode(button_B, INPUT);

pinMode(button_Cup, INPUT);

pinMode(speaker, OUTPUT);

}

void loop()

{

buttonstate_C = digitalRead(button_C);

buttonstate_D = digitalRead(button_D);

buttonstate_E = digitalRead(button_E);

buttonstate_F = digitalRead(button_F);

buttonstate_G = digitalRead(button_G);

buttonstate_A = digitalRead(button_A);

buttonstate_B = digitalRead(button_B);

buttonstate_Cup = digitalRead(button_Cup);

if((buttonstate_C == HIGH) || (buttonstate_E == HIGH) ||

(buttonstate_G == HIGH) || (buttonstate_D == HIGH) ||

(buttonstate_F == HIGH) || (buttonstate_A == HIGH) ||

(buttonstate_B == HIGH) || (buttonstate_Cup == HIGH) )

{

if (buttonstate_C == HIGH)

{

Cur_tone = tones[0];

}

if (buttonstate_E == HIGH)

{

Cur_tone = tones[1];

}

if (buttonstate_G == HIGH)

{

Cur_tone = tones[2];

}

if (buttonstate_D == HIGH)

{

Cur_tone = tones[3];

}

if (buttonstate_F == HIGH)

{

Cur_tone = tones[4];

}

if (buttonstate_A == HIGH)

{

Cur_tone = tones[5];

}

if (buttonstate_B == HIGH)

{

Cur_tone = tones[6];

}

if (buttonstate_Cup == HIGH)

{

Cur_tone = tones[7];

}

digitalWrite(speaker, HIGH);

delayMicroseconds(Cur_tone);

digitalWrite(speaker, LOW);

delayMicroseconds(Cur_tone);

}

else //in case no button is pressed , close the piezo

{

digitalWrite(speaker, LOW);

}

}

Step 4: Making the Box

You'll need to make a box to hold the Arduino and breadboard. It should have an opening at the top to allow access to the buttons and at one of the sides to let the USB cable through. Measurements depend on the type of box you want to make, just make sure it fits the Arduino + breadboard.

I've added the file I used to make the box. Note: this file does not contain the holes for the buttons and USB cable, be sure to add those in the right places for your design.

Or you could make your own using MakerCase.

Step 5: Done

That's it!

I also put a 3D-printed "A" on the box, which stands for my first name, the musical note and the Arduino.

Comments

author
seamster made it! (author)2016-06-29

Hey, looks good! Thank you for sharing all the details - great looking project! :)

About This Instructable

1,887views

3favorites

License:

More by AlexM377:Arduino Piano
Add instructable to: