This project is submitted for

Description

Two takes on the stereo relay input selector.

* One is controlled by an ESP32 or a rotary switch, with full ESP32 pin break-out for maximum flexibility
* The other is controlled by a rotary switch only, but adds LED footprints (the other board can use the ESP32 for this)

This project uses Panasonic TQ-2 relays and separates power and signal grounds to prevent any switching noise, clicks or pops in the audio channels.

This project is fully open source. Use it for any purpose and change it into whatever you like. I would appreciate some credit if you decide to fork the project, but it's not required.

PROJECT STATUS:
This project is fully built and tested. There's no programming of the ESP32 offered as of yet.

Eagle project files and gerbers are available in the files section.

Details

Features

Five stereo inputs, switched with Panasonic TQ-2 relays

One stereo output

Controlled with ESP32 or rotary switch

Space for the ESP32-DevkitC/NodeMCU, with break-out for all pins

IO pins go high when activating a relay, can be used for indicator LEDs

More about this below. But first, getting there was not all that easy:

IRremote.h and the ESP32

IRremote.h does not want to play nice with ANY library saving anything to the NVS memory. That's sort of a letdown if you'd like to use an infrared remote AND save preferences or states to the ESP32's internal storage.

Here's what happens (continuously, like every 0.2 of a second), showing only one instance of the error:

Getting the code to compile

Change the end of IRremote.h (probably in your Documents\Arduino\libraries\IRremote folder) from:

#elseconstint sendPin = SEND_PIN;
#endif
} ;

to:

#elif defined(SEND_PIN)constint sendPin = SEND_PIN;
#endif
} ;

Note that it's only the first row that's changed, the rest is there to make sure you find the right section of the code.

IR Receiver

I've used a TSOP4838 (not sure if others will work), and connected pin 1 to IO13 on the ESP32. The IR receiver's pin 2 connects to GND and pin 3 to +3.3V.

Open the Serial Monitor in the Arduino IDE, and it will print the IR codes it receives. Use them directly in the program below, the lines are commented with "Button chosen for "ON" / "OFF". Recompile and transfer it to the ESP32.

The first output, "7770223", is the "1"-button on my remote control. So I added it to the row that says "Button chosen for "ON"". The next number shown, "7774303", is the "2"-button on my remote. It was added to the row that says "Button chosen for "OFF"". I even pressed "3" on my remote, "7766143", but did nothing with that value.

I just found this video that shows very clearly why the diodes on the relays are needed. Worst case, you'll get a 250V peak without them. This can harm your electronics, and will create very audible pops.

The Muffsy Relay Input Selector combats this by using the flyback diodes, of course, and separating the power and signal grounds.

One problem with projects like these is that the wiring has a tendency to end up as a heap of spaghetti.

So I've been wondering about how I should do the rotary switch in particular (in a setup without the ESP32 module). This is the simplest setup, and you don't have to write any code at all.

Coinciding with this, wireless coverage isn't that great in my new house. So I bought a Google Wifi bundle, and look what came with it:

Yup, a very flat network cable. Great timing, hey? Let's get snipping!

I kept the white leads on each side, and cut the white ones in the middle. The switch is 2P5T, I'll only use one of the poles. Yeah, and the ESP32 module will be removed.

Here's the board without the ESP32 and the transistors, cable fully connected:

There are crimp connectors on the rotary switch, since it's fairly sensitive to heat (such as from a soldering iron). That's it, apart from connecting power to the relays, connect inputs and output, and cut the flat cable to the correct length.

Finally, with power connected. The rotary switch works perfectly, turn it to slowly and it will break one channel before connecting the other one. So no two channels mixed at any time.

There you have it. A stereo relay input switch that can be controlled by either an ESP32-module or a rotary switch. Fully tested and all.

It also writes to the serial monitor when a relay is turned on or off, and uses two different ways of blinking the LED

This shows how to turn on and off relays. Remember, you can connect an LED between the relay1-5 IO pins together with a 330 ohms resistor to GND. This LED will light up when the corresponding relay is active.

The ESP32 has the capability to store the last selected relay, so it can be selected directly if the device is turned off and on again. (not shown here)

Instead of just looping through the relays you can use push buttons, a potentiometer or a rotary encoder (and lots of other things that can hook up to the ESP32) to decide which relay is turned on.

Testing with an oscilloscope and the QA401 audio analyzer reveals that there's no switching noise, nor any clicks or pops injected in the audio channels. And, it does of course switch the left and right stereo channels. :)

* Using "make before break" relays * There are diodes between the relay rails * The relay power/GND is separated from signal/GND (which means this things needs its own separate PSU to work as intended)

I hope that will make this thing silent. I won't know before I build it though. PCBs are on their way on the slow boat, so it'll be a week or four...