0
\$\begingroup\$

Recently I designed a board to control the lights in my home remotely via HomeAssistant (ESPHome using a WeMos D1 Mini). Due to the lack of pins, I am using a PCF8574 to actuate the relays. The main issue I am facing is that when switching off fluorescent lights (be in PL-C 2 pin or tubular), the entire circuit (all the relays on the board) glitches to "ON".

Here is a circuit diagram of my board: Circuit Diagram detailing the important components As requested the .pdf files for the board and schematic.

A video of the problem I am facing can be found here. Between 0:00-0:27 of the video, I cycle through all LED lights in the room (using the remote app) and they work fine. at 0:27, I turn on the problematic fluorescent light. At 0:31, I attempt to turn it off but it doesn't turn off and causes all the lights in the room to suddenly turn on. Checking the logs shows that the ESP8266 did not reset nor did any of the PCF8574 pins go to "HIGH" during the period of the malfunction.

Hence I likely suspect that this issue is caused either by the PCF8754 glitching out or perhaps caused by some form of interference caused by the circuit design.

Interestingly, I had tried the board out before installing it on similar PL-C 2 pin bulbs which can be found here. As such, it's really perplexing as to why the circuit would have failed when being installed.

Currently, I have the following hypotheses (in order of likelihood:

  1. The PCF8574 glitches out when fluorescent lights are switched off on the relay. The cause behind this is unknown as I lack a proper oscilloscope and the know-how to troubleshoot the PCF8574. Solution: Redesign the board and switch the relay pins to the ESP8266 and leave the PCF8574 to do the sensing on the button and the outputs on the light

  2. Magnetic interference caused by the tangled nature of the wires could be causing the PCF8574 to glitch out. For reference, here is an image of the board being installed in the switch box: Image of board placed into socket Solution: Better wire management (which has been done, greatly reducing the amount of wire clutter); possibly isolating the wires from the circuit board using an aluminium foil?

  3. Lack of isolation between load circuit and signal circuit. Solution: Redesign the board with optocouplers to switch the relay with a separate power supply for the relays and the IC components.

I have written about this in greater detail in my blog here and have linked the relevant eagle files here if it is helpful.

As I am still a beginner when it comes to circuit design, I would be greatly appreciative of anyone who could point me in the right direction! Thanks everyone in advance!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ It's possible that the switching of the fluorescent lights is causing a transient on the power line which is then transmitted to your control circuit via the AC-to-DC power module you are using. One way to test this is to power your control circuit with batteries. \$\endgroup\$
    – ErikR
    Commented May 29, 2021 at 3:20
  • \$\begingroup\$ btw - are we talking about traditional fluorescent lights that are started with a ballast? \$\endgroup\$
    – ErikR
    Commented May 29, 2021 at 5:29
  • \$\begingroup\$ Yes it is a standard fluorescent light started by ballast. Thanks for the suggestion I will try the circuit again on battery power. If that works then it is most definitely the transient. \$\endgroup\$
    – Ethan Chua
    Commented May 29, 2021 at 6:13
  • 3
    \$\begingroup\$ First question: are you an electerician or otherwise legally allowed in your country to do fixed installations involving mains voltage in your building? Next: Why there are no pull-ups on I2C bus? Why no bypass caps? Why did you choose PCF8574, it has very weak ability to drive current out, even the 300k resistor may be enough to keep voltage much below 3.3V at FET gate? Why did you choose 2N7000, it can barely drive those relays when there is 3.3V at the gate? Why there are no snubbers on relay contacts to prevent arcing? \$\endgroup\$
    – Justme
    Commented May 29, 2021 at 6:42

3 Answers 3

0
\$\begingroup\$

If you want people to view your pcb and schematic, then make it available as a pdf.

First thing that jumps out at me is no pullup resistors on the i2C. Should be two 2k2 resistors. Any bypass caps?

With the fluoro, I’d suggest placing a varistor (MOV) across the fluoro supply. Something like a S20K270 if the mains is 230VAC or a S20K140 if 110. You could scavenge some movs from a dead PC power supply. A bit of Googling should assist if you are unsure.

The root cause is most likely a transient when the mains is removed from the fluoro. This transient probably finds it way via the relay, across your circuit and back around via your power supply. Adding a mov provides a preferential path for the transient and soaks it up. Other possible solutions are a snubber across the relay contacts using a 100nF mains rate cap and a 100R 2W metal film resistor.

Having not seen your pcb design, my guess is you don’t have enough creepage distance with your relay pins. The cheapy relays have the common pun between the low voltage coil pins. You need to ensure your pcb has slots to isolate the common from low voltage and that your lhigh voltage tracks do not come close to low voltage circuits.

Omron G2R style relays are much easier as they have sufficient distance between the coil and contacts.

I also hope you have adequate pcb track thickness and correct fusing so you don’t have a fire risk.

Keep your mains wiring away from the low voltage side.

\$\endgroup\$
2
  • \$\begingroup\$ Hello! Thank you very much for your feedback! As requested I have edited the previous post and uploaded the PDF schematic there. As for the pullups and the bypass cap, I will try soldering them on and try again. \$\endgroup\$
    – Ethan Chua
    Commented May 29, 2021 at 6:09
  • \$\begingroup\$ Next time, don't use the autorouter! You get extra points for having the slots in your pcb. There's no input protection, so I'd expect you'll have issue there if the wires run for a distance. The MOV is most likely going to be the solution to your immediate problem. Pullups and bypass caps are required, but unlikely to make a difference. \$\endgroup\$
    – Kartman
    Commented May 29, 2021 at 8:08
0
\$\begingroup\$

I found that the culprit to the problem was the PCF8574 and so I decided to go with hypothesis 1 and turns out the circuit functions without a hitch by driving the relays with the ESP8266's GPIO.

The PCF8574 still glitches and so occasionally I the lights on the buttons will all go out, but that's ok as the core functionality of the switches in switching the lights remains intact.

Thanks everyone for the help! I will be looking to replace the ESP8266 with an ESP32 with more IOs so I can drive everything from the IOs instead of using the finnicky I2C IO expander.

\$\endgroup\$
0
\$\begingroup\$

You are using N-FET to make it a Active High relay. PCF8574 has very weak current sourcing capability(about 300 microamps). It is best suitable to drive Active Low loads by sinking current. A PNP transistor or P-FET would have been a better choice.

\$\endgroup\$

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.