Arduino resets or behaves random when switching 220V

Hi there,

I'm working on this project for opening a lot of solenoids and to turn on/off lights.

When I'm testing, everything seems fine, but in production, the Arduino resets or even behave strangely by opening solenoids or starting the buzzer randomly.

I've noticed that It resets when I switch on and off the lights (fluorescent light, 12 of them, so a lot of spikes)

In Master.png is is my current design, and I'm planning to go to the one on Master-OPT.jpg

I've also attached the code that also works fine if not in production.

Can anyone advise, if there is something wrong with the schematics or code.

Are there any improvements that can be made in order to make this work?

Note, that the 24V is actualy 12V but from a different power source.

Best Regards,
Mircea

Lights_-_Delay.v2.ino (5.23 KB)

How do you supply the Arduino.
Leo..

buzzvertising:
Can anyone advise, if there is something wrong with the schematics or code.

This sounds like an unstable power supply. When you switch large loads, you're likely to disturb the Arduino's power supply if it draws power from the same supply as these loads. The 220V switches are also likely to produce EMC disturbances.

Try to add a ferrite bead right before the Arduino's power supply, and maybe add a large capacitor and a few decoupling capacitors as well. If that doesn't help, a different power supply may be necessary.

By the way, when you use NPN switches (such as the 4N35), you probably want the load to be between 12V and the collector. This has nothing to do with the reset problems though.

Looking at your schematic again, you seem to be powering several 4N35 LEDs simultaneously. I suspect you can't draw the amount of current from an Arduino that is required to light them all, so you may have to add transistor drivers for the 4N35 ICs as well. Or, you may be able to stay below the current limitations by using larger resistors for the LEDs. Even with resistor values several times that of your current choice, the LEDs can be expected to glow brightly enough to switch the phototransistors nonetheless.

Overloading the Arduino's outputs can lead to all kinds of erratic behavior, especially random resets.

Consult the datasheets for the 4N35 and the Arduino to find out if you're overloading its outputs.

Hi,
Can you post an image of your PCB please?
Are the relays mounted on the PCB with the Arduino?

Tom.... :slight_smile: