Instructables
Picture of Arduino Xylophone
_MG_4704_edit.jpg


I made a xylophone that uses an Arduino Mega to detect when a note is struck, and generate MIDI output. This project is wondeful because I essentially made a xylophone, a drumkit, and any other MIDI controlled sound instrument, with one tool. The following steps  will outline what I used to make this xylophone.
 
Remove these adsRemove these ads by Signing Up

Step 1: You will need...

Picture of You will need...
120607_0273.JPG
_MG_4675_edit.jpg
_MG_4679_edit.jpg
120607_0284.JPG
_MG_4684_edit.jpg
To construct the xylophone I used the following parts from Radioshack:

(x1) Arduino Mega 2560 (Radioshack #276-127)
(x12) Piezo Element (Radioshack #273-073)
(x12) 1M Ohm resistors (Radioshack #271-1356)
(x1) Single Core wire (Radioshack #278-1221)
(x1) Printed Circuit Board (Radioshack #276-170)
(x1) USB 2.0 Cord (Radioshack #26-714)
(misc) Electrical Tape (Radioshack #64-2373)
(misc) Heat shrink (Radioshack #55048444)

The housing for the xylophone was easy to build. I used:
1/4" plywood
1/8" acrylic sheeting
wood glue
1/4" vinyl tubing
1 1/2" long machine screws.
2" masking tape

Tools:
laser cutter
scissors
cotton swabs
small flat head screw driver

Step 2: Free the Piezos, then solder longer leads.

Picture of Free the Piezos, then solder longer leads.
120607_0279_edit.jpg
120607_0281_edit.jpg
120620_0450.jpg
For this project, I used piezo elements to detect when each note is struck on the xylophone. These piezos detect vibration, or a knock. Often the elements come in a housing, to protect the disc from being bent or smashed - but for this project I needed to remove them from their plastic.

By gently pressing around the edges with my fingers, you could hear the glue crack apart from the plastic, I loosened the bottom of the casing. Carefully, I insterted a precision flat-head screw driver, and popped the bottom of the case off.

The piezo element could then be removed from the outside of the housing.

Because I am using an Arduino Mega Board, I could have up to 16 Analog inputs, or 16 Piezos. I decided to just include an octave & a half, 12 notes, so I used 12 piezos.

After they were free from their case, I soldered longer wires to each piezo element, to prepare them to be inserted into the xylophone. When I was done soldering longer leads on to each piezo, I wrapped my solder points with heat shrink or electrical tape.
johnb2826 days ago

Hi guys. I made some progress on this . But I can't seem to figure out why my piezos and spitting out all kinds of wacky data. here is some the debug MIDI messages from the Hairless MIDI bridge application.

This is all from successive stries of the same xylophone key. I would thin it should always be putting out the same note number just with differing velocities. I seem to be getting all kinda of notes and ask pitch bending information, which makes for wacky sounds in my audio program (Logic). Any ideas? I have it hooked up like instructed..

john

Screen Shot 2014-03-29 at 9.35.43 AM.png

I was having a similar problem to yours and this is what I did to get it working.

Hey Guys! I just finished this project. Few things to consider for those of you having problems.

First: you need to make sure that your pins are initialized as "int" NOT "char" otherwise you might only have a few of your keys work.

Second: make sure the baud number/ serial port number is set to 115200 both in the code and in your serial to MIDI converter. I used Hairless so it should be under File-> Preferences

Third: (only applies to Ableton and Windows users users) Make sure that you use loopMIDI to create a virtual MIDI port and that serial to MIDI converter (Hairless) is set so that the MIDI Out is loopMIDI Port and MIDI In is set to loopMIDIPort. From there go into Ableton and set the Control Surface to "None" and Input as loopMIDI Port and Output as loopMIDI Port. .

Hope this helps!!

This is a super fun project

audreyobscura (author)  johnb2823 days ago

Huh....thats a new one. I wonder if boosting the resistors would curb that. or don't qualify 4 of the Analog ins in the beginning of the sketch - so try it with A0-A11 for your inputs?

cchisholm1 made it!4 days ago

Hey Guys! I just finished this project. Few things to consider for those of you having problems.

First: you need to make sure that your pins are initialized as "int" NOT "char" otherwise you might only have a few of your keys work.

Second: make sure the baud number/ serial port number is set to 115200 both in the code and in your serial to MIDI converter. I used Hairless so it should be under File-> Preferences

Third: (only applies to Ableton and Windows users users) Make sure that you use loopMIDI to create a virtual MIDI port and that serial to MIDI converter (Hairless) is set so that the MIDI Out is loopMIDI Port and MIDI In is set to loopMIDIPort. From there go into Ableton and set the Control Surface to "None" and Input as loopMIDI Port and Output as loopMIDI Port. .

Hope this helps!!

This is a super fun project

Xylphone.jpg
johnb2826 days ago

One more thing.. I think there was a small typo in the code...I could only get it to work when I used this instead of the line that was in there: char pinAssignments[16] ={

audreyobscura (author)  johnb2825 days ago
Awesome! There very well could be - do you mind emailing me your finished .ino file? audrey@instructables.com

I recently tried to revive this project in a different form and ran into some strange behavior. I thought it was because I was trying to use an arduino micro......

Thanks!
Audrey

Hi Audrey.

this code below seems to work. the only issue Im having now is that when I strike , it seems to trigger multiple notes. not sure if its because of excessive vibration or the code... The attached picture is what I get from hitting it twice, so instead of hearing clear tones, Im hearing a combination of xylophone tones in Logic. Did you ever have that problem?

Getting close!

int pinRead;

char pinAssignments[16] ={

'A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11','A12','A13','A14','A15'};

byte PadNote[16] = {

57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72}; // MIDI notes from 0 to 127 (Mid C = 60)

int PadCutOff[16] =

{

100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}; // Minimum Analog value to cause a drum hit

int MaxPlayTime[16] = {

90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90}; // Cycles before a 2nd hit is allowed

#define midichannel 1; // MIDI channel from 0 to 15 (+1 in "real world")

boolean VelocityFlag = true; // Velocity ON (true) or OFF (false)

//*******************************************************************************************************************

// Internal Use Variables

//*******************************************************************************************************************

boolean activePad[16] = {

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Array of flags of pad currently playing

int PinPlayTime[16] = {

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Counter since pad started to play

byte status1;

int pin = 0;

int hitavg = 0;

//*******************************************************************************************************************

// Setup

//*******************************************************************************************************************

void setup()

{

Serial.begin(115200);

}

//*******************************************************************************************************************

// Main Program

//*******************************************************************************************************************

void loop()

{

for(int pin=0; pin < 16; pin++) //

{

//int pin = 3;

// for (pinRead=0; pinRead < 16, pin++){

hitavg = analogRead(pinAssignments[pin]);

//Serial.println(hitavg);

// read the input pin

if((hitavg > PadCutOff[pin]))

{

if((activePad[pin] == false))

{

if(VelocityFlag == true)

{

// hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin])); // With full range (Too sensitive ?)

hitavg = (hitavg / 8) -1 ; // Upper range

}

else

{

hitavg = 127;

}

MIDI_TX(144,PadNote[pin],hitavg); //note on

PinPlayTime[pin] = 0;

activePad[pin] = true;

}

else

{

PinPlayTime[pin] = PinPlayTime[pin] + 1;

}

}

else if((activePad[pin] == true))

{

PinPlayTime[pin] = PinPlayTime[pin] + 1;

if(PinPlayTime[pin] > MaxPlayTime[pin])

{

activePad[pin] = false;

MIDI_TX(144,PadNote[pin],0);

}

}

}

}

//*******************************************************************************************************************

// Transmit MIDI Message

//*******************************************************************************************************************

void MIDI_TX(byte MESSAGE, byte PITCH, byte VELOCITY)

{

status1 = MESSAGE + midichannel;

Serial.write(status1);

Serial.write(PITCH);

Serial.write(VELOCITY);

}

Screen Shot 2014-03-29 at 3.54.22 PM.png20140329_155702.jpg
johnb2826 days ago

Hi. Great project. One thing Id point out that I overlooked is the oversized tabs on the case. I know you made yours with wood and it indicates your sanded them down. I may have missed that important point. I went and had some plexiglass laser cut with the .cdr file you attached not realizing that. So, everything fits together but obviously the tabs extend longer than they need to. And this material doesnt sand as easily as wood. Just something to consider.

phisitja1 month ago

thank you for your information and detail project.

lpeavey8 months ago
Must you use the exact piezo elements from Radioshack? Will any piezo elements work?

You don't need to use the Piezo elements from Radioshack (I hope). Here are the ones from Sparkfun:

https://www.sparkfun.com/products/10293

Hope this helped!

Kosmo28 months ago
We cant buy radio Shack parts in Canada, can you recommend an equivelant Piezo Element that we could maybe pick up elsewhere ?

Thanks

Mick
brassclams1 year ago
Is it possible to use an Arduino Uno? Sorry, I haven't read through your tutorial yet; maybe you explain there why the Mega is necessary.

Robert
This uses 16 output pins, UNO has 14 so you could make a xylophone with 14 notes instead of 16.
Not exactly true, this uses a lot of _analog input_ pins and the Uno only got 6 of those. The compiled code does consume less then 5 KB though, with some creative programming and analog multiplexers like the 4051 or 4067 an Uno or even oldest 8KB-arduino would be up to the task.
dBange11 months ago
Nice!!! I'll try to do this :D
agomes61 year ago
I just cited this here: http://www.instructables.com/id/Simon-Game-Xylophone-Version/

Hope someone merges them :)
mmorlan621 year ago
I love a project with a tool list that starts with "laser cutter." I'll just pick that up at the local Home Depot. :-)

Thanks for sharing the project.
LoveDrums1 year ago
That's tremendous!
dworki1 year ago
if(VelocityFlag == true) ... :-D ... I still remember a teacher LOLing at me looking at similar code I wrote ... what about if (velocityFlag) ... or if (velocityEnabled) ... makes the code cleaner.

But otherwise i like this instructable. Nice idea.
zvizvi1 year ago
Very neat! great i'ble, clear and super fun
In case you don't want to source a Mega just for those extra analog ins, I'd consider using a 4051 multiplexer (http://www.arduino.cc/playground/learning/4051)
neoroman1 year ago
Wow great...! I want to make it for my daughter.
Groovy idea, nice clean job too! I'll bet that your father is proud of you!
Huzzah! Beautiful. Thanks for this!
janw1 year ago
Awesome project!

As a trained musical instrument builder, I can only look at it and love it instantly. It would be even nicer if it had the typical shape of a Xylophone where the higher notes have smaller bars than the lower ones.

Maybe you should call it an Acrylophone as xylophone comes from the Greek ´xylos´ what means wood.

elhobe1 year ago
it's a fantastic project! play notes via midi with a manual input is cool and fun!

Thank's for sharing :)
agomes61 year ago
I like this so much that I will give it a try in a smaller scale 3D printed version with dig inputs for standard arduino usage....will keep you posted!!!

Congrats though, keep them coming :)
mamalove1 year ago
BEYOND SUPER!
That is awesome! I didn't know you were done. It looks great :D
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!