Designing a circuit to control a low signal dual coil DPDT latching relay from a single ESP32 GPIO

Thread Starter

joulupukki

Joined Sep 9, 2022
271
I'm wondering if there's anyone who may be able to help me figure out how I might control a 5V Dual Coil Latching Relay (maybe something like the Panasonic TQ2-L2-5V or the KEMET EA2-5TNJ) from an ESP32's GPIO pin?

My project is an open source chromatic tuner (Q-Tune: https://github.com/joulupukki/q-tune) that will be housed in a guitar pedal enclosure (125B size). I'm using an ESP32-CYD (Cheap Yellow Display: https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display) and unfortunately there are not maybe GPIOs available for use. I'm reading an amplified guitar signal using GPIO 35, reading the state of a momentary foot switch on GPIO 27, and want to control a dual coil latching relay with GPIO 22.

When a person taps the footswitch, I will see that by reading the state of GPIO 27 and if the tuner should go into tuning mode, I want to signal the relay by sending a constant 3.3V signal on GPIO 22. That will disconnect the incoming audio signal (stereo) from continuing on to the rest of a pedalboard or guitar amp. When a person taps the footswitch again, I will read that and change GPIO 22 to a constant 0V signal which should signal the relay again and put the pedal into true bypass mode so the signal bypasses the tuner circuitry entirely.

Is there some way to watch for the rise and fall of the GPIO 22 signal and send the appropriate 5V pulse signal (> 10ms and < 100ms) to the correct relay coil to set or reset the relay?

I already have a partial PCB designed that uses a standard pedalboard 9V DC IN with a voltage regulator that outputs 5V to power the ESP32 and attached screen.

It seems like this should be possible, but I've been banging my head against the wall trying different things gleaned from the Internet in LTSpice with not a lot of success. Using an external pre-built relay (very common in the DIY world) isn't really an option because most of them are controlling 120/240V appliances, expect 2 GPIOs to be available, and I also need to add this circuitry directly onto my PCB that will sit underneath the ESP32-CYD.
 

AnalogKid

Joined Aug 1, 2013
12,043
If I read this correctly, you want a circuit that takes a simple, single-pole momentary switch and turns it into an alternate-action set of contacts using a latching relay. Tap once, relay pulls in and latches. Tap again, relay releases and latches.

Yes / No

If yes, this can be done either with a standard relay and an electronic latch circuit, or a pulse-forming circuit and a latching relay. If you want to use a latching relay, then it must have two sets of contacts (DPDT), one for the audio switching and one to direct the switch pulses to the correct coil.

ak
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
If I read this correctly, you want a circuit that takes a simple, single-pole momentary switch and turns it into an alternate-action set of contacts using a latching relay. Tap once, relay pulls in and latches. Tap again, relay releases and latches.

Yes / No

If yes, this can be done either with a standard relay and an electronic latch circuit, or a pulse-forming circuit and a latching relay. If you want to use a latching relay, then it must have two sets of contacts (DPDT), one for the audio switching and one to direct the switch pulses to the correct coil.

ak
Actually, the momentary foot switch on the pedal will be directly connected to the ESP32 so that I can support things like long presses, double presses, normal presses and do different things in the software and on the screen. It won’t just be a simple tap to toggle the relay state. At least that’s what my hope is.

I think I need to figure out how to watch the rising and falling edge of my GPIO’s 3.3V output and translate that to a square wave 5V pulse that’s around 20-50ms. A rising edge should generate a 20ms 5V pulse to the relay’s Set coil and a falling edge should generate a 20ms 5V pulse to the relay‘s Reset coil.
 

BobTPH

Joined Jun 5, 2013
11,463
Your job becomes trivial if you have just one more pin. If you are not using all the parts of the device, steal a pin from an unused part as suggested here. It sounds like the “boot” button is already a n unused button on the device. Perhaps that input could be used for your foot switch.

Personally that product sounds rather silly to me, that they used up all those pins for features 90% of users won’t need, leaving only 3 pins for the end user. They could have at least had some jumpers to make the unused pins available.
 
Last edited:

Sensacell

Joined Jun 19, 2012
3,767
Use a tiny 6 pin microcontroller like the PIC10F series chip as a relay controller.
Write code to switch the relay coils, with pulses.
Use 2 X 3V logic-level NFETS to switch the relay.

Cannot think of a smaller-tighter-cheaper way to do it if you have only one IO pin.
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
Your job becomes trivial if you have just one more pin. If you are not using all the parts of the device, steal a pin from an unused part as suggested here. It sounds like the “boot” button is already a n unused button on the device. Perhaps that input could be used for your foot switch.

Personally that product sounds rather silly to me, that they used up all those pins for features 90% of users won’t need, leaving only 3 pins for the end user. They could have at least had some jumpers to make the unused pins available.
I’ll have to see how easy (or not) is might be to replace the boot button with a connection from the foot switch. Since this CYD is all surface mount components it makes it a bit more difficult. Ideally, a builder of this tuner kit wouldn’t have to do any physical modifications to the CYD, but definitely a good thought that I’ll look into.

Use a tiny 6 pin microcontroller like the PIC10F series chip as a relay controller.
Write code to switch the relay coils, with pulses.
Use 2 X 3V logic-level NFETS to switch the relay.

Cannot think of a smaller-tighter-cheaper way to do it if you have only one IO pin.
In this case would it act as a toggle and just switch the relay to its opposite position when detecting a pulse? Another requirement is that at boot, the tuner software must be able to specify to the relay what exact position to be in. For some, they like to power up in muted/tuning mode. Others prefer to power up in bypass/standby mode.
 

AnalogKid

Joined Aug 1, 2013
12,043
I think I need to figure out how to watch the rising and falling edge of my GPIO’s 3.3V output and translate that to a square wave 5V pulse that’s around 20-50ms. A rising edge should generate a 20ms 5V pulse to the relay’s Set coil and a falling edge should generate a 20ms 5V pulse to the relay‘s Reset coil.
Turns out, this is a semi-common request. I've posted several circuits to do this. One has two pulse circuits, one triggered by the rising edge and one triggered by the falling edge. There always will be a slight difference in the two pulse widths, but this shouldn't be an issue for you Another circuit has only one pulse timer, and directs it to one of two outputs depending on the input edge polarity. A bit more complex, but it guarantees that the two output pulses are identical. And, only one adjustment affects both output pulse widths equally.

IIRC, each circuit has only one IC, a quad NAND, a hex inverter, etc. I'll post them later.

ak
 

sghioto

Joined Dec 31, 2017
8,633
and want to control a dual coil latching relay with GPIO 22.
All transistor version and using a single coil TQ2-L-5 latching relay with one GPIO control.
When GPIO is high Q2 is ON and the relay coil gets a latching momentary pulse through C1.
When GPIO is low Q2 turns OFF and Q2 turns ON discharging C1 with reverse polarity through the relay coil to reset.
1734460810541.png
 
Last edited:

crutschow

Joined Mar 14, 2008
38,316
All transistor version and using a single coil TQ2-L-5 latching relay with one GPIO control.
Q3 has marginal turn-off due to Q1's saturation voltage and the voltage drop of D1, even though D1 is a Schottky.
Suggest adding another diode in series with Q3's base.
 

AnalogKid

Joined Aug 1, 2013
12,043
Here is one of the circuits, reworked for your application. A positive edge a the input caused Q2 to pulse, and a negative edge causes Q1 to pulse.

The inductors are the two relay coils. Click on the schematic for a larger image.

ak


!!DualPulser-9-c.gif
 
Last edited:
Top