DIY Arduino Air Drums
Have you ever wanted to play the drums, but they're too loud, expensive, or take up too much space? Or maybe you just find yourself "air-drumming" to your favorite songs at your desk.
What if you could turn those air-drum motions into real music?
In this Instructable, we will build exactly that: a DIY Air Drum Kit. Using an Arduino UNO, three common ultrasonic sensors (HC-SR04), and a clever bit of code, we will create a contactless MIDI controller that can play any sound you want.
Supplies
1x Arduino UNO or similar (the one I used is ELEGOO UNO R3)
3x Ultrasound sensors HC-SR04 (1 for Kit, 1 for Hi-Hats and 1 for Snare Drum)
1x Protoboard
Wiring and Connections
The connection and wiring is pretty simple. We don't need resistors or any other component to make it work since the Vcc, offered by Arduino, is 5V and the Vcc needed for the HC-SR04 is 5V.
The HC-SR04 has 4 pins:
- Vcc
- Trigger (Ultrasound signal that is sent)
- Echo (Received signal by the microphone of the sensor that will allow us to calculate the time difference between the signal being sent and received).
- Ground
First, let's start with the power supply and ground:
- Connect the 5V pin from your Arduino to the positive rail (the red line, +) of your protoboard.
- Connect one of the GND pins from the Arduino to the negative rail (the blue line, -).
- Now, connect the Vcc pin of all three HC-SR04 sensors to the positive rail and the GND pin of all three sensors to the negative rail.
Second, we need 6 digital pins in total (2 for each sensor). The code we will use in the next step is set up for these specific connections, but you can actually use the pins you want:
- Snare Sensor:
- Trigger pin -> Digital Pin 2
- Echo pin -> Digital Pin 3
- Hi-Hat Sensor:
- Trigger pin -> Digital Pin 4
- Echo pin -> Digital Pin 5
- Kick Sensor:
- Trigger pin -> Digital Pin 6
- Echo pin -> Digital Pin 7
Solding the Connections
After making sure that all the connections are correct we decided to solder all the common nodes (Vcc and GND). This decision was made because the protoboard was big and heavy. s
Coding
Here is where the magic happens. The idea was to replicate the movement of someone playing real drums and make the sensor recognize that movement so it sounds when you simulate that movement in the air. This movement consists of three parts:
- The drumstick/hand approaches the drum (the sensor will detect a decrease in distance).
- The drumstick/hand "hits" the air (the sensor will detect the distance stops decreasing and starts increasing. It should sound at this very moment).
- The drumstick/hand moves away from the drum (the distance will start increasing).
That's the key for the code. To know exactly what to ignore and what not to, we performed that movement and measured how the distance changes during the movement. We obtained a few important restrictions from here:
- It only sounds when the hand/drumstick stops at 8 cm or less from the sensor (this is our "Impact Zone").
- We have to ignore what happens at a distance larger than 30 cm (our code's UMBRAL_MAX_CM).
- We have to ignore small changes in distance (this prevents accidental hits from hand tremors, our code's MIN_TRAVEL_CM).
There are more technical things added (like a debounce timer), but you can read everything in the code provided. Once the Arduino detects the movement and checks all the restrictions, a MIDI signal is created with a certain velocity. The value of the velocity will depend on how close you stopped the movement from the sensor. The closer you stop, the higher the velocity (louder the sound), and vice versa.
Once our Arduino was able to create a MIDI signal, we wanted this signal to travel to our DAW. So, we used Hairless MIDI to bridge our Arduino (which sends MIDI signals) to the computer. To create a virtual MIDI bus from Hairless MIDI to our DAW, we used loopMIDI. For the DAW, we used REAPER.
On REAPER, we created a sampler using a snare.wav as the D2 MIDI note (Note 38), kick.wav as the C2 MIDI note (Note 36), and Hi-Hat.wav as the F#2 MIDI note (Note 42).
Downloads
Setting Up LoopMIDI
Download it from the official website, install it, and open it. This window should appear.
To create a MIDI port, we hit the '+' button and we can name it. In our case, we named it 'Arduino'.
Setting Up Our HairLessMIDI
Download it from the official website, install it, and open it. This window should appear.
Now we have to select our Arduino as the Serial port (at 115200 baud, you can select it clicking on 'File') and the bus we created in loopMIDI as the MIDI Out.
Setting Up Sampler on Reaper (1)
After downloading and installing REAPER from the official website, we have to open it.
We have to create the sampler for our MIDI to have sound, to create it we e are going to press Ctrl + T to create a new track. Once it is created you can change the name; we named ours "Air DrumKit".
Setting Up Sampler on Reaper (2)
Next, you have to hit the 'FX' button of the created track and add the following plugin: 'ReaSamplOmatic5000'.
You are going to add it three times in the same track, since we have three audio files we want to be able to sound simultaneously.
Setting Up Sampler on Reaper (3)
Now, we have to add the sounds to our samplers. We are going to grab each .wav file and drag it into its own ReaSamplOmatic5000 window, like the following picture.
Following the code provided, Snare is related to MIDI note 38, Hi-Hat to note 42, and Kick to note 36. In this example, we are setting up the Snare, so we are going to set 'Note start' and 'Note end' to 38. We have to do the same for the other two samplers (setting Kick to note 36 and Hi-Hat to note 42).
Setting Up Sampler on Reaper (4)
To make it work, we have to arm the track (click the red record button) and choose the MIDI input. Select Input: MIDI -> [Your loopMIDI port name, e.g., 'Arduino'] -> All Channels, as shown in the next picture.
Now everything is set up. Now you can enjoy playing your Air Drumkit!!!
Building the Box
First, we have to make the container for our project. I used black foam board (5mm thick) because it is very light and easy to cut with a cutter.
I cut the bottom piece and the walls. To make the box strong, I didn't just glue the walls to the bottom. I cut small triangles of foam and glued them in the corners. This support is important so the box doesn't move or break when we are using it.
Placing the Arduino
We need to fix the Arduino inside the box, but we cannot glue it directly to the floor. The bottom of the Arduino has metal points that shouldn't touch the surface directly.
So, I made a small "bed" for it. I glued small strips of foam to the base, and then I put the Arduino on top of them. This creates a small space under the board, which is safer for the electronics.
Cutting the Holes for Cables
Before we start with the cables, we need to make sure we can plug the USB in.
I put the Arduino in its place and marked where the USB and the Power inputs are on the wall. Then, I carefully cut two small rectangles in the foam. It is better to check if the cable fits well before gluing everything permanently.
Adding the Sensors
I cut two round holes for each sensor in the front panel. Then, I pushed the sensors from the inside out. To keep them very steady, I used a lot of hot glue on the back. It is important that they point straight forward so the distance calculation in the code works well.
Last Steps
Finally, I closed the box and decorated it. Since we are playing "air drums," it helps to have a visual guide.
I used markers to paint some tribal designs around the sensors. This makes the project look cool, but it also helps me see exactly where the sensors are so I know where to aim my hands.
And that's it. You can enjoy your MIDI-Air-Drum Kit :)