As per title I'm, looking a way to detect the press of a button powered at 220v ac through a gpio pin of the ESP32.

The simplest solution found seems to be an octocoupler, but are there devices that support such a high voltage difference? What could be a connection scheme?

  • why don't you do some research? ... you are not the first to solve this
    – jsotola
    Jan 1, 2022 at 21:43
  • what could be a connection scheme? ... connection to what? ... your post has no information
    – jsotola
    Jan 1, 2022 at 21:44
  • How is a “button powered at 220V”? A button does not use any power (or an extremely small amount). A button just opens or closes a circuit, which in the simplest case would be between your local reference voltage (usually 3.3V or 5V) or ground and a GPIO pin (details vary depending on the type of button). If there’s 220V somewhere around, there’s more than just a button… please provide a schematic of the circuit which includes this button.
    – jcaron
    Jan 2, 2022 at 23:55

1 Answer 1


I would recommending just getting a small normally open (NO) relay with 230V AC coil and then run your ESP32 Vcc (3.3V) to one relay contact and back from the other contact to a GPIO pin.

Alternatively check out AC main detector module for schematics on how to do it with an optocoupler.

  • Thanks, the link was just what I was looking for, I already knew about the relay, but this wasn't a viable solution for costs and space. Anyway at the end i used the solution attached to the first post
    – Stefano
    Jan 9, 2022 at 14:53
  • Very thanks for the info. But I'm really new and I can't understand how to use a relay to get the input form a button. I know if I send a signal to relay this will open the circuit of 220v. But I need, when the circuit of 220v is closed (now my button is 24v I think is the same with different relay), send a signal to esp32 (I use esphome to compile the esp32 device) The "AC main detector module" maybe is good, but I can't find a DC 24v version The thing I need is: when the 24v circuit is closed send a signal to esp32. Very thanks Niks Sep 12, 2022 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.