It's not uncommon for relays to cause problems for an Arduino if they're not properly isolated from it. Similarly, anything that pulls a lot of current (like your HID devices I suspect) can cause brownouts and subsequent resets.
Please provide more detail of the components you're using (including power supplies) and how they are wired up.
Hi thanks for the reply,
the ballasts are connected to mains via relay,
The Arduino is powered by an meanwell RS 25-5 (5V 5A Switching psu),
The relays are powered by a separate RS25-5,
It's all plugged in to a single outlet (16A breaker)
(Also tried different outlets, same result)
Powerdraw from ballasts is 0.2 Amps each. On power on its almost Double (source is osram website)
On power up no more than 2 amps should be drawn from mains.
Relays are connected to the Arduino with gnd, vcc and digital pins.
There is also an oled and rtc connected via i2c.
Relays should do 10A 230v.
Is it possible, that somehow the relay "backfires" into the Arduino?
Are these relays standalone? Optoisolated? A circuit diagram would be helpful. Basically though, it sounds like something is noisy or pulling enough current to reset the Arduino.
A diagram and picture, according to the posting guidelines, could avoid more questions.
Do not connect relay ground to Arduino ground. That defeats opto isolation.
The JD-VCC jumper must also be removed.
I assume you have kept mains wiring away from Arduino<>relay wiring.
Complex loads, like a pump and HID ballast must have a snubber circuit across the relay contacts.
Leo..
Sorry for the delay, here it is. It's the problematic circuit only (just one relay with ballast)
The ballast has an inrush current of 30A (operational in between 0.2 and 0.4 A)
Osram has no data on internal resistance, capacitance or inductance)
The dotted lines are the proposed snubber.
Osram technical service proposed to use a Electronic ballast rated relay, to keep up with the inrush current, but I guess that won't solve the EMI problem. (I guess)
Next thing I will try is to switch the relay with a switch connected to the Arduino only and no i2c devices. The program relies on a working rtc (as it switches the loads depending on the time from the rtc)
Maybe haywire i2c rtc is the reason for it bugging out?
Some tips here for reducing EMI.
Installing ferrite core(s) can be quite effective. One on the AC Line to the relay (try at least 4-turns through the hole) and could add a snap-on core to the power entry to the Arduino supply.
Thank you all!
I think it might be a bit... sketchy, but:
The way to success was to eliminate the Clock... unfortunately.
First I tried it with a simple switch, which worked, that led me to believe, that something is wrong with the bus itself.
Then I just used the external RTC to setHours() etc. to the internal RTC of the SAMD21. That worked as well.
Is there a simple way to restart the I2C connection? (Like checking if something is there and then beginning anew?
I will nevertheless get some Ballast rated Relays (there are some available at my local electronics dealer which are rated 800W for traditional ballasts) as I wont want my flat to burn out. Also Iam going to shield the I2C as good as possible.
I do want it to work not only get "patched".
The RC Snubber - I Am confident in handling simple AC wirework, but if its not necessary with a rated Relay, I wont go there, if you say it is necessary, ill talk to an electrician for that
I suspect that the RTC issue is a symptom, not the cause. The obvious culprit is the relay and I note that your circuit diagram indicates that you do have a shared ground. I'd put the clock back and run your code with the relay disconnected as a test.
Wawa:
Must do both.
No ground between the relay module and Arduino and snubber circuits across the contacts.
Leo..
Circuit was working fine, but then I thought, lets give it a shot.
Plugged in a Hairdryer in one of the Relay connected sockets.
That has the Arduino going loco again.
Okay, I'll go for the RC Snubber, get some bypassing and decoupling capacitors and throw in the suggested ferrite cores for good measure...
Those pesky ballasts ...
Anyway, here is a picture of the project, without the arduino.
(Stand is welded and build by me, in the bottom is all the "AC Stuff" ... well and the Relays. On top well be a small Box with the Arduino and a Display)
Further testing.
With RC snubbers (100 Ohms 0.1uF as a starting point)
With snubbers it works at a distance.
Before not even at 2m away. But 15cm away from the Lamp line was way to close.
It now starts to reliably work at a distance of about 25cm.
So I'll keep my distance an make it 50 and/or shield it.
Putting the Arduino in steel bowl at a distance of about 5cm also solves the problem.
Nevertheless, the RC snubbers clearly helped.
I did 10 testruns @50cm which works regardless of shielding, and 10 runs on top of the assembly with a steel bowl.
Working reliably.
I will be putting in 0.1uF capacitors on VIN for high frequency AC noise.
The case of the Arduino is now gonna be 3D printed and will be inlaid with aluminium foil.
I think that should do the trick.
Interesting though is, one ballast is clearly worse than the other.
(Might be a different batch, as they are the same)
If I learned one thing in this endeavour, I will be paying much attention to electronics in my third semester
Thank you all.
EDIT:
It still does it sometimes. I also posted it in the german forum, as my technical english is not as good.
Thank you all anyways.
Ill let you know if it worked out at some point.