0
\$\begingroup\$

I am trying to build my own SONOFF like device by using a Wemos D1 mini and associated circuitry. I am facing an issue with electrical noise where whenever switching of the relay causes chattering behavior in my circuit. The issue does not happen always but happens mostly. I have built several circuits with ESP 12E , ESP 01 , WEMOS D1 mini and all of them exhibit some kind of erratic behavior.
I may not be able to explain all kinds of noisy behaviors I have seen but it has mostly been that when switching a relay, it switches ON and OFF multiple times or the second switch is triggered by the first one. I have done the following to either debug this or avoid this by:

  1. I have put a low pass filter on the input pins if noise at those pins may be causing this. This has had no effect
  2. I have replaced the 230V-5V module by a DC source to rule out interference from it - this has had no effect.
  3. I am using pre-built active LOW relay modules which I drive via a PC817 optocoupler to isolate the WEMOS with the relay but it has no effect.
  4. I have tried measuring the noise but I dont have a Oscilloscope to be able to see it. I have not been able to figure out if the noise is at the input or output PIN.
  5. The issue has no relation to the firmware on the ESP. I have had my own code , TASMOTA & ESPURNA frameworks, I am able to get a varying level of erratic behavior with all of them. TASMOTA device reboots when that happens while ESPURNA device switches ON and OFF several times or triggers the other relay.
  6. Also, if I disconnect the load form the relay and operate them the issue almost does not happen. The relay works just fine. So only when I connect the load (which is a fan or LED down lights) the chatter happens.

I have attached photos of the module I have built to enable somebody to point out some glaring issue but as I have made several modules in different configurations, I think that might not be an issue but open to hear if I am missing something there. I have also attached a circuit diagram of the whole circuit which it is based upon. Any ideas on how I can debug the issue more would be helpful. Thanks

Schematic

PCB Front view

PCB Back view

\$\endgroup\$
6
  • \$\begingroup\$ where are the resistors for those diodes? maybe you overloading output pins \$\endgroup\$
    – Maple
    Commented Jun 30, 2018 at 16:39
  • \$\begingroup\$ are you really putting 230VAC on that green-white cat-5 looking twisted pair? you should probably use a cable designed for 230V and scrape off the metal pads surrounding the mains voltages to gain some creepage distance. (overheating the pads with a soldering iron can loosen them) \$\endgroup\$ Commented Jul 1, 2018 at 9:38
  • \$\begingroup\$ @Maple - orange-orange-black south west of the optos north-west quadrant of the board. \$\endgroup\$ Commented Jul 1, 2018 at 9:41
  • \$\begingroup\$ you have D8 shorted to 3V3 this connection is not shown in the schematic. \$\endgroup\$ Commented Jul 1, 2018 at 9:45
  • \$\begingroup\$ Hi @Jasen, yes that wire for 230V isn't the final one, that was put only to test out on my desk. Actual installation has a proper 230V cable. \$\endgroup\$
    – Vijay
    Commented Jul 1, 2018 at 13:13

1 Answer 1

1
\$\begingroup\$

I would recommend connecting LEDs to +3.3V with current limiting resistors and switching them on by driving output low. You can also continue driving them by output high, but you do need current-limiting resistors anyway.

Also your phototransistors seem to be connected in wrong direction. It doesn't matter where you put the resistor (pull-up or pull-down) and connect output to relay, but emitter should go to the ground, not Vcc in either case.

enter image description here

I would also suggest supplementing capacitor on power supply with one of your own. And if it is the same to you I'd rotate the module to put antenna as far away from power supply and relays as possible.

\$\endgroup\$
9
  • 2
    \$\begingroup\$ to the OP : drawing your schematic so that Vcc is up and GND is down, and orienting components to suit that, would help avoid this kind of error. \$\endgroup\$
    – danmcb
    Commented Jun 30, 2018 at 17:13
  • 1
    \$\begingroup\$ @dmb good point! I often find it hard to read a circuit with random component placement... or with signal processing going from right to left, unless its some kind of feedback. \$\endgroup\$
    – Maple
    Commented Jun 30, 2018 at 17:20
  • \$\begingroup\$ The relays are 5VDC 70 Ohm and cannot ever draw 1A under any conditions. (pub.ucpros.com/download/…) They will draw a maximum of about 70 mA. Driving the relay input signal in the way you propose may not work at all, the MCU is 3.3V and won't drive 5V signal levels. \$\endgroup\$ Commented Jun 30, 2018 at 19:17
  • \$\begingroup\$ The relays actually have two versions, 71mA and 89mA. They CAN draw much more than that when you apply power to them, it is basic inductance behavior. But you are correct on 3.3V point, I'll update the answer. Regarding direct connection that I proposed, those modules have simple transistor switch on the input. I used them before. Even 1.5V is enough to open the transistor. \$\endgroup\$
    – Maple
    Commented Jun 30, 2018 at 19:41
  • \$\begingroup\$ @Maple A 'basic' inductor will conform to a conventional LR time delay for the current during activation. The current starts at zero and ramps up. How do you predict that you will get this high pulse of current? Even if you found another datasheet that quotes 89mA ….since the maximum current is set by the resistance value of the inductor/coil ...how will more than that current ever flow? The point about the transistor input is not about the ability of the 3.3V MCU to turn it on (it's on when low by the way, this one has no jumper) its about the output on high being pulled above 3.3V. \$\endgroup\$ Commented Jun 30, 2018 at 22:04

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