I'm planning to add some home automation to my home, using a 5V relay and most likely an ESP8266.

This will be used, for instance, to control the lights or the heaters, certainly through Home Assistant. I have experimented a lot with 5V DIYs, but this will be the first time that I will touch to 220V (domestic voltage in France.)

I read a lot of tutorials before even thinking of reproducing this, as I have very little knowledge of electronics. For instance, I'm considering a circuit like this one. (source [fr]).

However, most DIY tutorials do not dare to address all the possible security issues. Some are just mentioning "be cautious for fire hazard due to high voltage", but nothing more specific.

In such a relatively small project, what is the worst that can happen and what should be done to prevent it?

Any source of noob-friendly documentation would be very welcome.


Reading the comments, I could refine my search keywords and find some resources.

For instance, you could consider this circuitbasics tutorial (and especially the comments). It certainly doesn't seem to require an electrician but it would be very interesting to be proved wrong here. If they actually teach something wrong I think it is essential to notify it.

Electrical experts should really be aware that DIY is a thing and that telling people to seek qualified persons instead of teaching themselves is useless: they will do it anyway.

However, teaching what should be done in the right context might make some aware that they cannot do all the required things. In this case, they will stop by themselves and ask a qualified person.


I live in a concrete building, as there are almost no more homes made of wood in France, especially in big cities like the one I live in (unlike in the USA I think). This might be important to consider regarding the fire hazard.

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Voltage Spike
    Nov 24, 2020 at 19:02

3 Answers 3


What should be done to prevent danger and what are the risks?

  • fire, usually caused by a short circuit, have a fuse, check all connections are secure, don't connect the mains to the 5v circuit. Check the relays are rated for the correct current, take into account inductive loads such as motors, transformers, power supplies etc.
  • electrocution, don't have any exposed connections that are live or neutral, if you can touch it and it is metal it shouldn't be live or neutral and should be earthed.
  • earth leakage tripping RCD or GFCI, don't have any path between live and earth or neutral and earth.

Always use the relay to switch the live side of the circuit, and as you are in france where they have some non-polarised connectors, only use plugs with earth sockets in to ensure that the live (switched side) is always connected to the same pin and isn't connected to neutral.

  • \$\begingroup\$ If you are not confident: don't test the circuit around anything flammable, don't touch the circuit at all, not even the low-voltage part, unless it's in a nice non-conductive plastic box. \$\endgroup\$ Nov 24, 2020 at 18:46

In addition to what MParks said, I would add:

If there is a metal box, ground it. So that a loose wire inside the box cannot cause the box to become live.

Also try to keep some minimum distance between the high voltage and low voltage parts of the circuit, usually it's something like 5mm. This is so that some moisture, or a fleck of metal won't energize the "safe" part of the circuit with high voltage.


The following is my advice, purely from a safety perspective. I cannot speak to any regulatory concerns in your country.

  1. Avoid working with exposed live mains. Prototype your system using lower voltages.
  2. Use enclosures designed for electrical use, either made of flame retardant plastics or made of metal. If using metal enclosures ensure they are solidly connected to mains earth.
  3. Where wiring enters an enclosure containing mains ensure it is adequately restrained.
  4. Use wire with insulation rated for mains voltages.
  5. Keep the mains and low-voltage parts of your circuit seperate, test as much of your system as you can before bringing mains into the picture.
  6. Use components with appropriate safety ratings for any crossings between the mains part and the low voltage part. Keep the mains and low voltage connections to those parts as far apart as reasonably possible.
  7. Be careful about relay boards sold by various "maker" vendors. I have seen way too many such boards that are fitted with mains-rated relays but are designed in a way that is in no way appropriate for mains-voltage use. IMO there is a lot to be said for industrial relays with screw terminal connections to avoid the need to either design PCBs suitable for mains use or find relay boards that were actually of competent design.
  8. Use an appropriate safety-rated power supply to power your low-voltage circuits.
  9. Ensure there is adequate over-current protection.
  • \$\begingroup\$ Maybe 10. Wear eye protection the first time you switch it on, preferably with a switch some way away, and be ready to see where any smoke comes from. \$\endgroup\$ May 24, 2023 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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