arduino xylophone

13
http://www.instructables.com/id/Arduino-Xylophone/ Food Living Outside Play Technology Workshop Arduino Xylophone by audreyobscura on June 6, 2012 Table of Contents Arduino Xylophone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: Arduino Xylophone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: You will need... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: Free the Piezos, then solder longer leads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 3: The Bars and Housing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Step 4: Attach the Piezos to the Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Step 5: Attach the Bars to the top Panel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Step 6: Build the circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Step 7: Connecting to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Step 8: Power and communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Step 9: Serial to Midi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Step 10: Jam it! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Upload: octavio-dominguez

Post on 31-Dec-2015

71 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Food      Living       Outside        Play        Technology       Workshop

Arduino Xylophoneby audreyobscura on June 6, 2012

Table of Contents

Arduino Xylophone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro:   Arduino Xylophone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1:   You will need... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

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

Step 3:   The Bars and Housing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 4:   Attach the Piezos to the Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 5:   Attach the Bars to the top Panel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 6:   Build the circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 7:   Connecting to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Step 8:   Power and communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Step 9:   Serial to Midi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Step 10:   Jam it! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Page 2: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Author:audreyobscura    audreyObscura.comi work at instructables! i make things with technology, eat pho, and play electric ukulele.

Intro:  Arduino Xylophone

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 axylophone, a drumkit, and any other MIDI controlled sound instrument, with one tool. The following steps will outline what I used to make this xylophone.

Step 1: You will need...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" plywood1/8" acrylic sheetingwood glue1/4" vinyl tubing1 1/2" long machine screws.2" masking tape

Tools:laser cutterscissorscotton swabssmall flat head screw driver

Page 3: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 2: Free the Piezos, then solder longer leads.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 ahousing, 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 aprecision 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 12piezos.

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 longerleads on to each piezo, I wrapped my solder points with heat shrink or electrical tape.

Page 4: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 3: The Bars and Housing.I used CorelDraw to draft vector files that would guide the laser cutter for the housing and bars of the xylophone.

The acrylic bars were each 10x2 inches. Each bar has two holes in them that will guide a machine screw through the bar, and mount to the top panel of the woodenhousing.

The wooden housing I designed is 10.5x30x3 inches. It forms a shallow box that supports the electronics embedded within it. I used woodglue and a cotton swab tosecure all of the corners, and allowed 24 hours to cure before I sanded down all of the edges.

The CorelDraw file for the base housing is attached to this step.

Page 5: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Page 6: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

File Downloads

xylophone.cdr (16 KB)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'xylophone.cdr']

Step 4: Attach the Piezos to the BarsI threaded the Piezo wires through the middle holes in the top panel of the housing. Then, I centered the piezo element on each acrylic bar, and used 2 inch blue maskingtape to adhere the piezo to the bar.

Page 7: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 5: Attach the Bars to the top Panel.I used 1 1/2" machine screws and nuts to secure the bars to the wooden paneling.

To prevent excessive shake or vibration on each bar, I decided to use vinyl tubing as a shock absorber on each machine screw. With 12 bars, I used 24 machine screwsand nuts, and 24 3/4" lengths of vinyl tubing. Thread the machine screw through the bar, then the vinyl, and slip it into the paneling. When the screw was through thepanel, I was able to twist on the nut to fully secure it to the panel.

All of these should only be finger-tight, to avoid stress on the paneling, or on the bar.

Page 8: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 6: Build the circuit.Before connecting the piezos to the Arduino, I connected a 1-megohm resistor in parallel to the Piezo element to limit the voltage and current produced by the piezo, andto protect the analog input ports on the Arduino. On the PCB, I marked with a permanent marker which piezo goes to each analog input port on the Arduino. I also madethe same markings on the back of the top wooden panel.

After I soldered the resistors into place, I ran a small jumper wire from one end of the resistor, to the longest rail on the PCB, and designated it my ground rail. Next, Isoldered all of the piezos' ground wires into place, in line wtih the same end of each grounded resistor. The positive lead from the piezos is soldered in to the same rail asthe other end of each resistor.

I cut 12 lengths of green wire to be my "signal wire" to the Arduino. Each signal wire is soldered into the same positive resisted rail of the piezo.

The fritzing diagram file is attached to this step.

Page 9: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Page 10: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 7: Connecting to the ArduinoI took all of the signal wires, and the ground wire running from the PCB and marked each one with blue masking tape, writing which port each wire was designated to. Ithen fed all of the marked single core wire into the corresponding ports of the Arduino.

All remaining Analog ports must be grounded! Otherwise it will affect your serial output from the arduino. I used 4 black wires, running from the ground rail of the PCBdirectly to the open analog ports of the Mega board. (A12, A13, A14, and A15)

When you have completed your circuit, you can load the xylophone program, or sketch, onto the Arduino board from the Arduino Developing Environment .

Here is the sketch I used.

//Xylophone//Adapted for an ArduinoMega//from Jenna deBoisblanc and Spiekenzie Labs initial code

//*******************************************************************************************************************// User settable variables//*******************************************************************************************************************

int pinRead;char pinAssignments[6] ={ 'A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11'};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] ={ 400,400,200,800,400,400,400,400,400,400,400,400,400,400,400,400}; // Minimum Analog value to cause a drum hitint 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 playingint PinPlayTime[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Counter since pad started to playbyte status1;

int pin = 0; int hitavg = 0;//*******************************************************************************************************************// Setup//*******************************************************************************************************************void setup(){ Serial.begin(57600); // connect to the serial port 115200

}//*******************************************************************************************************************// Main Program//*******************************************************************************************************************void loop(){ for(int pin=0; pin < 16; pin++) // {

Page 11: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

//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);

}

Page 12: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 8: Power and communication.The Arduino can be powered via USB, which doubles as a communication port. I ran a USB cable through the housing of the xylophone. By drilling a small hole, that wasbig enough for the ends of the cable, I could hide most of the USB cord in the housing.

I drilled a second hole to hold my mallots.

Page 13: Arduino Xylophone

http://www.instructables.com/id/Arduino-Xylophone/

Step 9: Serial to MidiTo get the xylophone coupled with my comptuer I used software called Hairless . It converts the serial out signal from the Arduino into a MIDI signal that programs likeGarageBand, Logic, and Ableton can read and record. Be sure that the bridge is running before you try and import MIDI data from the xylophone.

Note: Disable the bridge while trying to update the sketch on the Arduino board. You cannot have the bridge running while trying to communicate to the board from theArduino software.

Step 10: Jam it!After you are up and running, you can play the xylophone like drums. Record your beat track. Then kick change the MIDI instrument to a bass synth, and record a rhythmtrack. Finally turn it back into a xylophone and create a melody track for the best song ever. This thing is a lot of fun!

Related Instructables

Musical MIDIShoes bythobson

Arduino/AbletonColor Organ;MIDI controlled(video) by _Aias

ControllingCubase withArduino basedMIDI by pstretz

Acoustic GuitarDiy PiezoPickups byrbneville

Arduino playing"Puff the MagicDragon" on apiezo (video) byearthshine

SNF DrummingMIDI Gloveusing Arduinoand lightsensors(Photos) byBruno Ratnieks