Arduino MIDI Relay Servo Drumkit

I wanted some alternative sounds to use with the Arduino MIDI Relay Drumkit so dug around in my bits box for some cheap servo motors.  These are very easy to control from an Arduino and make a sound that I decided would make a pretty good cymbal style sound to contrast with the relays as the drums.

Warning! I strongly recommend using an old or second hand keyboard for your MIDI experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Arduino Uno
  • 4x Relay modules
  • 3x Mini servos
  • Midi receive module (see Arduino MIDI Interfaces)
  • Breadboard and jumper wires

The Circuit

The servos, like the relays, have three wires – 5V, GND and a signal wire.  To make things easier this time I used a “clone” Arduino Uno board that has several strips of additional pins all arranged in 5V-GND-Signal triplets (the black-red-yellow pins labelled GVS in the photo).

2020-06-16 17.10.31

One of the great things about the whole Arduino eco-system is the open source nature of the designs.  This means people are building new variants of the official boards all the time.

Using one of these meant it was trivial to wire up the relays and servos, but you could do the same thing with a shield or a breadboard if you wish.

The Code

The code is starting to get more complex now.  I’ve had to duplicate all the lists and variables to cope with the “drums” to allow for “cymbals” too.  I used all the same principles from the drumkit sketch though.

In order to use the servos, there is an Arduino library that makes it trivial.  Each servo needs to be initialised and then a value is written out to the servo and the library will do the necessary magic to make it turn to that angle.  These cheap servos will turn a full 180 degrees and back.  One slight complication, is that I wanted the servos to sweep between two values – there and back – to get the sound, so I duplicated the drumstates[] logic but with specific values I can use as the sweep angles.  In the future, I might be able to use different SERVO_HIGH values to give me longer sweeps and hence different cymbal sounds, but for now they are all the same.

There are some programming tricks I could use to handle a number of servos in a neat way, but for now, I’ve “hard-coded” in Servo1, Servo2, Servo3 and use them in the appropriate places when I receive the right MIDI notes.  Its not particularly elegant, but the code is already getting a bit complicated so that will do for now.  It means the project will only support up to three cymbals without adding extra code.  But the number of drums is still fairly easy to change though by just adding extra pins, states and MIDI drum notes in the right places.

Find it on GitHub here.

Closing Thoughts

Relays and servos still have a relative limited set of sounding options, so it is worth experimenting with different resonant surfaces to see what kinds of sounds can be made.

Kevin

Leave a comment