Optoisolator relay, ESP-8266 12 E, Electromagnetic interference

Hi.

I am using dual channel Optoisolator relay with my ESP8266 12-E module programmed through Arduino IDE to control 25watt AC 240 energy saver bulb. Relay is isolated according to following;

https://arduino-info.wikispaces.com/RelayIsolation

Every thing is working very smooth since months. But I want to add a push button and interrupt in my setup. But it is facing Electromagentic interference problem, especially when turning off Higher AC load such as pump which are not connected to my system. I think EMI is coming through power line, I am using 2 ampere 5v Power supply and 100 uf 16v electrolyte capacitor after power supply and couple of two parallel 100nf capacitor before and after 3.3 v regulator (AMS1117 3v). I have also tried 470uF capacitor after power supply in place of 100uF, Also tried with out capacitor. All have the same results.

i.e. If bulb is turned ON or OFF, I switch on motor pump (2hp), nothing happens, but when I switch off motor pump, light turns OFF if ON or turns ON if OFF.

Circuit picture is attached.

I also tried reed switch in place of push button and found that, if both component of reed switch are close, there is no false interrupt due to motor pump, but if i put the reed component apart (in open position), same problem arises as in case of push button. I have attached pull up resistor of 10k ohm in both situation (for reed and push button).

May someone please help me to cope with EMI?

Is your schematic correct? I don’t see any connection from the power supply/regulator to the ESP8266 ground.

  • Scotty

It is connected Sir, the blue circle. File is attached

AMS1117 Power Supply Stability Check figure 1 in the datasheet. You'll need to use 22µF on the output (Vout).

Grounding I assume there is a ground connection from the ESP8266 12-E to the AMS1117 regulator (not shown) or your circuit wouldn't work.

EMI(RFI) Your connections to the relay module seem OK for opto-isolation providing the jumper is removed and there is no ground connection to the ESP8266 12-E.

The interference is happening when the relay contacts break the load and arcing occurs. If the motor is 240VAC, I would recommend using an MOV like this across the contacts.

You can reduce RFI further by increasing the distance from the relay module and AC circuit to 1-2 meters if possible.

Also make sure the AC wiring is located separate to the low voltage wiring.

Thank you so much dlloyd for detailed answer. Yes there is ground connection between AMS 1117 regulator and ESP8266.

And I am not controlling Pump with relay, I am just controlling 24 watt bulb with the relay (Only one channel of two channel relay is being used). Pump switch joins the AC circuit around 2 meters away from my ESP8266 setup and Pump is installed around 4 meters away from my ESP8266 setup.

I'll consider using 22uF capacitor on AMS1117 output. I have few questions in my mind right now.

1) Why I have problem with my set up only when reed switch is not in joined state (but separated). There is no false interrupt when reed switch is in joined state. May you explain this phenomena?

2) You advised to use MOV. To which contacts should I use MOV? I am getting confused. May you tell me according to my circuit diagram (through it is very rough diagram)?

3) If I connect my main ground to metal sheet installed on brick wall (I have not installed yet)? Will it help reducing EMI strength (Actually I am using a wood container for holding my circuit with ESP8266 and Relay). I have read somewhere that increasing ground area reduces the EMI.

4) You advised "You can reduce RFI further by increasing the distance from the relay module and AC circuit to 1-2 meters if possible". Do you mean increasing distance of relay from my ESP8266 circuit?

I'll consider using 22uF capacitor on AMS1117 output.

Yes (high priority).

I also tried reed switch in place of push button and found that, if both component of reed switch are close, there is no false interrupt due to motor pump, but if i put the reed component apart (in open position), same problem arises as in case of push button. I have attached pull up resistor of 10k ohm in both situation (for reed and push button).

After re-reading your original post, I think the main problem is just the false interrupt. The cause is probably a combination of things ... contact bounce, noisy power supply, RF signals from the ESP, AC ripple and noise on inputs, EMI/RFI.

Getting a false interrupt is quite common in a setup like this, especially when there's no debounce (external filter or code) implemented. Here's a hardware debounce suggestion for the switch input:

1) Why I have problem with my set up only when reed switch is not in joined state (but separated). There is no false interrupt when reed switch is in joined state. May you explain this phenomena?

I'm not sure what input is your interrupt pin ... could you post your code? The above filter might resolve the problem.

2) You advised to use MOV. To which contacts should I use MOV? I am getting confused. May you tell me according to my circuit diagram (through it is very rough diagram)?

It's not on the diagram, but it could go across the motor power connections. Another MOV could go across the bulb connections. Is it CFL type?

3) If I connect my main ground to metal sheet installed on brick wall (I have not installed yet)? Will it help reducing EMI strength (Actually I am using a wood container for holding my circuit with ESP8266 and Relay). I have read somewhere that increasing ground area reduces the EMI.

The relay should not be close to the ESP8266 ... physically separate as much as possible (i.e. 2 meters). Using separate ground wires all terminated to a common point (star-point grounding) will prevent ground loops and is highly recommended. I don't think the metal sheet will be necessary.

4) You advised "You can reduce RFI further by increasing the distance from the relay module and AC circuit to 1-2 meters if possible". Do you mean increasing distance of relay from my ESP8266 circuit?

Yes ... relay and any AC circuitry.

I think we have to be careful with such glib generalisations as “increasing the distance from the relay module”.

This problem has a lot to do with layout of the components and good wiring practice, which cannot be summarised so simply. In fact, the most important thing is that wiring is “tight”, with (short) power rails and all other input and output connections run together in pairs, switches referenced to ground and grounding to a common point at the Arduino.

41af8ad67afb4d2df4ff7d6e48fb2d53a7b3cd23.png

There is already a concern there with the relay module returned to 5 V while its inputs are controlled by 3.3 V outputs. Even allowing that the optocoupler and indicator LED drop 2.7 V so will generally not “back-feed” the ESP8266, we potentially have a large pick-up loop in the supply chain.

A perfectly focused photograph of your set-up with all wires and parts clearly visible as they terminate on the modules and showing that as a link in the text, preferably not an attachment, would likely give a clue to the problem.

The best way to actually do this unless your workshop is lit by multiple floodlamps, is to take it outside in full daylight but not direct sun and use a digital camera at least a metre away from directly above (or very slightly offset to ensure all the connections are able to be distinguished) using the (actual) zoom to just include all parts of the assembly.

I think we have to be careful with such glib generalisations as "increasing the distance from the relay module".

This problem has a lot to do with layout of the components and good wiring practice, which cannot be summarised so simply. In fact, the most important thing is that wiring is "tight", with (short) power rails and all other input and output connections run together in pairs, switches referenced to ground and grounding to a common point at the Arduino.

Not a glib generalisation ... I've designed relay boards for 600VAC and installed over 5,000 relays over the years. There isn't much any circuit, no matter how well designed, that can survive the severe RFI/EMI effects caused by [u]close proximity[/u] contact arcing when breaking a highly inductive and high voltage AC load. Especially without EMI suppression across the contacts or load itself. Increasing the distance [u]always[/u] makes an improvement.

From the diagram, it appears the relay module is connected properly for opto-isolation. I believe that if this wasn't the case, the problems would be much more severe than just an invalid interrupt. More like lock-up of the Arduino along with random I/O states.

My only very minor concern with operating the opto-leds using 3.3V is not having a large pick-up loop (outputs are inherently not sensitive to noise) but a slightly slowed operate and release time of the relay, which means more contact arcing than if using 5V control.

Its unfortunate that the most common practice is to use a fly-back diode across the relay coil. This resolves one problem (inductive spike at the coil) only to cause increased contact arcing during contact release due to the much slower release time. A much better design is to use a zener-diode or TVS solution across the coil with clamp voltage >= coil voltage.

The issue here is easily resolved ... as it stands, its only one false interrupt when the relay breaks the load.

Thank you so much dlloyd for your kind support.

dlloyd: The issue here is easily resolved ... as it stands, its only one false interrupt when the relay breaks the load.

dlloyed, I think there is a little misunderstanding, As I am facing false interrupt not in case of "relay breaks the load". I have a pump which is few meters apart my circuit and which is not controlled by any relay but a bigger manual switch (25 Amp) as used in regular electrical domestic wiring. When I push the switch up to turn on the pump, I don't face any false interrupt on my ESP8266 circuit (Which has a push button on it to toggle the bulb ON and OFF which is controlled by relay). But when I lower the switch to turn the pump off, I face false interrupt which toggle the bulb.

ESP8266 is very sensitive device which used to fails in case of improper circuit. But in my case it is running for months which out being reset or failed even once. I am only facing false interrupt problem. Few months ago, when I had not practiced optoisolation, my system was very unreliable and leads to failure.

Moreover, I have tried the same setup with Solid state relay SSR-10DA. Which can be controlled from 3~32VDC.

http://www.fotek.com.hk/solid/SSR-1.htm

But the problem is very same in case of both relays, False interrupt.

dlloyd: AMS1117 Power Supply Stability Check figure 1 in the datasheet. You'll need to use 22µF on the output (Vout).

According to datasheet, I should use 22µF tantalum capacitor. I have 22µF 50v Aluminum electrolyte capacitors. May I use Aluminum electrolyte capacitor in place of tantalum capacitor?

Yes, just make sure it is close to the regulator, and use a 0.1 µF ceramic in parallel with it.

dlloyed, I think there is a little misunderstanding, As I am facing false interrupt not in case of "relay breaks the load". I have a pump which is few meters apart my circuit and which is not controlled by any relay but a bigger manual switch (25 Amp) as used in regular electrical domestic wiring. When I push the switch up to turn on the pump, I don't face any false interrupt on my ESP8266 circuit (Which has a push button on it to toggle the bulb ON and OFF which is controlled by relay). But when I lower the switch to turn the pump off, I face false interrupt which toggle the bulb.

OK, thanks ... the contact arcing at the switch contacts is causing the false interrupt. This MOV connected across the contacts should make an improvement. If not, take a look at the MHXAC1F240 NOsparc Arc Suppressor.

Moreover, I have tried the same setup with Solid state relay SSR-10DA. Which can be controlled from 3~32VDC. http://www.fotek.com.hk/solid/SSR-1.htm

Unfortunately, some of these SSRs do not switch the load ON/OFF properly (at zero-cross) with inductive loads, or if the control signal is low voltage (3.3V or 5V). 12V control signal provides a more reliable zero-cross turn ON/OFF as it will provide adequate trigger current in the internal opto circuit. Datasheet

ESP8266 is very sensitive device which used to fails in case of improper circuit. But in my case it is running for months which out being reset or failed even once. I am only facing false interrupt problem. Few months ago, when I had not practiced optoisolation, my system was very unreliable and leads to failure.

Yes, the opto-isolation is working and will resolve conductive EMI issues on the power rails.

I would focus on the false interrupt itself ... it could be debounced in hardware as shown in reply#5 or in software. If you could provide your code, I'm willing to help add software debounce to your interrupt routine.

dlloyd:
If you could provide your code, I’m willing to help add software debounce to your interrupt routine.

Here is the code. I am attaching two files. “vickey_complete.ino” contains complete code including my WiFi, MQTT setup and various other function which I have not arranged as a library yet. While “vickey_main_code.ino” contains simplified version of What I am doing regarding Relay, Interrupt etc. in “vickey_complete.ino”.

vickey_complete.ino (16.1 KB)

vickey_main_code.ino (665 Bytes)

Here, the ISR should be fully debounced (rising an falling) , the on board LED should will show the debounced status:

volatile byte history = 0xAA; // history of switch status
unsigned long timeNow = 0;
unsigned long timePrev = 0;

void setup() {
  pinMode(5, INPUT);
  attachInterrupt(5, toggleSwitch, CHANGE); // rising or falling is detected in ISR
}

void loop() {
  timeNow = micros();
  if (timeNow - timePrev > 100000) { // switch polling interval
    timePrev = timeNow;
    history = history << 1 | digitalRead(5);
  }
}

void toggleSwitch()
{
  if ((history & 0xF) == 0xF) { // previously stable high, now falling
    digitalWrite(13, LOW);
  }
  if ((history & 0xF) == 0x0) { // previously stable low, now rising
    digitalWrite(13, HIGH);
  }
}

Ok. I'll try it and post the results. Thank you so much for your kindness dlloyd. I have one more question.

If I want to add one or two more switches, How should I modified that "0xAA" part? As Its first time I trying this kind of stuff.

If I want to add one or two more switches, How should I modified that "0xAA" part? As Its first time I trying this kind of stuff.

That's the status for just one switch, it defaults on startup to binary 10101010 which will be considered "unstable" or bouncing until the loop fills it with readings from the switch input.

Just add another variable for each switch i.e historySwitchA, historySwitchB etc. Would also need separate timePrev and timeNow variables for each switch.

I have it so there needs to be 4 previous stable readings (taken 100000µs apart = 0.4sec debounce time) before the ISR will consider the CHANGE interrupt valid and perform an action based on rising or falling status.

This is untested code (just an idea of how to debounce both when the switch is pressed and when the switch is released).

dlloyd: This is untested code (just an idea of how to debounce both when the switch is pressed and when the switch is released).

Just an update: I tried the idea and ESP8266 12-E crashes when I press the button.

You'll need to focus on the arc-suppression ... it may take more than one corrective action, but this can be resolved.