How to add MIDI relay bypass switching?

I am building an analog guitar multi effect pedal which has 3 separate effect PCBs within a 1590DD enclosure. I would like to add MIDI control of bypass switching to the design. I know I need a microcontroller (hence posting here) and I have some Panasonic TQ2 relays, how do I go about this project?

The functionality I want is to press buttons A, B or C to trigger each of the separate PCBs. As these are preamps, I only want one effect on at a time. I also want a second press of an active effect to toggle the pedal into bypass mode.

My intention is to design an additional PCB that has MIDI input, an Arduino and the relays, but I'm not totally sure what to do or how to sequence things. Any advice or assistance would be most welcome. Thanks.

Welcome! This is not a class project is it? I responded a very similar question about a week ago. What you want to do is doable. What preliminary work have you done or are you expecting us to do the design. We have no idea of your skill level so forgive me if I am to simplistic. Start by generating a preliminary schematic, not a frizzy thing. Chose the different hardware parts you will be using including the Arduino. We know it will not be correct out of the chute but as you work with it it will evolve. There are many tutorials that cover parts of what you want to do, best to watch some of them. As you get more questions post the schematic with links to the hardware items showing technical information. Example your TQ2 returns a lot of different devices, yes voltage etc is important. Most important thing is to have fun with this. I expect you will have this finished and enjoying it by Christmas.

I am curious and ask whether you would switch the audio with something other than a relay?

So I googled and ppl like relays, ok. I did not find a particular relay that is preferred for audio, but I bet there are some opinions.

I came across this:

I have developed a coating that can be sprayed on the circuit board tracks which neutralizes air/copper ionic interaction to smooth the laminar flow in the surface of the copper.

I hope you have a bottle of that around. :wink:


Hi, thanks for the comments and advice. No, not a class project, but if I get it working I will absolutely show my students at school!

My level of skill is low but I'm a quick learner. This year I have started to build guitar effects pedals and have even begun to design my own effects PCBs. I am still working out how electronics works but I can solder OK and have some basic coding knowledge. I know very little about the Arduino, other than that it's a programmable microcontroller that operates on 5V.

I guess I was after a starting point, which you are advising is to generate a schematic for a multi-relay circuit with an Arduino. I know I will need a voltage regulator, the MIDI input, the microprocessor, and the relays.

I've seen several schematics for single relay bypass circuits using an ATTINY85, so my first question is which in/outs on the Arduino do I use to connect to the relays? Can I configure it to work on any of the numbered terminals?

That is a question I cannot directly answer. You can use all the outputs including the analog pins as they can also be set to output. I label them with names that relate to the project such as fan1, fan2 ..etc. When I wire the board I connect to what is convenient staying away from the I2C and SPI pins as I will probably use them for something else. Then in the code I assign my pins that way if something changes you only need to change one point not go through all the code. Example my test pin:
Start with: #define test_Pin 7
In setup: pinMode(test_Pin, OUTPUT);
After that I just refer to test pin, and if for some reason it becomes pin 9 I just change to #define test_Pin 9. Hopefully that helps.

And as a generalization of this idea, the more times you can do anything in just one place, the better.

Like using functions instead of repeating yourself “long hand” in the code.

Or learning to use arrays instead of multiple identically used scalar variables.

And so forth.


OK folks, here is my Work In Progress schematic. So far it only has 1 of the loop sections as I wanted to be sure the layout for that section works before duplicating it for loops 2 and 3. Would really love some feedback and correction if I've messed anything up. It's essentially the schematic for a 5 channel MIDI looper that I found on the internet, but I will only use 3 loops. I would eventually like to change this design to have latching relays to lower power consumption, and also to drive the LEDs directly from spare Arduino pins.

What is still not clear in my head yet is the audio path on this circuit. I'm thinking it comes directly into Pin 4 of the relay and out via Pin 13 to subsequent relays or the output. The Arduino I'm guessing only sends voltage to switch the relays and doesn't have audio coming in or out.

Please post a link to that!

I agree, I don't think audio is not meant to go in and out of the Arduino. Switched by relays only, relays switched by computer program.

Ironically, ppl usually get slammed for not providing a schematic; in this case, I would do better with less information, as I will be learning about MIDI and audio and looping…

Draw us a simple diagram of the audio path(s) as a more block diagram type thing, showing the switching points (relays) and just noting that the switches are inder external control. It is hard to trace the circuit when lines just go into boxes representing relays, we have to draw it again to see what is the relay coil and what are the common, normally open and normally closed contacts.

Unless the one you are cribbing from has a more (less? haha) detailed explanation of what's being done.

The LED1 looks like it is wired backwards.

You have over used "LOOP 1 IN" and the other labels to name more than one signal. I think.

What is the roll of SW2? What are MIDI2 and MIDI4?

I'll reread your explanation and it is possible all these questions are answered in the link I requested or just part of what anyone messing with MIDI would consider common knowledge; I won't be the only one looking for that myself in the meantime, abject curiosity as this is outside my experience if not above my pay grave.

I can say latching relays work very well and consume less power. It will probably mean you need 2 output lines from the Arduino to set and reset each switch point (relay).


Thanks for the response! :grinning:

First here's the link to the MIDI looper schematic:

You'll see I followed it fairly closely. I was confused about the LOOP 1 IN, as it is used in 3 places on the diagrams I was working from. But I believe that one is intending to talk about Audio In while the other is pointing to Arduino In. I've updated my own schematic to have audio coming into relay pin 4 and leaving via relay pin 13.

Here's the pinout and terminal assignment of the relays being used in the design (at this point) so you can check my thinking:
Pinout D2N

SW2 I'm not 100% sure on, but the guy said you turn it on (or off?) when programming the Arduino.

MIDI 2 and 4 are pads that connect to a 5-pin DIN female socket (or an appropriate substitute) and are the pins that transmit the binary signals needed for MIDI information. 2 is shield, 4 is voltage reference.

You're right, the LED is backwards, having just checked a few guitar pedal designs to see how it is implemented there. I won't amend it as I intend to run LEDs straight from the Arduino when I tweak this design, and will end up deleting that part of the loop circuit. I assume to run LEDs straight from the Arduino that I just need to connect the LED to an Arduino pin, then a current limiting resistor, then connect to ground?

Thanks for the questions and help!

OK, that link makes things a bit clearer.

He too seems to overuse the labels.

For each loop section

The relay switches audio.

The processor runs the relay, using either the signal from MIDI or the pushbutton associated with the section.

And an LED shows the status of the loop relay.

The pushbutton wiring in the original is a bit odd, usually one uses only a single pullup resistor with the switch wired to ground. Since all your logic is 5 volts, I don’t see why he did that.

Presumably the code watches the pushbutton and the MIDI input to inform its decisions about when and whether to switch the relay.

He speaks about latching relays that work with a pulse to toggle. I am not familiar with that kind of relay, the latching one I picked a long time ago has two coils, one to set and the other to reset, both of which could either be a steady signal, or less wasteful operate from short pulses (like 20 ms if I recall correct) produced in code. It means basically using another output pin, transistor and associated components for driving a relay coil.

Which is longhand for Imma look for that pulse driven latching relay. :expressionless:



So I finally read carfully.

Yes, run the LED as you suggest.

The SW2 is the manual control button, it will do whatever you code it to.

So it comes down to mere software. Cough!

What does the original inventor’s code do and how does that differ from what you are aiming for?

The original code should be studied, it must have everything you need - receive MIDI messages, watch pushbuttons, pulse or hold relays.

Take a few and try to make sense of it, it may be crap I’ll take my own peek L8R.


Thanks again for your assistance and feedback. I have begun to modify, simplify and personalise the schematic according to the reading I am doing. I might be going backwards to eventually go forwards, but as a teacher, I value that journey.

I used a momentary button tutorial:

And a relay driver circuit tutorial:

These have helped me hook up the hardware to the Arduino in a way that makes sense to me. Here's an image of my modified schematic:

I have used values for R4 and R7 as per the tutorials, but I'm not sure how those values were arrived at for their original use and if they need to be otherwise for my application. What do you think?

I have also renamed some of the parts to make more sense to me. Loop 1A at the Arduino goes to Loop 1A at the relay circuit, etc. IN FX1 is an audio send that will go to the first effect PCB input which is labelled IN and OUT FX1 will come back from the effect output, which is labelled OUT on that board.

As the "B" loops were part of the footswitch circuit originally, I don't appear to need them anymore, but have kept them at this stage in case the conversion to latching relays requires a reset path.

If the LED1 and SW2 sections at the Arduino are correct, then I will duplicate them for Loop 2 and 3. Same for the relay driver circuit. Let me know if you spot any issues.

Also, got a question. In my first diagram, I've got the 5V power track going into the 5V pin on the Arduino. Should it go there or to the VIN connector? Starting to think VIN.

The 5 volt pin, pin 27 is where you should feed your good 5 volts.

The switch tutorial uses a pulled down input, I think just to keep from confusing noobs.

It will work fine, but more typical is to use a pullup to 5 volts, and wire the switch between the input and ground. This inverts the sense of the switch - pushed will read LOW, and not pushed will read HIGH, but this is easily accounted for in the code.

Some might point out that with that change, you can use pinMode INPUT_PULLUP and save a resistor. I am old fashioned or stubborn and use INPUT and a real resistor, just habit. The value is unimportant and could plausibly be anything from 4K7 to 33K. 10K is fine.

Drawing the relay in its physical box is confusing; take a look at how the original inventor shows it in his second diagram - drawing the relay coil and transistor in one place and the switching action in another makes the switching action instantly clear… don’t make us redraw the relay or memorize how its pins relate to their function.

The 4K7 at the LED might be a little dim, 1K or 470 ohms will make it bright. Try a few different values and see what you like. Just don’t exceed the maximum current for the LED you select. You seem good at googling or however you do you research, so check out how to select the current limiting resistor for an LED.

The 1K base resistor in your relay circuit is also OK but could probably safely be higher, you just need it low enough to turn the transistor on fully. No large deal, but you could learn about how that choice is made if you were curious,

As the "B" loops were part of the footswitch circuit originally, I don't appear to need them anymore, but have kept them at this stage in case the conversion to latching relays requires a reset path.

That makes no sense to me yet. I may be missing something but it seems like you are mixing two separate problems together.

TBH and in case it isn’t obvious, it is the audio switching that is the part I have forgotten the most about. I haven’t taken time to refresh my memory about send and return and loops and dry and is it wet? I will, don’t bother ‘splainin that here.

I haven’t looked at the original code, have you? :wink:


OK thanks, I will leave the 5V input where it is.

I have modified the schematic to have a pullup resistor, I can see how it will read as a constant 5V HIGH until it registers a 0V LOW when the footswitch is pushed as that signal momentarily passes to ground. Just checking I have got that part correct:
Midi relay switching 4

I have re-drawn the relay path for audio using the 2D pattern for the latching relay I would like to use instead. The path is equivalent to the diagram given before, but more obvious for those who don't have the relays' C, NC and NO pins clear in their minds:

The audio normally passes through the NC pins, bypassing the effects circuits (:desert:). When each relay is activated, it passes through the NO pins and into the effects circuits' I/Os instead (:cloud_with_rain:).

4K7 is standard for guitar pedal CLRs, but that's not a law and I'm not sure how it would be impacted by 5V power supply rather than 9V. I will do some rummaging and find out.

I spoke to the original inventor on the DIYStompBoxes forum and he said:

If you use a latching relay, you will need two arduino pins, one for set and one for reset.

That's the part I've confused you with at the end. I don't understand yet how the latching relay resets and whether or not I need an additional Arduino pin and subsequent circuit to control the reset.

I haven’t looked at the original code, have you? :wink:

No, not yet. I want to get the hardware kinks ironed out before diving into the coding. I can tell where your main interest lies though! :grinning:

EDIT: I will definitely look through the code and glean from it what I can, but I intend not to use it "as-is" and will very much want to modify and customise however I can. The more I do that, the more I will learn.

So I've done a little bit more research. I think the audio path through the relay actually needs to be set up like this:
Relay switching
IN and OUT are the I/O for the effect PCB.

That diagram is from an intelligent (single) relay switching board for guitar effects pedals using an ATTINY85 microcontroller:

I am also not sure how to drive reverse polarity through the relay at pins 10 and 1 in order to reset the latching mechanism, which is how the model I want to use operates. Any suggestions?

The switch and LED wiring look good. See how more clearer things are getting in your schematic.

The 4K7 on the LED makes sense for 9 volts, it will mean a less bright LED on 5 volts. You will find out why, it's fairly simple maths or electronics.

I just googled if you don't like maths. :wink:

The relay in the circuit you led me to is a single coil latching relay; you will note, however, that it uses two output pins on the microprocessor. The trick to reversing the polarity is to write a HIGH to one pin and LOW to the other for setting the relay, then later do the opposite to make the current go the other way, resetting it.

In between times, both pins are set LOW, resulting in no current through the coil and no power required.

It looks like 30 ms will flip the relay. I couldn't find the data sheet nor any code for the circuit it is shown in.

But… I think he's hanging it out over the edge there, however briefly, by powering the relay directly from the output pins. Someone above my pay grade will have to assure me that what I think he is "getting away with' is actually just fine.

I use dual coil relays, they may have inferior characteristics for audio switching compared to that exact relay. So yes, two copies of the transistor driver and again, two output lines, run a bit differently all just code.

So with either type, you need two output pins per relay.

There may be a third kind of relay I am not familiar with.


OK I finally remembered to look at the code (zips from Github) when I was at an appropriate information appliance, otherwise known as the big rig.

And… there's a lot less going on in the code than one would think from at-a-glance.

With the exception of modifying it to work with latching relays, no matter single or dual coil, you should be able to read and understand and use it.

There are plenty of pins left for the two-pins-per requirement.

I don't usually like code I didn't write (!), this is no different and begs to be crispified and tweezed into something a bit more compact.

But I never argue with success. Literal code has its place, it may really be best for those at a certain level of incompetence, as it is plain how it works, making it perhaps easier to change.

I am happy to discover that DIY layout tool. It deserves some time and may become useful to me, file that under "you learn something every day" and doing that is one large reason I hang out here.

When you get to the software part and have made some choices about the relays and find yourself needing help you know what to do.



Nice Schematic. A few comments to save you some problems later. I see no bulk capacitors or high frequency bypass capacitors on the regulators. They need to have leads as short as possible and as close to the regulator as you can get. This will eliminate a lot of problems in the future. I also put them on the output as you did and a high frequency bypass also. Check the data sheet for suggested values. On the input if I need for example 100uF I use two that way if one fails you never know. Good luck and have fun!