loop counter for (viod loop)

Hello guys
Sort of quick explanation :slight_smile: on what I’m trying to accomplish.
I made a solar panel and solar tracking stand. I have the sun tracking portion working fine in Arduino and working on the charging portion of the program.
“Deba168” created a nice instructable on building a charging system controlled by Arduino and I followed his schematic and program “attached” then modified his program to work for my setup.
There is one problem I’m trying to solve i’m not sure Deba168 accounted for.

If you look in the schematic you will notice voltage check is done through resistor net work for battery and solar voltage with a circuit disconnect between the two via mosfet to start/stop charge.

As long as the mosfet is not turned on “set HIGH” the battery and solar voltage readings are correct. Once the battery goes below full charge set point and solar panel output is above battery voltage, the mosfet turns on and charging begins.

The program constantly samples battery charge and solar voltages for charge status or if solar is no longer charging. “sun down”

The problem is… the reading for battery and solar are the same as the highest voltage in the circuit as long as the mosfet is turned on.
So… monitoring the “actual” battery voltage in the current program is useless while charging.

My thought was to suspend the battery check for a few minutes at a time, then turn the mosfet off for half a sec to check the battery then return to charge mode if needed.

Can anyone think of a programmable way to turn the mosfet off every few minutes to check the battery with out interrupting the main program?
I’m not advanced enough in programing to come up with it, if you could point me to example I could read, I would be happy to work this out by learning.
Thank you in advance.


Solar_charge_controller-v2.ino (16 KB)

Can anyone think of a programmable way to turn the mosfet off every few minutes to check the battery with out interrupting the main program?

See the Blink Without Delay example. It blinks an LED every so often. But if you replace the blinky code with what you want to do every so often then...

Basically all it does is check to see how long since the last time you did something and if it has been longer than some set time then it takes an action. Sound like exactly what you want.

Thank you Delta_G for responding.

I absolutely will look at that and try to relate it to my project.

I also wanted to say I looked again at the schematic and found another diode on the other side of the mosfet but before the resistor net work made the temps read separate as they should, even while charging. So I don't need to fix through programing but going to try it any ways just to learn how!
Thanks again

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.