Close a circuit using ESP32?

I have an LED Light bar. It has a push button on each end that if I push either, the light comes on. Removing one handle, I see a JST-XH2Y plug. Removing that plug, and shorting the two pins turns on the light.

What I want to do is to short those two pins with an ESP32 when a person enters the room. I am all set with Home Assistant, ESPHome, mmWave presence detector, ESP32, etc.

The part I need help with is: can I safely short those two pins using the ESP32 only, or do I need a relay to do the work? It is my belief that the two buttons just short the circuit and there is already a relay inside the light bar that does the heavy lifting, but I need to prove that. If I put a multimeter on the two pins in the JST-XH2Y plug, set to measure amps, then the light does light up, but the multimeter reads 0.000 Amps. If I put the multimeter in miliamps or microamps mode, with the leads in the relevant multimeter pins, and across the JST-XH2Y plug, then the light bar stays off.

Does this sound like it is safe to short those two pins with the GPIO on an ESP32, or is there better testing that I should be doing?

EDIT: I measured 2.8 volts across the two pins on the JST-XH2Y plug. Also, the light bar has an internal battery, and a 12v DC barrel plug for charging.

Thanks for any guidance.

Without seeing a better description of the light bar, specifically the voltage and current across the two pins, I won’t make any recommendations.

Thanks for your reply. Measured on a Fluke 17B+:

2.95v
1.70 mA

I could not get my cheap multimeter, nor the UNI-T to show the Amps at all, but the Fluke showed 1.69 to 1.70 mA.

I will have a look to see if I can see anything in the ESP32 specs to see if that is good, but appreciate any guidance as well.

Thanks

wire the pins to a relay and use that to short the connection for the light.

1 Like

Thank you for the reply. With the relay option I need a relay and another power supply. That is fine if it is the only way to go. If the ESP32 can close a 3 volt 1.7 mA circuit with the inbuilt pins, then the project will be cheaper, smaller, and more power efficient. It is all running off a 12 volt solar battery.

Thanks

How are you currently powering the ESP? You should be able to use the same power supply since you can get relays that run on 3.3 or 5v.

Looking at the doco, it appears that the GPIO pins on ESP32 can handle up to 40mA. So 3 volts, 1.7 mA should be fine. But I think I am asking the wrong question.

I am not certain that any of the GPIO pins on the ESP32 can be configured to act as a switch? I can see them programmed to supply voltage, or to receive voltage, but can they switch an external voltage?

Looks like I am looking for a relay then. Most of the relays I have seen are quite large for large volts and amps, and I only need to switch 3 volts, 1.7 mA.

Thanks

no they can’t, hence needing to use a relay.

The ratings you are seeing are max values so that’s fine. ie: a relay rated to switch 10 amps will obviously very easily switch 1.7mA

Damn. I thought this would be a quick project with the stuff I already have. :slight_smile:

With a 5 volt micro USB cable, into a USB Socket that is on the side of the 12 volt 100 Ah deep cycle 12 volt battery.

Just raided my parts bin and found a HK4100F 5 volt relay that can switch up to 30v DC, 3 Amp. Will use that.
Thanks

Just configured the ESP32 with GPIO27 as a switch in ESPHome and tested it. It does output 3.3 volts when the switch is on in Home Assistant. But the relay that I have needs 5 volts to work. Is there any way to use the HK4100F 5 volt relay with the ESP32 GPIO pins? Or do I need to go buy an ESP32 with the built in relay as linked above?

Just trying to use what I have in order to save time and cash, and learn something in the process.

I will probably order a couple of those relay ESP’s listed above, as they will likely come in handy anyway, just that it will take a couple of weeks for delivery in Australia.

Thanks

Level shifter

I would rather use a mosfet if you want to buy it anyways. Doesn’t have mechanical parts and doesn’t make “clicking” noises when switched. It also should in theory last much longer.

For around $4 such a device is available which can be powered directly from the 12V source for your light bar.

In the past I’ve had no issues at all with using relay modules like this. Due to them having some input circuitry to control the relay they will switch at 3.3v input, because you also feed 5v to the other pins on the board.

Thanks for this link, that is a much more appropriate product for my needs. I have already ordered an ESP32 relay and an esl8266 relay, but I will likely not see them until end of Feb. They might come in use for something later, they were only the cost of a couple of coffees each.

I will look at getting one of these…

I do have a question for those that understand relays. The light bar that I am going to control with esphome has two momentary switches. Push either, and the light goes on. Push either again, and the light goes off. Well that was how it worked. Now, if I push the switch, the light goes on only while I hold the switch on.

From my research on these relays, it appears that this light bar must have had a latching relay, that is no longer latching. Does that sound like it is the issue? I am now thinking that I will attempt to pull the LED light strip out of the housing, and locate this relay, and attempt to bypass it, making the new relay perform that duty. Initially I was just going to close the 3.0v 1.7mA circuit that turns on the relay within the light bar.

Also, given the esp32 relays linked above (Relay is on the board with the ESP32, is there any limit to the length of time that the GPIO can provide the 3.3 volts to pull the relay? Typically, in my scenario, the light will only stay on for a minute after the presence is no longer detected, and typically, it will be a few minutes per day. I guess this will be fine for the ESP32?

Thanks, appreciate your help while I learn this.

Either option should be possible, which ever is the easiest for you I guess. If it’s not too difficult to pull it apart and bypass the internal relay that would be better, but you may find there is no relay but in fact electronic switching being done.

No issue in keeping the relay energised for long periods of time. I have relays on for hours at a time, operated by ESP’s.