So I've decided to hop on the ESP8266 WiFi module bandwagon and build a light switch with a couple of differences.

1) the light switch needs to go in the wall and be the same size as the existing panel light switches (deeper will be OK)

2) the circuit needs to pull power from the existing 250v power that runs through the switch

3) the light switch needs to contain a microphone so I can walk around the house issuing voice commands and each light switch will be able to hear the command and relay it to a central hub for processing.

4) the light switches will use the esp 8226's ability to be a wifi client and AP to create a mesh network so commands can be relayed around the house.

5) I need a design that an support up to 4 switches in one light switch panel.


1) What should I use to pull 5v from the 250v power supplier. I've seen switching power supplys but these are all fairly bulky and contain transformers. I was hoping that there was a smaller solution. I only need 250mA to power the device.

2) Can the esp 8226 be used to forward raw audio from a digital microphone. I would estimate the device will need to handle about 100Kbps given I probably won't have sufficient room on the device to compress before I send the data. So there are two parts to this question

a) is it possible to wire a microphone to the esp 8226 and capture the audio

b) can it handle 100Kbps

3) If I 3d print the panel and a mount box in PLA is that considered electrically safe ?

4) How much of a challenge is reception going to be if the antenna is in the wall? Should I expose the antenna on the switch face plate? As i'm designing the light switches as a mesh network there should be another light switch just a few meters away in most cases.

Sorry if the questions are dumb but I'm a programmer not an electrical engineer.

  1. "Only" 250mA is not the word I'd use when you want to drop up to 345V (if full wave rectified) - I'd like to hear you managed to dissipate 80+ Watt in a linear regulator. The 2 common options are a) full wave rectify, and use a buck converter to drop to 5V (addendum by bss36504: flyback converters do both) b) Use a transformer to drop the AC voltage first, then rectify and you may use either a linear regulator depending on the dropout voltage and the voltage ripple across the filtering capacitor of the rectifier. My advice to you is: c) don't reinvent the wheel, it's time consuming, expensive, and potentially dangerous. Use one of those 5V wall wart. They're bulky due to their transformer, but they work first try and they have been safety-checked. Otherwise you'll have to ask an electrician to check your system to cover your back in case anything goes wrong (I suspect insurance may not reimburse your home if it burns down because of something that you've done yourself and has not been checked...)!
  2. The ESP8266 will never be able to send uncompressed audio at 100kbps in real time. This source has tested it and measured 7kbps in TCP, and 19kbps in UDP. What you could do though is recognise commands, and send the command waveform at a slower rate. Assuming one command takes 1 second, it would take 15s to send the command over in TCP and 6s with UDP. Maybe you can compress on board first, reducing the time it takes to send the data, but I doubt you can do it with a ESP8266 alone (I've seen it done on Atmega328s). As for the microphone connection, you've got 2 GPIO's exposed on the connector of the common 8-pin ESP8266, and I THINK none of them are analog. Enough for a serial microphone module. The chip has 1 ADC though, so there are bigger boards with more signals routed and in particular 1 ADC which would allow you to use the more commonly available analog microphone modules such as this one. Seeing how voice recognition is barely good enough with a decent PC or smartphone microphone, I have no idea if the audio will be clear enough with cheap microphone modules, you need to test it.
  3. As long as you use a decent wall wart (or equivalent) to drop mains voltage to less than 25V, a PLA enclosure is absolutely fine and in fact it would be legal to leave the box open if the environment is dry. This should be valid in Europe only although I suspect it's similar elsewhere. I don't have my BS EN 7671 book with me, so you'd better check the details yourself for anything above 12V.

I'm about to do the same here, and my advice to you is that you should probably trade some of this off: I'm personally going to use "OK google" on my phone, and send the commands to the correct ESP8266 in the house. After all, who wanders around without their phone nowadays?

  • 1
    \$\begingroup\$ 1) I don't think this can be done without a transformer somewhere. Also, Buck is not the topology to use when transitioning from mains voltage (You would use a flyback converter). At this power level, you could probably get away with a small, inexpensive step down transformer fed to a linear regulator. 2) Good luck doing voice processing on board. That's one of the most complex computing tasks in existence. It isn't really feasible to do it on board. You will likely need to find a way to transmit your voice data back to the hub like you initially hoped. \$\endgroup\$ – Brendan Simpson Mar 3 '16 at 14:47
  • 1
    \$\begingroup\$ Thanks for your comment. 1) If rectified first, buck can be used. Flyback is better because it uses a transformer as part of the converter. I've added this in my post. 2) You're only partially right. I said "maybe", because I've seen it done on Arduinos so 8 bit micros can do it. I doubt the ESP8266 can do it on its own, but coupled to an Atmega328 it could be done (see uSpeech). It all depends on how many features you need. Simple, distinct, words are not that bad to recognise. \$\endgroup\$ – Mister Mystère Mar 3 '16 at 14:56
  • 1
    \$\begingroup\$ I had not seen uSpeech, thanks for pointing that out. I recently spent a solid week searching for something just like that and came up empty. You learn something new every day! I'd imagine the ESP's processor could handle that though. I think we can all agree, an inductor will be necessary somewhere, and a transformer and a linear will probably be the simplest to design. Finding a buck controller at that voltage will be hard, which leaves it to a custom design. As the OP said, they are a SE not an EE. \$\endgroup\$ – Brendan Simpson Mar 3 '16 at 15:03
  • \$\begingroup\$ Compromise suggestion: find one of the easier codecs such as AMR and use that to transmit the speech. Although the work I did with openAMR required most of an ARM926EJS, so I'd not expect it to fit into an Atmega. It's speech optimised and has silence detection so you don't have to TX continuously. \$\endgroup\$ – pjc50 Mar 3 '16 at 16:51
  • \$\begingroup\$ Firstly as the OP, thanks for your responses. I'm still googling to actually understand some of the comments but I will come back with more once I've done my research. \$\endgroup\$ – Brett Sutton Mar 3 '16 at 21:38

Just regarding your power supply question: For the ESP8266 you need 3.3 Volts, not 5. If you use an Arduino as main processor, remember to use an 3.3V model.

You could use something like this as supply. Small(ish) and more than enough power for the ESP and a bit additional stuff.


I've built a ESP8266 power switch that can go into the wall console. You can check detailed description on my website: http://hristoborisov.com/index.php/projects/switcher-a-wifi-open-source-power-switch/

I am using this power supply: Hi-link 5V/3W (you can find it on the internet). Then I am using LM1117 to lower it to 3.3V

Antenna reception is good enough even if the esp is in the wall. I am using esp8266-01 with pcb antenna.

PLA box is in my view well isolated electrically.


1) 220V-5V adapter can be use. Phone charger is best solution when we take out only PCB inside, it is small

2) Microphone for ESP8266 -> not sure it can work with microphone

3) Mount box from 3D print -> it's safe by plastic

4) don't need antenna. ESP8266 has good antenna for signal

I've done this kind project. ESP8266 to control light switch from phone or local switch, of course it is in small size. You can visit for instruction http://engineer2you.blogspot.com/2017/07/esp8266-wifi-light-switch.html


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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