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:
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?
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.
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.
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.
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.
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.