Crosstalk / Interference from relay to ESP8266 pin

Hello,

So I have this project in ESP8266 which uses a relay (GPIO4) and what I call a "factory reset" whose porpuse is to clear the microcontroler's EEPROM. You can see the connection in the following image:

In the schematic, you can see the microcontroller's connections and relay in the following image:

The problem with all this is that the "Factory reset" is connected to a switch button, whose function's code is:

void ICACHE_RAM_ATTR FactoryReset()
{
  Serial1.println("<< Push Factory Reset >>");
  static unsigned long previousInterruptionTime = 0;
  unsigned long currentMillis = millis();
  static int numPulses = 0;

  if (currentMillis - previousInterruptionTime >= 200)
  {
    previousInterruptionTime = currentMillis;

    if (currentMillis - previousInterruptionTime <= 3000)
    {
      numPulses++;
      Serial1.println("Push: " + String(numPulses));

      if (numPulses >= 5)
      {
        Serial1.println("\n\n¡¡FACTORY RESET!!");
        EEPROMManager::removeAll();
        EEPROM.end();
        ESP.restart();
      }
    }
    else
    {
      numPulses = 0;
    }
  }
}

So, as you can see, after 5 consecutive interrumptions, it clears the EEPROM and restarts the device.

What is happening if that I am writting the relay pin to high and low, which is connected to a contactor and turning on and off a set of lights from a building.

The behavior is ok, but for some reason and WITHOUT pressing the "factory reset" button, I can see how the program is detecting "factory reset" interrumptions, what must be from the relay being turned ON and OFF.

My initial hypothesis is that the relay is making some kind of interference to the "factory reset" pin, making it detect as it was set to HIGH, while it is not.

What I can see is that the relay track is kinda close to the pin, but I am not really sure. What do you think?

Thank you so much,
Diego

It sounds like EMI (Electromagnetic Interference) Try moving the relay away from the Arduino. If the load is AC use a solid state relay that utilizes zero crossing. This about the best I can do without seeing what you did. Thanks for the schematic, it ruled out a few problems.

1 Like

Hi,
I agree with @gilshultz , but also I would be widening those tracks where possible.

Especially any power supply tracks and try and route any supply tracks to the relay coil so that the coil current does not share the same track carrying current with the controller.

Tom... :grinning: :+1: :coffee: :australia:

1 Like

What is connected to that relay.
Strange things can happen when you switch an inductive load without back-emf protection.
Leo..

1 Like

Hey Tom

Thank you for your answer. Can you explain what do you mean with

and try and route any supply tracks to the relay coil so that the coil current does not share the same track carrying current with the controller

please?

Diego

Can you please post an EXPORTED jpg image of your PCB?

If you have a track that is connected to the gnd power input, if you just loop it from component to component and the tracks a very thin.
When current travels in that track, there will be a voltage drop, the component on the end of the loop will have its gnd pin above the power supply gnd.

If you use wider tracks and route them so that major current flow is kept way from other current sensitive components you can minimise that sort of problem.

Tom... :grinning: :+1: :coffee: :australia:

Use a single continuous ground plane.

Min track width/space 10/10 mils

Use a snubber on the relay output.

Don't use interrupts for the switch.

Use a simple R-C filter on the switch input.

Yes, the load is a single phase installation. Do you recommend any specific solid state relay for this solution?

Thanks,
Diego

It is a single phase installation, specifically, It has access to the lights of a building.

Anyway, how can I provide the system with that "back-emf protection". Not understanding you really well there... sorry

Thanks,
Diego

Hi,
Thanks for the images, but I was refering to this type of image, from the PCB editor not a 3D rendering.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hello again,

Sorry for the missunderstanding. Here it is:

Thanks!
Diego

The schematic looks sound to me, except that I'd use 100 uF instead of 10 uF for C2.

There's a lot of code missing. Lots of ways to make mistakes there.

Re-use of global variables in other places could be the cause of such behaviour as well.
If you need a variable to keep its value between calls to a function, you can declare it static within the function. Prevents that kind of errors.

1 Like

If you look through all the relay treads here with code/lock-up problems, then you frequently see that the problem comes from the load that the relay switches. Because most beginners forget to add a snubber circuit across the relay contacts.

Do you also have the issue when nothing is connected to the relay contacts?
Leo..

Does your relay control a contactor, how does it access the building lights?
What load current through the relay?
What sort of lights?

The width of the tracks between the relay contacts and the output terminal appear to be TOO narrow.
Also the isolation gap between those tracks and the ground plane are way too small if you are switching 230V at the relay.

A complete schematic would also help, please include ALL components, including the power supply components.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Fixed with the snubber circuit. Thank you so much :slight_smile:

Hello,

It fixed by adding a snubber circuit as Wawa suggested. Thank you so much for your help!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.