Thursday, 12 January 2012

The Arduino Air Drums Part 2

Doing things the way you see it, going by your own heart and soul, that is pure artistic integrity. Whatever the hair is six or sixty inches long, the eyes have make-up or not, the riffs are in 'E' or 'F' sharp, the amps are Marshall or not, all those things don't matter if you are doing it for the right reason, which to me means doing it for yourself! 

“What's the message in Metallica? There is no message,
 but if there was a message, it really should be look within yourself,
 don't listen to me,
 don't listen to James, don't listen to anybody,
look within yourself for the answers.”
Lars Ulrich
- this guy -

Although people hate Lars because he's not a great drummer and he sued Napster and can't play things right away and everything, you have to give it to the guy for being one of the most vocal drummer and speaking his mind out.
Anyway, I wanted to start the post with a cool quote and it kinda blew out. Sorry. :P 

The drums aren't complete without pedals, right? We need the bass pedal to play the bass and a hi-hat pedal to open and close the hi-hat. If you're unfamiliar with the awesome kit that is the drums, Google has THE picture. 

We followed mmidgal on his concept and used two slippers, one with a ADXL335 accelerometer and one with the photocell. 
[UPDATE: The photocell that we got wasn't very effective in changing it's resistance fast, so we decided to remove this part of the kit completely] 

So what we did was, we made a slit in our first slipper almost 3/4th the way in the front so as to insert the accelerometer. 

The accelerometer was connected to the USB connector
 the same way that we had done for the sticks. 

Now that we're done with all three of our elements, the easy part was hooking the circuit up. USB cables are awesome for the job, and pretty cheap as well! 

Now we move on to 

The Program 

For the impatient, you can find the code Here.

But I'd like to take a while and explain what we tried to do with the code and the problems that we ran into:

Firstly, a useful function to see how the Arduino is 'reporting' back changes given by the accelerometer is the analogRead(pinNum)
along with the Serial.println(var) function, both of these when used in one program displays the reading received by the Arduino program as illustrated here. The results are then printed on the Arduino's serial monitor. 

Using the above program we noticed that the value printed changes when the accelerometers are moved in their respective directions. So we figured our basic logic would be

if(valueReadBySensor > someThreshold) then return (a MIDI message)

and that's just repeated for all the other accelerometers.

One more important thing is that we could never get our MIDI to USB converter to work with our program, after days of searching, we chanced upon a brilliant little piece of software, that reads MIDI messages directly from the USB port without the use of any DIN connectors or anything!!

It's brilliant and so simple to use!! Just select the output port as Microsoft GS Wavesynth and you're good to go! We experimented with other softwares and virtual MIDI ports such as LoopBe and MIDIyoke but we could never get a sound out of Reaper or Audacity. 

Alright, so now you have your simple piece of code to play a note when the accelerometer moves an appropriate amount.

void loop()
  int threshold = 375;
  int reading = analogRead(A0);
  if(reading > threshold)
  noteOn(9, 35, 120);

[You will find the definitions for noteOn and everything in the code.]

This is great now, but what was happening was since there were a bunch of readings above the threshold that appeared as the drumstick was flicked, the S2MIDI software gave us a 'trrrrrrrrrrrrrk' sound. 

So, we thought delay() was a great function, which paused the function for a certain number of milliseconds. But this still was not good enough because we could never reach a compromise between a really low delay value and the 'trrrrrrk' sound.

After days and days of experimenting, we finally decided that the code mmidgal posted on his video was the best, although we made some modifications to make it better.

Dave Lombardo style. Well, almost. :P 

We used arrays along with the function millis() which really increased the response of the drum kit and allowed us to play Slayer songs. Almost.

A few things that we wanted to add were: 
  • A button on one of the sticks that when pressed, would play a pre-recorded drum roll.
  • A crash cymbal sound when the hi-hat stick is swung a bit harder [the code was also written, but it was still a bit fickle and we could never get it right, so that one line is commented out].
  • A more responsive bass pedal.
  • A ride sound when the stick is swung in the X direction. This we could never get right because it was happening even when the stick was swung in the Z direction.  

And that's it, so try it out and if you have any questions about the code, about the concept, criticisms on the blog or any feedback, really, please leave a post or send us an e-mail at

Sorry I couldn't post a demonstration video.. None of us are drummers, all of us are guitarists, actually, we'll make one as soon as we get our hands on a kickass drummer. :D
Thanks for reading and happy drumming!!!

- Bhargav

PS: If you have an interesting project or idea, or recommendations for our next project, do share it with us, we would love to hear it!


  1. I am working on a similar project, but found the delay between the actual hit and the sound rather annoying. I made a simple data collection of a drum hit using PLX-DAQ and from there I could see how the values from the accelerometer changes. Using this I can predict a hit, because you will always lift the stick before the actual hit.

    Code snip:

    if(accOld2 < 400 && sensorValue2 >400)
    {noteOn(9, 38, 120);}

    Where accOld is the value from the last iteration and sensorValue2 is the current value. This functions as a rising edge detector (The values crosses 400 from below) and this also means that you will not get the TRRRK sound that you describe, because it is only triggered once. So 2 problems solved (delay and multiple triggering).
    Thanks for the inspiration.

    1. Thank you so much for the feedback, and that's a pretty ingenious way of going about it. This project was disassembled ages ago but we might just dig it up to give this a try. Thanks again !

    2. I just saw this a few weeks ago and I'm trying to do something very similar. Sune, where did you put this snip of code in your arduino code?

  2. what music software did you use with s2midi? I cant seem to find anything that can pull s2midi as an input. =(

  3. teria como disponibilizar o codigo para download?

  4. The code here( not working, it write Error: No paste found.

    Please repait it

    1. Hey sorry about that, the link is repaired, you can find the code now at

  5. Hi, can you upload again the code please?
    Awesome work

  6. Help me!!
    What music software did you use with s2midi???!?!? :(
    and can you upload again the code plzzzzz!

  7. Hola, soy de El Salvador. Siento que mi inglés no sea el mejor, pero quiero contactarlo, porque con mis amigos universitarios queremos construir este proyecto y no entendemos cómo construirlo. Estamos estudiando ingeniería en electrónica y comunicaciones pero bajo nivel y nuestra programación no es buena y el ingeniero que nos enseña esta catedra nos ha pedido que lo conectemos con una aplicacion android en vez de una computadora. muchas gracias

  8. Please share your contact number.

  9. This comment has been removed by the author.