ESP8266 Wireless Light Switch - UK Mains - Schematic/PCB Review and Suggestions

Hello all,

Currently in the process of designing a small project to make my UK light switches Wi-Fi connected whilst at the same time keeping the current light switches (they're nice stainless steel ones).

I've had the schematic looked over by a couple of people on another forum and they seemed to think that part should work... not had chance to breadboard it all yet as I don't have all the parts.

The next stage for me assuming it will work on the breadboard is to get the PCB compact enough whilst trying to maintain the best practices. Now I'm completely new to the PCB creation world so what I've done is potentially the completely wrong way of going about it but I've loved to get some feedback on the PCB and if you feel like it the schematic for the project too.

The way I have it: UK Mains (230V) connected to a HLK-PM03 providing 3.3V for the ESP8266-01 chip. Connected to the ESP8266 is a standard UK light switch and also connected to the ESP8266 is an optocoupler and triac which in turn connects to the load (in this case a light).

Light switch connector shouldn't have a resistor, or you may not get a reliable LOW (it's a voltage divider with the pull-up resistor of the ESP).

I see no phase detection so I take it this is meant to be a simple on/off, no dimming. Should work like that.

What's the purpose of RV1?

Looks like it will work but be very careful when prototyping; I don't think a solderless breadboard is a good idea when working with line voltages. Will need some soldering.

RESET and CH_PD should be connected to 3.3V. Easy to fix.

GPIO0 and GPIO2 need to be pulled high for normal boot. This is going to cause you some difficulties.

You could add a 10K pull-up to GPIO0, but this might leak enough current to activate the opto-isolator all the time. And in any case, the opto-isolator might pull the pin low, preventing normal boot.

I don't know what to suggest for GPIO2. You need it to read LOW with the switch in one position, but that would prevent booting, should there be a power failure while the switch was in that position.


You may be better off using TX for the opto-isolator and RX for the switch. This will make programming & testing the esp-01 awkward, but in the final circuit, you won't need TX/RX.

Also, I'm no expert on triacs. But my gut tells me the way you have the opto-isolator and triac connected looks wrong. The opto-osolator pin 6 is connected to the switched live.

PaulRB:
RESET and CH_PD should be connected to 3.3V. Easy to fix.

RESET can normally be left floating with ESP-01 modules (that's at least what all circuits I find on Google do), apparently it has a pull-up resistor installed. The CH_PD indeed does have to be connected to Vcc (either directly or with a 10k resistor, both work fine).

GPIO0 and GPIO2 need to be pulled high for normal boot. This is going to cause you some difficulties.

GPIO0 high for normal boot; low for program mode. In my experience a normal LED causes no problems - the 1.8V or so V(F) keeps the pin voltage high enough. An optocoupler's LED has lower V(F) which may not be enough to be detected as HIGH.

GPIO2 needs to be high indeed but can be left floating: the internal pull-up is enabled on boot. A switch on that line is indeed not a good idea, a momentary push button should give no problems.

The only reason I went with the ESP8266-01 is for size to try and keep it compact, not realising I would have issues with the GPIO pins. Would I be better then going with the ESP8266-12F which has more GPIO pins and maybe won't cause me as many issues?

wvmarle:
Light switch connector shouldn't have a resistor, or you may not get a reliable LOW (it's a voltage divider with the pull-up resistor of the ESP).

I see no phase detection so I take it this is meant to be a simple on/off, no dimming. Should work like that.

What's the purpose of RV1?

Looks like it will work but be very careful when prototyping; I don't think a solderless breadboard is a good idea when working with line voltages. Will need some soldering.

When I breadboard with the light switch, I tested it with just an LED connected to a GPIO and the switch without the resistor and that seemed to work fine. However if I attached a relay to the GPIO without the resistor there wasn't enough current for the relay to operate (the LED on the relay module lights but no changeover), however with the resistor this worked?

RV1 was from a suggestion on https://skippy.org.uk/quick-look-at-the-hlk-pm01/.

And yes just on/off for the first design.

Tenatious:
The only reason I went with the ESP8266-01 is for size to try and keep it compact, not realising I would have issues with the GPIO pins. Would I be better then going with the ESP8266-12F which has more GPIO pins and maybe won't cause me as many issues?

That's a barebones module - need external components and so. Do have a look at the WeMOS D1 boards, much easier to work with (especially during prototyping - if you're done you can upload your sketch on the ESP-01, and use GPIO1 & 3 (TX and RX). After setting up OTA updates you don't need them any more for that purpose.

By the way, GPIO2 is the TX of Serial1 (no RX for that interface, it's for debug only). Can be very convenient at times, such as debugging a sketch you uploaded OTA and TX and RX are in use for other purposes.

wvmarle:
That's a barebones module - need external components and so. Do have a look at the WeMOS D1 boards, much easier to work with (especially during prototyping - if you're done you can upload your sketch on the ESP-01, and use GPIO1 & 3 (TX and RX). After setting up OTA updates you don't need them any more for that purpose.

By the way, GPIO2 is the TX of Serial1 (no RX for that interface, it's for debug only). Can be very convenient at times, such as debugging a sketch you uploaded OTA and TX and RX are in use for other purposes.

I've got a Wemos D1 mini at the moment which is what I've been testing on. Haven't got hold of the ESP-01 yet so just assumed it'd operate in the same way, hence my mistakes!

Ah okay, I'll go with RX and TC for the I/O and modify my schematic with this :slight_smile:

So if I've understood you correctly, the schematic should look like this:

GPIO2 may be left floating.
GPIO0 must be pulled low to enter programming mode - you don't have any facility for that. A momentary button is the normal solution - as long as it's pulled low when booting it's fine, after boot it may be released as the chip boots in program mode.

For more details read the ESP beginner's guide. Very useful, tells you everything about the different GPIO and their functions.

Hopefully this is right then...

ESP is fine.

PaulRB:
Also, I'm no expert on triacs. But my gut tells me the way you have the opto-isolator and triac connected looks wrong. The opto-osolator pin 6 is connected to the switched live.

This doesn't matter. It's AC so both directions are fine, as long as the opto is wired "in parallel" to the triac, i.e. between the gate and the cathode on the other side of the part.
Even live/neutral doesn't matter at all. You can turn around the plug and it works just the same.

Have you considered a sonoff? If not, have a look at this video. It covers exactly what you're trying to achieve! Good luck!