Constant connection to button from ESP32

I’m trying to connect an ESP32 to a board from a remote control, so I can press the buttons from HA. This is my first ESP project, so I’m still learning. I first set this up with a breadboard and LEDs to test it, and it worked great.

Now I’m soldering the ESP32 to the board, but I’m running into an issue where the LED on the board stays on, indicating that the button is being “held down”. I’m not sure if it’s an issue with my code or has something to do with how I’m making the connections. Any help would be appreciated!

output:
  - platform: gpio
    pin: GPIO26
    id: gpio_on
  - platform: gpio
    pin: GPIO27
    id: gpio_off

switch:
  - platform: template
    name: "TV Mount"
    optimistic: True
    turn_on_action:
      - output.turn_on: gpio_on
      - delay: 300ms
      - output.turn_off: gpio_on
    turn_off_action:
      - output.turn_on: gpio_off
      - delay: 300ms
      - output.turn_off: gpio_off

I’ve only got pin 27 hooked up at the moment



That looks like a keyboard matrix which is detecting connections from one pin to another, you won’t be able to just apply voltage to a particular button and get the desired result. The MCU there is scanning the rows/columns of the matrix and looking for a connection, and providing power to each row or column as it performs the scan. Injecting voltage into it will create press signals to multiple buttons and undesired presses.

Your best bet is a relay to connect to the button you want to press as it will function identically to the switch that is in the circuit currently.

If the signal is Infrared from the remote, it would be much cleaner to connect an IR receiver to your ESP32, capture the code and then attach an IR LED to the ESP32 and replay the captured command.

The remote is RF and uses 2.4g, which is why I’m going this route since it won’t work with a Bond Bridge. I think I have the wiring figured out that I need to do. Does this look correct?

That looks good, I think that will do the job, although I’m not 100% on your specific relay module, but it does look right.

Awesome, thank you so much for your help! I will report back once I get the relay and wire it up

No it doesn’t.
You mix 5V and 3.3V if your wiring is like on your image.
You should remove the jumper, power the relay at 5V on the JD-pin(and GND) and connect the other header to 3.3V, Gnd and Gpio.

Also, the remote button is probably switching GND and you could do it just with Esp without relay (to verify with multimeter).

Does this look better?

Can you please explain what you mean about switching the GND and wiring it without the relay?

It’s not readable. It’s correct if the jumper is removed and 5V is wired to JD pin and VCC pin next to it is not connected to anything.

Since you are supplying remote button board from Esp32 and applying GND to the button pad (through relay) why don’t you connect the button directly to Esp32 Gpio-pin? And set the pin OUTPUT_OPEN_DRAIN.

Edit:
Also, if the button pad is triggered with GND, the turn_on/off_action on your post#1 is wrong, you need to invert the logic.

I would switch the relay to opto couplers.
They are much smaller and silent

1 Like

Setting the pins to OUTPUT_OPEN_DRAIN and inverted = True did the trick! I was able to wire the ESP directly to the buttons and leave out the relay. Thank you so much for your help!

Good.
Be aware of the correct relay circuit for your next project.

+1 to @Hellis81’s suggestion to use optocouplers when dealing with something as small as a remote.

Was working on a similar project and these ready-made boards are perfect for the job - smaller than a relay module, come in 2/4/8 channel versions, and quite cheap.

But you just need the little black part.
The rest is unnecessary

Agreed 100%, but for someone who’s just starting out & tinkering, it’s perfect due to the screw terminals.

You can always desolder the little black part and hook it up directly once you know what you’re doing :wink:

No relay or optocoupler was needed in this case.
But optocouplers are handy when voltage levels are not compatible between each other.

1 Like

Or when you optically what to separate the circuits, like when one might destroy the other

1 Like