Relay Controlled with ESP-8266

I have a schematic that I got from a YouTube video and adjusted the relay to switch the Live of the AC.

I wanted someone to confirm to me whether it will work or not. If not, how to make it work. Thank You in advance.

Schematic: Electifi OTI v3 - EasyEDA open source hardware lab
YouTube Video: Make your own Sonoff | DIY Sonoff | Sonoff wifi switch using ESP8266 and MQTT | IoT Projects - YouTube

Any idiot can make make a video. Unfortunately that is exactly what you found, an idiot that built a dangerous piece of crap that looks like it works.

Provide a proper 3.3 volt supply, move the emitter of the bc547 from mains to dc minus and perhaps you will not kill you yourself touching the low voltage side. The esp-01 will probably fail due to the lack of a current limiting resistor for the led/Opto, it depends on the led.

Work? I seriously doubt it. It’s a crap design from a YouTube genius.

WattsThat:
Any idiot can make make a video. Unfortunately that is exactly what you found, an idiot that built a dangerous piece of crap that looks like it works.

Provide a proper 3.3 volt supply, move the emitter of the bc547 from mains to dc minus and perhaps you will not kill you yourself touching the low voltage side. The esp-01 will probably fail due to the lack of a current limiting resistor for the led/Opto, it depends on the led.

Work? I seriously doubt it. It’s a crap design from a YouTube genius.

Do you by any chance have a way to make it work or any other schematic that would serve the same purpose?

That design look extremely dangerous (as already stated) because there appears to be a direct connection between the AC mains and the “low” voltage side of the circuit.

If the objective is to control mains voltage using an ESP8266, then purchase a purpose made relay module which includes an optocoupler, driver transistor, bare relay, fly back diode, led etc. all on a small board. So you can eliminate all those individual components.

You would be left with the ESP, the AC mains to 5v converter, the 3.3 volt regulator (with 2 capacitors - not shown) , a push button and of course a relay module.

If you can find a relay module which can be powered at 3.3 volts, you can get an AC mains to 3.3 volt converter and then also eliminate the 3.3 volt voltage regulator.

6v6gt:
That design look extremely dangerous (as already stated) because there appears to be a direct connection between the AC mains and the “low” voltage side of the circuit.

If the objective is to control mains voltage using an ESP8266, then purchase a purpose made relay module which includes an optocoupler, driver transistor, bare relay, fly back diode, led etc. all on a small board. So you can eliminate all those individual components.

You would be left with the ESP, the AC mains to 5v converter, the 3.3 volt regulator (with 2 capacitors - not shown) , a push button and of course a relay module.

If you can find a relay module which can be powered at 3.3 volts, you can get an AC mains to 3.3 volt converter and then also eliminate the 3.3 volt voltage regulator.

The thing is all of the Relay Modules I saw have small terminals, that is why I want to make one of my own so i can make custom PCB's.

SoulG23:
The thing is all of the Relay Modules I saw have small terminals, that is why I want to make one of my own so i can make custom PCB's.

Care to explain what you mean there?

Paul__B:
Care to explain what you mean there?


These wire terminals are small.

These are the ones I want to use.

OK. If you want to build your own relay module, which can be triggered by 3.3 volts and powered by 5 volts, this circuit is likely to be more reliable. Two mixed leds in series (including the one in the optocoupler) especially at 3.3 volts is not a good idea. The relay here is activated when the ESP pin is high.

If you redraw your schematic, try to group and cleanly separate the mains voltage, 5 volts an 3.3 volts parts of the circuit.

6v6gt:
OK. If you want to build your own relay module, which can be triggered by 3.3 volts and powered by 5 volts, this circuit is likely to be more reliable. The relay here is activated when the ESP pin is high.

esp8266 - Can I use a 3.3v GPIO to control an opto-isolated 5v relay board? - Arduino Stack Exchange

If you redraw your schematic, try to group and cleanly separate the mains voltage, 5 volts an 3.3 volts parts of the circuit.

In this schematic is the relay isolated from the ESP?

and Thank you for your help.

SoulG23:
In this schematic is the relay isolated from the ESP?

and Thank you for your help.

The ESP is isolated from the high voltage side of the relay. The 3.3 volt pin of the ESP is sufficiently isolated from the 5 volt circuit through a 1K resistor and a transistor.

6v6gt:
The ESP is isolated from the high voltage side of the relay. The 3.3 volt pin of the ESP is sufficiently isolated from the 5 volt circuit through a 1K resistor and a transistor.

Alright I will try it. Thank you very much.

6v6gt:
OK. If you want to build your own relay module, which can be triggered by 3.3 volts and powered by 5 volts, this circuit is likely to be more reliable. Two mixed leds in series (including the one in the optocoupler) especially at 3.3 volts is not a good idea. The relay here is activated when the ESP pin is high.

esp8266 - Can I use a 3.3v GPIO to control an opto-isolated 5v relay board? - Arduino Stack Exchange

If you redraw your schematic, try to group and cleanly separate the mains voltage, 5 volts an 3.3 volts parts of the circuit.

Correct me if I did something wrong.

You do not need U3, it is superfluous. R3 is too high, it should be 220 ohms for the relay used. The 2N3904 is not appropriate, too close to its max ratings. To select a far better switching transistor, do you have preference for surface mount or thru-hole devices?

OK. If you are now using a "30Amp" relay instead of the original "10Amp" variant shown in the video, there will be some consequences. The coil current of this model is 185mA.

Are you using a buck converter for the 5v to 3.3v device or a voltage requlator ? Anyway, check the data sheet to see if it requires capacitors which are not provided elsewhere in the modules you are using.

If you insist on using an optocoupler, a current limiting resistor is also required for the internal led.

When it comes to PCB design there has to be a clear separation between the mains side and the low voltage side so there will be a stronger grouping of the relay, the input and output terminal block and the power converter input. I would begin to reflect this already on the schematic.

WattsThat:
You do not need U3, it is superfluous. R3 is too high, it should be 220 ohms for the relay used. The 2N3904 is not appropriate, too close to its max ratings. To select a far better switching transistor, do you have preference for surface mount or thru-hole devices?

I rather use thru-hole devices.

6v6gt:
OK. If you are now using a "30Amp" relay instead of the original "10Amp" variant shown in the video, there will be some consequences. The coil current of this model is 185mA.

Are you using a buck converter for the 5v to 3.3v device or a voltage requlator ? Anyway, check the data sheet to see if it requires capacitors which are not provided elsewhere in the modules you are using.

If you insist on using an optocoupler, a current limiting resistor is also required for the internal led.

When it comes to PCB design there has to be a clear separation between the mains side and the low voltage side so there will be a stronger grouping of the relay, the input and output terminal block and the power converter input. I would begin to reflect this already on the schematic.

This is the one I am using. It is capable of providing 800mA.

If the Optocoupler is not required I will remove it from the schematic.

SoulG23:
This is the one I am using. It is capable of providing 800mA.

Possibly, if you are dropping from only 5 V.

SoulG23:
If the Optocoupler is not required I will remove it from the schematic.

If you have the same ground connected to both its input and output, is is not isolating anything at all. :astonished:

WattsThat:
You do not need U3, it is superfluous. R3 is too high, it should be 220 ohms for the relay used. The 2N3904 is not appropriate, too close to its max ratings. To select a far better switching transistor, do you have preference for surface mount or thru-hole devices?

Is the 2N5401 good for the job?

Wrong polarity, it is PNP. The 2N2222 (or PN2222) is a common NPN that would handle the 200ma relay you’ve specified.

In general, you want a device characterized as a switching transistor rather than an amplifier.