Introduction: Arduino Air Drums

This instructable will tell you how to make your own set of air drums using little more than an Arduino microcontroller and a few accelerometers. 
Here's a video of the drums I based this design off of: 

http://www.youtube.com/watch?v=jjvy_jzGlAQ


My drums feature a number of improvements over those shown in the video:

-Funtional Hi Hat Pedal: Looking at the original designer's code, I noticed he never got the photocell "hi-hat" to work. Instead, he programmed the cymbal drumstick to play a crash at high acceleration and a closed hi hat at lower accelerations. 

-More responsive drumsticks and pedals

Step 1: Get Your Materials

Items you will need (can be found on sparkfun.com unless otherwise noted): 
4 - 6 foot usb a male - a male cords
8 - usb female type a smd connectors 
3 - adxl 335 accelerometers 
1 - Mini photocell 
1- 10k resistor
1- 220 ohm resistor
1- MIDI Connector - Female Right Angle
1- MIDI USB converter (find it on Amazon.com for around $5) 
Arduino Uno microcontroller 
A Breadboard
Lots of Wire  
Cheap flip flops you can cut up (got mine at target for $3) 
Replacement strap for flip flops (I used some tennis wristbands for this) 
Air drumsticks (I used some PVC pipe) 

Step 2: MIDI Connector

The first thing you'll want to do is wire up your Arduino to your MIDI female connector so you can play MIDI notes.  This is an easy process - just follow the diagram! Note that the resistor is 220 ohm. 

Step 3: Wiring Up the Accelerometers

Next, we want to hook up our accelerometers to the Arduino. Hook up the z terminals of the accelerometers to the analog inputs 0,1, and 4 of the arduino. Hook up the GND terminals to ground and the VCC terminals to the +3.3V of the Arduino. Also, hook up the Analog Reference pin to +3.3V. For reference, see the diagram below. 

Also, to avoid long, tangled wires, use usb cables as connectors. Just solder the wires from the accelerometer onto the usb females and use usb males to connect them. The picture below shows a USB female with accelerometer cables soldered to it. 

Step 4: Wire Up the Hi Hat Pedal

The hi-hat pedal works by utilizing a photocell as a voltage divider. The diagram below shows how to hook it (again, using a usb cable as a connector). Note that the resistor value is 10k, and that the middle of the voltage divider should be hooked up to Analog Pin 3, as shown. 

Step 5: Putting It All Together

Upon completing the last step, you should have all of the necessary components wired up. First, put two of the accelerometers in some sort of "stick" (I used pvc pipe). the third accelerometer in some sort of "bass pedal" (I used the right foot of some cheap flip flops), and the photocell in a "hi hat pedal" (Left foot of cheap flip flops). Look at the pics below to see how I set things up. 

Step 6: Code

Now it's time to upload the code to your Arduino. Here it is: 

//snare
const int NumSnareReadings = 7;
int SnareReadings[NumSnareReadings];
int SnareIndex = 0;
int SnareTotal = 0;
int SnareAverage = 0;
int SnareMax = 700;
int SnarePin = A2;

//hi hat
const int NumHatReadings = 7;
int HatReadings[NumHatReadings];
int HatIndex = 0;
int HatTotal = 0;
int HatAverage = 0;
int HatMax = 700;
int HatPin = A0;

//bass pedal
const int NumBassReadings = 7;
int BassReadings[NumBassReadings];
int BassIndex = 0;
int BassTotal = 0;
int BassAverage = 0;
int BassMax = 700;
int BassPin = A4;

//crash (hi hat pedal up)
int PedalPin=A3;
int Light = analogRead(A3);
const int NumCrashReadings = 7;
int CrashReadings[NumCrashReadings];
int CrashIndex = 0;
int CrashTotal = 0;
int CrashAverage = 0;
int CrashMax = 700;
int CrashPin = A5;
int Threshold = 125;

//Millis function to give a delay between MIDI notes
long PreviousMillis1= 0;
long PreviousMillis2= 0;
long PreviousMillis3= 0;
long PreviousMillis4= 0;

long Interval1 = 100;
long Interval2 = 100;
long Interval3 = 100;
long Interval4 = 100;

void setup() {
  Serial.begin(31250);
  pinMode(SnarePin, INPUT);
  pinMode(HatPin, INPUT);
  pinMode(BassPin, INPUT);
  pinMode(PedalPin, INPUT);
  analogReference(EXTERNAL);
 
  for( int ThisSnareReading = 0; ThisSnareReading < NumSnareReadings; ThisSnareReading++)
  SnareReadings[ThisSnareReading] = 0;
   for( int ThisHatReading = 0; ThisHatReading < NumHatReadings; ThisHatReading++)
  HatReadings[ThisHatReading] = 0;
  for( int ThisBassReading = 0; ThisBassReading < NumBassReadings; ThisBassReading++)
  BassReadings[ThisBassReading] = 0;

}

void loop ()
{
  unsigned long CurrentMillis = millis();
  //snare
  SnareTotal = SnareTotal - SnareReadings[SnareIndex];
  SnareReadings[SnareIndex]=analogRead(SnarePin);
  SnareTotal = SnareTotal + SnareReadings[SnareIndex];
  SnareIndex=SnareIndex+1;
  if(SnareIndex >= NumSnareReadings)
  SnareIndex=0;
  SnareAverage = SnareTotal / NumSnareReadings;
  if(SnareAverage > SnareMax && (CurrentMillis-PreviousMillis1) > Interval1)
{
   PreviousMillis1=CurrentMillis;
   playMidiNote(1, 38, 127);
}
 

//hi hat

  HatTotal = HatTotal - HatReadings[HatIndex];
  HatReadings[HatIndex]=analogRead(HatPin);
  HatTotal = HatTotal + HatReadings[HatIndex];
  HatIndex=HatIndex+1;
  if(HatIndex >= NumHatReadings)
  {HatIndex=0;
  HatAverage = HatTotal / NumHatReadings;
  if(HatAverage > HatMax && (CurrentMillis-PreviousMillis2) > Interval2 && analogRead(A3) < Threshold)
   {playMidiNote(1, 42, 127);}
  }
 
//crash

  CrashTotal = CrashTotal - CrashReadings[CrashIndex];
  CrashReadings[CrashIndex]=analogRead(CrashPin);
  CrashTotal = CrashTotal + CrashReadings[CrashIndex];
  CrashIndex=CrashIndex+1;
  if(CrashIndex >= NumCrashReadings)
  {CrashIndex=0;
  CrashAverage = CrashTotal / NumCrashReadings;
  if(CrashAverage > CrashMax && (CurrentMillis-PreviousMillis4) > Interval4 && analogRead(A3) >= Threshold)
   {playMidiNote(1, 46, 127);}
  }
//bass pedal
  BassTotal = BassTotal - BassReadings[BassIndex];
  BassReadings[BassIndex]=analogRead(BassPin);
  BassTotal = BassTotal + BassReadings[BassIndex];
  BassIndex=BassIndex+1;
  if(BassIndex >= NumBassReadings)
  BassIndex=0;
  BassAverage = BassTotal / NumBassReadings;
  if(BassAverage > BassMax && (CurrentMillis-PreviousMillis3 > Interval3))
  {
PreviousMillis3=CurrentMillis;
  playMidiNote(1,36 , 127);
}
}
void playMidiNote(byte channel, byte note, byte velocity)
{
  byte midiMessage= 0x90 + (channel - 1);
  Serial.write(midiMessage);
  Serial.write(note);
  Serial.write(velocity);
}

Step 7:

Here's a quick video of my drums in action: