I'd like to fit an ESP32 directly into a single gang (North American) electrical box with enough room left over to fit a typical light switch over the top of it (these are usually pretty shallow, and the box itself is almost 3" deep).

What sort of hardware would I need to wire one of these into AC directly?

I'm trying to solve the problem of not having batteries everywhere in my house, where I spend 8 hours a week hunting down dead batteries and replacing them. I have no clue how it's become acceptable to design products like exterior door locks with batteries. I suspect it's a stock market scam to boost share prices for Energizer.

The National Electrical Code apparently tolerates mixing low voltage and high voltage in a single junction box for communication devices, supposing that it meets several criteria:

  • The wires/conductors have at least 6mm of separation on the board and within the box
  • The wires/conductors for the low voltage portion meet the same insulation standards as those for the high voltage (no cheapskate jumper wires, in other words)
  • All components are clearly marked as low/high voltage

This could (in theory) meet code.

This is an IoT question and not a "how do you power a general purpose computing device" question because:

  1. It requires a networked computing device small enough to fit into a single gang junction box.
  2. It's for the purpose of connecting a sensor and/or an actuator to a home automation system.
  3. It would require hardware specific to such a device, nothing general purpose would suffice.
  4. The very premise of the question rests on the challenge of putting such devices where they have not tended to fit before.
  • 3
    This sounds like a bad idea. Edit the question to describe the actual problem you are trying to solve with this and we might be able to suggest a better alternative.
    – hardillb
    Mar 11, 2022 at 22:04
  • 3
    Again what is the actual problem you want to solve? Are you trying to power the ESP32 from 110VAC? Are you trying to monitor the voltage or current of the AC line? Are you trying to switch the AC line? "Wire ESP32 directly to 110VAC" means more to you than to us.
    – romkey
    Mar 11, 2022 at 22:26
  • 2
    No it's not, say what the ESP32 will be doing, otherwise you should be asking this on the electrical engineering site, not here.
    – hardillb
    Mar 11, 2022 at 22:27
  • 2
    Please edit the question as asked. And you still haven't answered my question about WHAT the ESP32 will be doing. If you can't answer that question then you really are asking in the wrong place
    – hardillb
    Mar 11, 2022 at 22:32
  • 2
    See arduino.stackexchange.com/questions/86116/… note that heat dissipation IS an issue, and that in many countries plugging something like this is subject to code, and may not be allowed unless the device is certified. The risk of electric shock or fire really exists.
    – jcaron
    Mar 12, 2022 at 0:32

2 Answers 2


Take a look at the Tasmota project, which allows you to run custom code on cheap off-the-shelf ESP8266 and ESP32 mains devices.

You can probably buy some cheap hardware that does what you want, or will do what you want with very minor modifications.

  • I appreciate the advice. I install Tasmota on all of mine, getting ready to gut a Broadlink RM Mini 3 and replace the board with a D1 Mini board just for that.
    – John O
    Mar 14, 2022 at 5:17

I still think this is a bad idea, but 5 seconds (it was in the list returned by the top none advert hit) of googling for "3.3v from 110v ac" turns up the following:


The dimensions appear to meet your requirements.

I expect it to get warn sealed up in the wall, so when one burns your house down you were warned,

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