Arduino TRS Jack for Expression Pedal and Dual Footswitch

by

If you are building your first MIDI Controller using an arduino you've likely already learned how to wire your buttons, leds and pots, but if you next stop is adding a TRS (tip/ring/sleeve) jack for an expression pedal or for dual footswitches then you may want to consider reading thru this.

Since releasing BMC I've received a fair amount of questions about adding jacks for expression pedals and issues that can come when doing so, for this reason I wanted to share some information on some good practices for this.

First of all, a potentiometer is a variable resistor, typically it has 3 pins as seen below

When you rotate it clockwise, resistance between pin 1 and pin 2 is increased while resistance between pin 2 and pin 3 is decreated, when you rotate it counter-clockwise resistance between pin 1 and pin 2 is decreased while resistance between pin 2 and pin 3 is increased. The typical expression pedal is just a potentiometer wired to a 1/4" TRS jack or directly to a cable with a TRS Plug, the wiring is done this way:

Pin 1 is wired to the TRS Jack's SLEEVE pin, Pin 2 to the TIP and Pin 3 to the RING.

On the other end the MIDI Controller will have the TRS Jack will be wired like this, TIP is the analog input pin on the microcontroller, RING is the reference voltage (VCC) and SLEEVE is the Ground (GND) pin.

With this in mind, when you rotate the pot clockwise, resistance between the Analog Pin and the GND is increased and resistance between the Analog Pin and VCC is reduced, this is turn will increase the voltage going into the Analog Input pin, when you rotate the other way it will reduce the voltage going to the Analog Input pin.

Adding an TRS jack for an expression pedal will just require you to wire your arduino's VCC to the RING of the TRS Jack, GND to the SLEEVE of the TRS Jack and your analog input pin to the TIP of the TRS Jack, at least this is how it works on paper, however, there are some issues with just doing this:

  1. Hot Plugging (plugging/unplugging and expression pedal to the TRS Jack while the Arduino is powered up) will cause a short and boot up your arduino, or worse, fry it! This is because the VCC and GND signal can get shorted while the plug is inserted or removed.
  2. When an expression pedal is not plugged in and the Arduino is running, the Analog Input Pin will be left floating (aka unstable) which will produce random value at the analog pin, if you do this and use the analogRead function in arduino you will get a ton of random readings, if you have code reading that analog value and creating a MIDI message that is then sent out, you will bottle neck your MIDI Bus and flood the entire signal with random readings.

The good news is that this is easily fixed, to solve #1 you can wire a 100ohm resistor between VCC and the RING pin of the TRS Jack.

To solve #2 you can use a switchable TRS Jack, there will have 6 pins, each pin (T/R/S) has a pin on the other side, these pins are connected to one other until you plug in a TRS Plug, then the pins are disconnected. In the image below you can see which pin is which and how they behave based on weather a jack is plugged in or not.

So to solve the issue you can wire the TRS Jack as explained before but connect the Ts Pin to GND, by doing this, when an expression pedal is plugged in the Analog pin on your arduino will read get a reading, when nothing is plugged in the Analog Pin will be shorted to ground and the analogRead function will always read 0, this will keep the Analog Pin from floating when nothing is plugged in.

So a good practice wiring for an expression pedal jack for your arduino MIDI Controller will look like this:

The only downside of this method is that when nothing is plugged in your analog input value will always be 0 and therefor your code will have to account for it (ie. do nothing when the value is 0 and only work when the value is above a certain threshold) but at the least this method only requires one analog pin from your arduino and one 100ohm resistor.

The "ENABLE" pin trick

There is another method you could use if you have a spare pin on your arduino available, you could skip wiring the Ts pin to GND and instead wire the spare digital pin to the Ss pin of the TRS Jack, this digital pin will have to be set as an input with the internal pullup resistor enabled, this is done by using "pinMode(YOUR_PIN_NUMBER, INPUT_PULLUP)" if the pin doesnt have an internal pullup just wire a 10k resistor between the spare pin and VCC, since the SLEEVE pin of the TRS Jack is wired to GND, when you read your spare pin and nothing is plugged in to the TRS Jack the pin will read LOW, when you plug in a TRS Jack the connection between the spare pin and GND will be broken and the pin will read HIGH.

With this method the spare digital pin will become an "ENABLE" pin, then you can make your code read the analog pin ONLY if the spare pin is HIGH, when the spare pin is LOW nothing is plugged in so the reading from the analog pin can be ignored, it won't matter if the pin is floating since the reading will be ignored. You can wire the Ts pin of the TRS Jack to GND if you want for extra piece of mind but as long as your code is ignoring the reading then you should be ok.

A good idea would be to wait a little bit after the spare pin starts reading HIGH while the plug is fully inserted and teh readings from the expression pedal stabilize, you can do this by adding a delay after the pin reads HIGH or using other timing methods to delay without blocking other code (like using the millis() function), 1 to 2 seconds would be a good time to wait.

The code to use the enable pin could look something like this:

Now to use the TRS Jack with a dual footswitch the wiring is similar, instead of using the analog pin and VCC you will have to wire a digital pin to TIP and a digital pin to RING, in your code you can set the pins to use the internal pullup or wire a pullup resistor if your board doesn't have one. The ENABLE pin trick can also be used to avoid an unintentional change of state on the digital pins when hot plugging the external footswitches.

So you have your options laidout for safe and good ways to wire your TRS Jack for either an expression pedal or a dual footswitch, for the expression pedal you only need 1 analog pin + 1 digital pin if you want the ENABLE pin trick, for the dual footswitch you will need 2 digital pins + 1 digital pin for the ENABLE trick.

The only downside is one you wire it for either an expression pedal or dual footswitch and you change your mind you will have to re-wire it, but what if you could wire it to work with either an expression pedal or a dual footswitch? well you can!

BMC (https://www.roxxxtar.com/bmc) gives you that option so that you can change how you use the TRS Jack you can use it for either expression or footswitches without re-wiring, the trick is pretty simple, you will have to wire an analog pin to TIP, a digital pin to RING, GND to SLEEVE and a digital pin to Ts as an enable pin.

This will give you the best of both worlds, the trick here is simple, when you want to use it for expression pedals you will set your Analog pin as an INPUT (not INPUT_PULLUP) and the digital pin wired to the RING of the TRS Jack will be set as OUTPUT and set HIGH, this will output VCC thru the RING the same as if you had VCC wired to the RING pin of the TRS Jack, plus you will not need a resistor since most GPIOs set as outputs will not short the board if you ground them. The ENABLE pin trick will works as explained before.

When you want to use it as for a dual footswitch you can set the analog pin and digital pin 1 both as digital inputs with the internal pullup resistor enabled. You could code your MIDI Controller to do this on the fly, maybe by adding an additional momentary switch somewhere that when it's held for a set amount of time the jack will be toggled for an expression pedal or a dual footswitch.

That's it! now you can have a TRS jack that can be code to be used with an expression pedal or a dual footswitch.

If you are using a Teensy for your MIDI Controller (which you shoudl as it's hands down the best Arduino compatible board for anything MIDI) then you can give BMC a try, BMC is an open-source MIDI Controller library for Teensy with a companion editor app, it doesn't require you to write any code and with BMC you can setup AuxJacks which is a TRS jack wired as above and BMC will handle all the code to switch between the behaviour of the TRS Jack.

I hope this is helpfull and gets you closer to the MIDI Controller of your dreams, if you have time visit my shop for MIDI Controller modules that may come handy! https://www.roxxxtar.com/bmc-shop

Nero

About Nero

I'm a Musician, Web Developer, Graphic Designer, Sound Engineer and the list goes on!
View all posts by Nero


Sign In to leave a comment

OR

Comment as a Guest