It’s a common issue when running inductive loads from a Arduino controlled relay. Many folks think it’s a voltage problem and try throwing capacitors on the relay supply, or using a opto isolated relay (separate power and ground). These solutions may work, but more often than not, they don’t.
So what is causing the problem? It’s EMI!
The back EMF from an inductive load causes the relay contacts to act like a spark gap transmitter, scrambling the processor. The Atmel chips are very susceptible to RF.
Not to worry, it’s not permanent, it clears when you cycle power.
How did we discover this and how do you keep it from happening?
We have a project where a Nano and a common relay board are installed in a small case. When all the parts are assembled on the bench, it works fine. When crammed together in the box, it works for a while, then freezes. But only with a inductive load attached to the relay. With no load, or a resistive load, it runs forever (well, 3 days or more, forever was too long a test period). We have tested this six ways to Sunday with a variety of Arduino and Arduino clones.
Become the Maker you were born to be. Try Arduino Academy for FREE!
Installing snubbing diodes on relay coils and motors (the common solution) can be difficult (they don’t work on ac devices) or void a warranty on many household appliances.
I series connected a resistor and a capacitor together, and connected those across the Arduino relay contacts (as close to the relay contacts as you can get). This quenches the back EMF, and prevents the Arduino from locking up. There you go, a $0.30 solution to a nagging problem.
Make sure your capacitor is rated for the voltage you expect to see. I used a .1 uF 50v Tantalum, and a 100 Ohm 1/4w resistor on a 26v circuit. My load was another relay. In another application, the load was a 120v motor, so the cap was 150v.