Tiny RTC causes arduino to hang when switching relay

Hello everybody!

My set-up involves a Leonardo which is connected to an RTC, LCD (I2C) and a relay which switches 230V (electronic ballast for metal halide lamps). The relay has a separate power source than the arduino. The electronic ballast issues 5kV voltage to get the lamps started. To avoid any kickbacks the relay has diodes for the coils and I also installed a snubber (100 Ohm + 0.1 uF) across the 230V contacts of the relay.

The RTC is connected via I2C with 4700 Ohm pull-ups. From the RTC the LCD is connected also via I2C. Also, I have some 0.1 uF caps across the power lines before the RTC and the LCD display.

Nevertheless The arduino hangs whenever the relay switches the internal ballast if I have the delay() at the end of my loop() set to 100. Some weird characters are shown on the display and sometimes its backlight is even turned off. If I set it to 1000 the arduino hangs very, very seldom when the relay switches.

Does anybody know why? I thought that if there is some voltage spike or something similar its consequence for the circuit is independent of the delay() within the loop().

Anyway, I tried to reduce my program to make sure it is not some weird software issue. Nothing helped even though I reduced the program to only switching the relay - the problem did not go away. Thus I rule out a software issue - hopefully.

At some point I started removing hardware modules. If I remove the RTC and connect the LCD directly to the Leonardo via I2C there are no issues. No weird characters shown when the relay switches, it works perfectly even if I set the delay() to 10 in the same program delay(100) made it hang before on every switch.

Why does the RTC cause so much trouble while the LCD does not seem to care? Could I assume that this means that there is no kickback in the circuit but some other EM problem?

Finally I tried to connect the LCD to pin 2+3 and the RTC to the SCL and SDA pins on the Leonardo. But again, the whole arduino hangs if I switch the ballast. Also I tried to only connect SDA+SCL to the RTC, i.e. no 5V+ground.

What else can I try to avoid the RTC hanging the arduino?
Can I really rule out that the circuit gets some kickback since the LCD works without problems?

Any help would be greatly appreciated since I ran out of ideas.

Sven

Hi Sven

Can you post your code, so we can see how the delay in loop() relates to calls to the RTC.

Also please post links to the RTC and LCD modules.

The arduino hangs whenever the relay switches the internal ballast if I have the delay() at the end of my loop() set to 100. Some weird characters are shown on the display and sometimes its backlight is even turned off.

Can you clarify what you mean by "hang"? After the weird characters, it sounds like the program appears to halt?

In the normal configuration, are you supplying +5V and GND from the Arduino to the RTC and the LCD?

Does the problem still happen if you leave the relay connected but disconnect the load?

Regards

Ray