uno hangs on switching the relay

Hi im building a kind of "ATS" automatic transfer switch based on a battery voltage status and on the availability of 2 powersources... like

if bat < then minvolt switch to powersource 2
if bat >maxvolt (charged) switch to powersource 1

if no powersource1 swittch to power source2
if no powersource2 swittch to power source1

  • powersource1= inverter connected to the batteries 220v ac
    *powersouce2= generator 220v AC

I have :
a big dpdt (in fact 3) relay that can support 230v up to 40 amp that have a 24v coil
small 5v relay that i use to open or close the 24v circuit to the big relay...
voltage divider to sense battery voltage

Small ac/dc transformers (iphone type chargers) to sense both sources
i2c lcd that show some info on what is happening...
Lm2596 power converter to convert from 24v to 8v that go to the vin of arduino then from arduino 5v I'm powering the small relay and the lcd.

Problem: After some switches of the relay the Arduino hangs.... random some times after 2/3 switches some times after 50...

now if i take the lcd out it don't hang at least after 200 switches when i stopped the test ... if i disconnect the the big relay it also don't hang...

So its the big relay(with no 230v power presence) just by switching does any electric noise dirty that hangs the arduino ? some times it doesn't hang but the lcd gets strange characters ...

So do i need any decoupling capacitors , where ??? how can i troubleshoot this...

it only come back to life reseting the arduino....

Please advice..

Regards

If that schematic is correct, you are powering the relay and the LCD display from the Arduino +5v supply. That may be a bit too much for the linear regulator on the Arduino.

edit: Is the regulator on the Arduino getting hot? That could be a thermal shutdown.

I would not power any inductive device (like servos and relays) with the regulated +5v on the Arduino. The voltage sags and spikes can cause real trouble for digital devices.

It does sound like 2 things.

  1. not enough current?
  2. the voltage spikes produced from the magnetic fields of the coil may be causing you the issue.

Instead of using VIN, increase your voltage out to about 7.5volts on your regulator, feed it into the DC barrel jack, it will then regulate the voltage down to 5v also with it's smoothing capacitors there, you might just get away with it...

Thing with inverters and relays and generators, they create a lot of EMI noise, add a couple of caps, use an inductor, keep the power source to the Arduino as clean as possible..

To anyone else here, could optocouplers help?

SurferTim
my first desing was with the lm2596 in 5v mode (so no need to use arduino 5v regulator) and both lcd and small relay where getting power from it..
but was even worst the hangs where more frequent.....
I can try keeping the lm2596 at 8v->arduino vin and use 3 diode in series to reduce to 5v and from that power both smal relay and lcd...

cjdelphi:
all circuit is consuming 170mili amps so the lm2596 can give 3amps and the arduino can give this on its 5v pin, the strange is that only happen when the big relay is trigger and (not the small that is connected to the arduino) that is coming direct from the 24v battery
As far as i know the vin uses the uno regulator the diference for the barrel is the reverse diode protection.. and i'm doing that now with 8v to the arduino

where do you suggest caps ?

btw if i don't use pull up resistors for the sca & scl i2c lines the hangs are more frequent also

fca:
So its the big relay(with no 230v power presence) just by switching does any electric noise dirty that hangs the arduino ? some times it doesn't hang but the lcd gets strange characters ...

Put a diode in parallel with the coil of the big relay, right at the relay terminals, cathode to the positive side, anode to the negative side. Type 1N400x (where x = any of 1 thru 7) will do.

Put a diode in parallel with the coil of the big relay, right at the relay terminals, cathode to the positive side, anode to the negative side. Type 1N400x (where x = any of 1 thru 7) will do.

thanks a million that seem to solve it ..
(strange that making a pull-up to the lcd minimized at almost 100% the hangs), now i will leave it in my intensive test 500 relay actuations ..

Regards..