DIY Arduino MIDI instrument
And another summer project got finished… ;-)
My sons drum corps teacher triggered me to build an Arduino Midi controller so he could practice his rhythm skills.
Inspiration
The easiest library is the Arduino Midi USB library as described here. Although I was not very happy with the code provided…
A project on Instructables showed how the piezos could be used and also some ports of the code were used.
My version
- Arduino Leonardo (MidiUSB doesn’t work on Uno)
- Stack-on board
- 6 used of 100PCS 1MΩ 1/4W 0.25W Metal Film Resistor ±1%- for $1,18
- 6 used of 10PCS 35mm Piezo Elements buzzer Sounder Sensor Trigger Drum Disc+wire copper KT for $2,26
- Aluminum of 3cm wide
- Left over pieces of wood, cables etc.
I protected the red wire on the piezos with a piece of tape and taped each one of those on an aluminum plate. After testing on a breadboard, I used a stack-on board to easily add the resistors.
This is the scheme used:
Sources
The Arduino code inspired by the examples can be found on my GitHub account.
The two separate functions but with very similar code “noteOn” and “noteOff” were rewritten to one “sendNote” function. Also “MidiUSB.flush();” was moved into this function because at some point I forgot to add it and this caused strange behavior when playing music as the notes were not “released”:
void sendNote(boolean on, byte note, byte velocity) {
// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15\. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).
byte event = on ? 0x09 : 0x08;
byte onOff = on ? 0x90 : 0x80;
byte onOffChannel = onOff | MIDI_CHANNEL;
midiEventPacket_t noteOn = {event, onOffChannel, note, velocity};
MidiUSB.sendMIDI(noteOn);
MidiUSB.flush();
}
The result
Combined with EarMaster this works “out of the box” as a controller on Apple. When hitting too hard, the neighboring piezos also detect a change, so maybe I will still need to add some kind of tempering when we want to use it further, but for EarMaster this doesn’t seem to be an issue.