Ultrasonic Air Drums
I've always been a fan of air instruments where you make music without touching anything so when DFRobot offered to send some sensors so I can make a project with them, I pitched the idea of making a set of Air Drums.
An Air Drum is a device where you can make a rhythm without actually hitting any surface and for that, I'm using ultrasonic sensors that detect when my hands get close enough to the sensor.
Supplies
The project is based on the URM09 sensors from DFRobot as well as their FireBeetle ESP32 development board that has WiFi, Bluetooth, and an onboard lithium charging circuit so the entire drum kit can be made portable.
You can check out the DFRobot store here: https://www.dfrobot.com/
Below is a list of all the DFRobot sensors and controllers used in the video:
- URM09 Ultrasonic sensor - https://www.dfrobot.com/product-1832.html
- FireBeetle ESP32 IoT Microcontroller - https://www.dfrobot.com/product-1590.html
- Gravity I/O Expansion Shield - https://www.dfrobot.com/product-1592.html
- Gravity: I2C HUB - https://www.dfrobot.com/product-2179.html
- DFPlayer Pro - A mini MP3 Player - https://www.dfrobot.com/product-2232.html
- MAX98357 I2S Amplifier Module - https://www.dfrobot.com/product-2614.html
- Stereo Enclosed Speaker - https://www.dfrobot.com/product-1506.html
- Gravity: Voice Recorder Module - https://www.dfrobot.com/product-1507.html
Solder Headers to the Microcontroller and Expansion Shield
To start working with the sensors and the expansion shield for the FirBeetle Microcontroller, we first need to solder headers to them so the two can be connected together.
This is fairly easy and all the required headers are provided with the boards.
Test Out the Communication With FireBeetle Microcontroller
To add the FireBeetle board to the Arduino IDE we can follow the instructions on the official wiki for it. As with other boards, we first need to add the board definition to Arduino IDE and after that, the board will become available in the selection dropdown.
The URL to add is:
http://download.dfrobot.top/FireBeetle/package_esp32_index.json
To verify that we can program it, I like to always start by uploading the basic blink sketch and making sure that the upload process goes as expected.
Read the Distance From a Single URM09 Sensor
The drumming will be detected by 4 ultrasonic distance sensors URM09. The sensor can read distances of up to 50cm so anytime our hand comes closer than 10, we will play a different drum sound based on what sensor was triggered.
To read the distance of the sensor, DFRobot has a dedicated library, and all the details can be found on the product wiki page.
After installing the library, I used the provided example sketch to read the sensor and successfully detected the distance of my hand from the sensor.
Read the Distance From Multiple Sensors
Now that we have one of the sensors working, we need to expand it so there can be multiple ultrasonic sensors. In my case, I will be using 4 but they can be even more.
Since all of the URM09 sensors come preset at address 0x11 for the I2C communication, we need to change this address to three of them so there are no collisions.
For that, there is a sketch provided that we need to upload to the microcontroller and we can change the addresses to 0x12, 0x13, and 0x14 for the rest of the sensors.
Once the addresses are changed, we can then use the I2C hub from DFRobot to connect all of the sensors to it and then connect the hub to the FireBeetle board.
To measure the distance from all of the sensors, I just replicated the code from the example sketch to have 4 instances and 4 printouts and everything worked as expected.
Fail: Try to Play Drum Sounds With MP3 Player
My initial idea for the project was to make it a standalone thing where all of the drum sounds will be played through an MP3 player and a speaker but since the player can only play one file at a time, I quickly realized that this will not work, at least not in the way that I had imagined that it will.
Anyway, for the player, I used the DFPlayer Pro module, again from DFRobot and I connected it to be controlled via UART from the FireBeetle board.
The player module has 128MB of onboard storage so when I connected it to my computer, I was able to copy sounds to it that were then played based on what sensor was triggered.
This all worked nicely, but as I mentioned before, I wasn't able to get the desired effect because when I tried to make more elaborate beats, the previously playing sound would be cut off once a new hit was detected and that is not how real drums work.
Having a dedicated player for each sound would have solved this but instead, I declared this step as failed and moved to use MIDI instead where the sound will be generated on a computer.
Add BLEMIDI Functionality
I'm no MIDI expert but using the provided examples from the Arduino MIDI as well as the BLE-MIDI libraries, I was quickly able to create a sketch where instead of playing a file when a hit is detected, I was sending MIDI notes to the receiver.
The receiver can be any Bluetooth-enabled device like a computer or a phone so the entire controller can be easily used for other music generation as well.
One of the items that I struggled with the most was to have my device recognized as a BLE MIDI device and for that, I had to install a special driver from Korg that I found here.
Connect to MIDI Enabled Software on PC
Any MIDI software can be used but for my example, I opted to use FL Studio. This is paid software but it has a long enough trial so that I can make the example work and properly test it.
As I said before, I'm completely new to MIDI so if you have any recommendations on other, possibly free applications that can be used, please leave a comment below.
Start Drumming
Now with everything connected, it was time to start drumming and I must say that I had a great time playing the drums with my kids.
Not that we knew how to drum but producing a sound by just waving your hand was fascinating and really enjoyable so I call this project a win.
All of the code can be found on the project repo at: https://github.com/bkolicoski/arduino-air-drums
If you liked it, then you can also check out my other Instructables and my YouTube channel for more projects and tutorials.
Thumbnail photo by Tunahan Günkan on Unsplash