ESP8266 mains sensor switch project - Page 1
Forum section: electronics / projects

author: Hixfield
author_rank: Contributor
timestamp: February 27, 2017, 06:57:47 am
content: Attached my schematic (and prototype picture) for my ESP8266 mains sensor switch project.Any feedback / help is appreciated.What is does?- Its a mains switch operated via WIFI based on the ESP8266- It contains a digital temp sensor (DS18B20)- It contains a PIR movement sensor- It has a beeper- It has a simple button that can be pressed that also contains a led for status indicationSo basically it can be configured as a WIFI enabled thermostat with manual button and movement activation for example.Maybe some questions / ideas :1. Do I need a big cap e.g. 330 uF to stabilise the power supply? I read many things regarding spontaneous resets of the ESP... If I look at the datasheet of my LM3940 it says that tantalum 47 uF in input and output is enough...?2. Do I need some kind of noice suppression (capacitor) on the mains input for the noise coming from the HiLink HLK-PM01 PUS ?3. Is it a good idea to include the varistor and fuse on the input such as I did?4. I am thinking of maybe also exporting all other unused pins of the ESP to some external header. But I do not have much room anymore in the casing. What would be the best option for this?5. Should I include pull-up/down on any unused inputs of the ESP?6. The attached picture is for europeans style plug. If I would want to make this a world-wide project I would need some case that can be ordered for all types of mains plugs (but with same internal structure/size/holes so I can use same PCB for all of them (PSU is universally supporting 110-240). After searching for 4 hours on the web, I could not find anything. Does anybody have any good reference for such a case?

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: February 27, 2017, 08:16:49 am
content: pin1 of jp2 should probably connect to ac2 of the power supply and MOV instead of pin2 of jp2. Otherwise it wont turn on at all.Should put fuse and relay contact both on the Active mains input.IEC C13 and C14 would suit this IMO.You are probably not allowed to sell into many countries without getting certification/approval.C3 maybe 100nF.(Always good to sprinkle 100nF everywhere in electronics.)I think MOV is ok done like that.Noise suppression depends on local rules, also psu manufacturer probably gives guidance on this.I don't think you would want a big cap like that.

author: kripton2035
author_rank: Super Contributor
timestamp: February 27, 2017, 08:31:19 am
content: what about hacking a Sonoff device ?https://www.itead.cc/sonoff-wifi-wireless-switch.html

author: Hixfield
author_rank: Contributor
timestamp: February 27, 2017, 08:32:15 am
content: Thx for feedback!pin1 of jp2 should probably connect to ac2 of the power supply and MOV instead of pin2 of jp2. Otherwise it wont turn on at all.sorry for not explaining good enough, but the PSU is always on. The relay just switches the mains device plugged into the output (mains) socket.So this should be okShould put fuse and relay contact both on the Active mains input.I don't want to fuse the mains socket output, just the PSU (remember the PSU is always on, see answer above).IEC C13 and C14 would suit this IMO.Do you mean C1 and C2?You are probably not allowed to sell into many countries without getting certification/approval.I would sell it as a DIY kit, I guess this changes the rules and I don't need certifications...?C3 maybe 100nF.(Always good to sprinkle 100nF everywhere in electronics.)increased to 100 nFI think MOV is ok done like that.OKNoise suppression depends on local rules, also psu manufacturer probably gives guidance on this.the psu supplier is vague, but I found some review here :https://skippy.org.uk/quick-look-at-the-hlk-pm01/I don't think you would want a big cap like that.looking athttp://internetofhomethings.com/homethings/?p=396I think I will include a 470 uF cap.Think its a good idea, better safe then sorry?

author: Hixfield
author_rank: Contributor
timestamp: February 27, 2017, 08:35:03 am
content: @kripton2035 yes i have seen those Sonoff devices, but hey... I just like designing things from scratchAnd I want a finished product with the right mains plugs and case and stuffI will design a PCB for this too... there is always some thing that comes close to what one wants to do, but well I just like inventing and designing things from the ground up

author: tggzzz
author_rank: Super Contributor
timestamp: February 27, 2017, 09:23:22 am
content: You appear to be thinking of how it willwork. So far so good.But when you are dealing with mains voltages and low impedance supplies, you also have to considersafetyand how it willfail. Which components can fail, how can they fail, and what will happen to equipment and people when they do fail?

author: Hixfield
author_rank: Contributor
timestamp: February 27, 2017, 09:36:35 am
content: Well I included a fuse at the psu input and a surgeprotection using varistor. I believe that is the same thing that commercial devices do (and sono)?Sent from my iPhone using Tapatalk

author: tggzzz
author_rank: Super Contributor
timestamp: February 27, 2017, 09:58:24 am
content: Quote from: Hixfield on February 27, 2017, 09:36:35 amThat's necessary, but not sufficient.Startwith how can the relay fail, the PCB fail, the varistor fail, the diode bridge fail, the connectors and interconnections fail.It would be dangerous for me to use this forum to attempt to teach you how to avoid some dangers, since I would only teach you poorly.Not all commercial devices are designed to appropriate standards. Some simply lie about whether they meet standards; there are videos on this website on that topic.

author: Hixfield
author_rank: Contributor
timestamp: February 27, 2017, 10:00:37 am
content: I dont understand. Could you give a few concrete examples based on my schematic?Sent from my iPhone using Tapatalk