Arduino Resetting with Relay

im currently making a project that needs to be online/running as much as possible. its a self sustaining system.

in the system we have 2 batteries, the system will monitor the State of charge of the two batteries. either of the two batteries can be charge and discharge at the same time.

for example. the arduino is currently using battery1 while battery 2 is currently charging. when the arduino detects the battery is about to deplete, the arduino will switch the relay to the other battery. also, i'm starting to test the switching but there's a millisecond that the arduino and the relay will reset/shut down causing the code to reset too and will go back to the battery1 and sometime stuck

Now.
is there any module that can read the state of charge of a battery?
any circuit or anything that can fill the gap when switching the relay to prevent the resetting/shutting down of the arduino and relay?

Thanks in advance. :smiley:

How do you control the relay? Using a snubber (diode…)? And a big enough capacitor to bridge the gap?
Please show your circuit diagram.

The relay will drain the battery more than the Arduino does, I guess.

How do you control the relay?

the relay is a 5v DC, i control the relay using the Digital pin of the arduino.

Using a snubber (diode…)? And a big enough capacitor to bridge the gap?

i thought the snubber is for AC, how big is the capacitor? can capacitor really fill the gap?

The relay will drain the battery more than the Arduino does, I guess.

is that so? do you have any alternatives for switching the batteries?

Capture.PNG

the first battery(default battery to be used in arduino) is connected to normally closed of the relay while the 2nd battery is connected to the normally open of the relay. both negative of the batteries are connected in the common of the relay. in the arduino side. the negative source of the arduino is connected in the common of the relay, while the positive is connected in both positive of the two source.

Why two batteries, instead of a single battery connected to your power source, that in turn powers the Arduino?

That’s the more usual arrangement, and very commonly used in e.g. solar power applications. No need for a relay, switching over, etc. If the power goes out, the battery supplies power to the Arduino, when the power is back the battery gets charged again.

Just make sure your battery is big enough to bridge the longest supply outage you expect (or want to bridge).

I wonder how much current the relay draws, an Arduino pin should not source more than 20mA.

A snubber is required for all inductive loads, else powerful spikes on the supply can damage other components and reset the controller.

The capacitor size depends on the total current and relay switching time. 100µF to 1000µF may be sufficient.

Usually Gnd is common and Vcc is switched.

wvmarle:
Why two batteries, instead of a single battery connected to your power source, that in turn powers the Arduino?

That's the more usual arrangement, and very commonly used in e.g. solar power applications. No need for a relay, switching over, etc. If the power goes out, the battery supplies power to the Arduino, when the power is back the battery gets charged again.

Just make sure your battery is big enough to bridge the longest supply outage you expect (or want to bridge).

as i've stated, we want the system to be online(IoT project)/running as much as possible. I'm sorry i forgot to mention that we're using Piezo elements for the power source (yes it has a low output power) that's why we assume that it will take hours, days to charge a battery and the rate of consumption of the charge of the battery is faster than the rate of charging of the battery. That's why we come up with the idea to use a two switching batteries.

DrDiettrich:
I wonder how much current the relay draws, an Arduino pin should not source more than 20mA.

A snubber is required for all inductive loads, else powerful spikes on the supply can damage other components and reset the controller.

The capacitor size depends on the total current and relay switching time. 100µF to 1000µF may be sufficient.

Usually Gnd is common and Vcc is switched.

i dont have any Digital multimeter on hand yet. I'm gonna check it as soon as i buy one.
we dont have any high loads. we'll just use those relay for switching batteries.
okay noted. where should i connect the capacitor before or after it connects to the relay?

Do you have any ideas how we can read the battery percentage (state of charge)?

after we read/detects the battery percentage, we will display it on a website. Also, the switching is based on the percentage of the battery

So you plan to remove the battery that’s not used and charge it from another source? It sounds like you produce less power than you use from those piezos, so sooner or later you will run out of battery regardless of how many you have. A relay is pretty power hungry as well.

Battery percentage is tough. By measuring the output voltage you can tell full, medium and low. To get to a more or less accurate percentage (like your phone does) you have to continuously measure the actual current taken, and calculate how much charge was taken from the battery, and with it how much charge is left.

I think that you should understand electricity a bit better.

Two batteries are required only if the charger can not both charge a battery (current and voltage controlled) with a load permanently attached.

If two batteries are used with a solar panel, both batteries must be loaded during daylight, with the load being powered as well. At night first one battery is drained, then the other one.

Using transistors will allow to switch batteries without spending much energy and without a drop out while switching.

Charging procedures and charge state determination depends on the battery type. Learn more about battery types before selecting a specific type, or learn more about your favorite battery type chargers.