voltage measurement error


Yes battery measurement on a solar and wind charged nickel/iron battery pack. In the end I am looking to have low voltage disconnects that disconnect certain loads when a minimum voltage (~11.8V-11.5V in priority succession) is reached for a period of time like 5 minutes and then reconnected when battery voltage reaches 12.0-12.3V in reverse succession. I.E. least important load disconnects first and reconnects last and most important load disconnects last and reconnects first.

Second part is to turn on dump loads when battery voltage reaches 16.5V for 5 minutes and disconnect them when battery voltage gets down to 15V for 5 minutes. I will probably have several loads in case some get satisfied and I still have additional power to dissipate. The first dump load will be a power inverter that will run stuff in my house. I have made outlet boxes that switch between grid power and inverter power automatically whenever the inverter comes on. System works great when I am there to monitor the system and turn things on and off but I am looking to automate "myself" so it will function while I am at work.

I already have made a board with 8 tiny relays driven by the arduino connected with a ribbon cable. I will connect to this board either directly the inverter which has a logic remote on/off function or other things through appropriately sized relays driven by the relay board.


Have you measured your 5V pin on the Arduino to see what the 5V supply really is?

Thanks.. Tom.. :slight_smile:


Not yet but I will tonight. I kind of thought the regulator would get that right but now I have doubts. I am probably going to put a 7809 regulator on my shield board to feed the arduino from the battery so I don't overload the on board 5V regulator. I have heard it has trouble dissipating the power when fed with higher voltages and tends to thermal out to protect itself and then turn back on when the temp drops and cycle like that continuously.


There have been some minor equipment changes since this was taken but here is the rig to be controlled.

I am probably going to put a 7809 regulator on my shield board to feed the arduino from the battery so I don't overload the on board 5V regulator.

Probably not a good idea to use a negative voltage regulator. I think you mean 7809.

Better to use a micro-power 5volt switching regulator like this one, and feed that 5volt into the 5volt pin.
Twice as efficient as the linear regulation you're suggesting.

$1 clones on ebay.

The sketch I posted does not rely on Arduino's supply.

Nice setup.
You should measure individual cell voltage in battery stack like that.
Cell voltage too low/high is more important than stack voltage.

Done something like this with "flying capacitors" and small relays.

Picture in post 49.

Tolerances .

Resistors - according to the quality : +/- 10, 5, 2 , 1, 0.1 % etc - you gets what you pays for.

Reference voltage..... as above. The arduino's 1.1v isn't very good.

a/d ... not perfect.

Temperature coefficients? How stable are all the above? .... how many ppm/C?

And variance over time - ageing?

how accurate do you want to be ? ( or pay for)

there are solutions. But not cheap.


A single cell nickel/iron (~1.65volt) battery, could be measured with flying caps and an Arduino with 2.5volt Aref (or external Aref and/or A/D) with <2.5mV resolution, without even using a resistor devider.

If the Arduino's voltage reference for A-to-D (or D-to-A) isn't quite right, then would the lower voltages be slightly off as well? The OP has the 'lower' voltages measuring to be about right, while the highest voltages are kind of out/wrong.

So the input range is not actually 0-5V as the spec says?

See what happens if you use a AC/DC adapter supply with 8 to 9 V DC going into the arduino's DC jack.

OK so the problem is I am an idiot. Power supply wasn't putting out what it said it should. Grabbed another out of the wallwart box and all is OK. Damnit. The only thing I DIDN'T take a meter to. Don't know why. I never trust anything.

Thanks Leo. They are 1.2V cells. I would like to monitor cell voltage but I have bigger fish to fry right now. I need to be using power instead of having the charge controller choke down the panels because the batteries are full. I also need to get the low voltage disconnect functions going so I don't have to put up with the ones I have now, which are hardware, shutting down because there was a nanosecond long spike to 11.5 volts because the fridge kicked on. I need that time buffer working.

Thanks to everyone for all your help and suggestions.

So I am back with a programming question.
Since the hardware is now performing as expected I am programming the system.
Low voltage disconnect programming operates as expected. On at 12+- and off when below 11.8-11.6v for x time (10 seconds for now but will be 5 minutes when done) depending on which of the 3 loads it is. Perfect.

Dump Load is another story. I am using 2 relays for this. Inverter on/off relay and a connect relay. I want the inverter to be on for some period of time like 20 seconds before I close a large relay to connect the load.

I basically want to do something like If inverter relay (#7) is HIGH and connect relay (#8) is LOW then time for 20 seconds and turn relay 8 on.

How do I read the state of a relay and use it to make this decision?

At some point in the future I will want to monitor the current of 3 current shunts I have in the system. These shunts provide 75mv at 200A. I am assuming I will need to apply some kind of op amp circuit.


The Arduino should know the state that the relay. Add a state variable.

if (some condition is met) {
relay1State = HIGH;
relay1Pin = HIGH;

If battery voltage is less than 26volt (max), use an INA219 breakout board.

Connect the 0.1ohm onboard shunt across the 200A (high-side) shunt.
An INA219 measures voltage and current with an onboard 12-bit A/D.
Four I2C addresses, so up to four boards use only two Arduino pins.


I am sure the arduino knows the state of the relay. I want to make a decision based on the state of some relays.

if (some condition is met " relay 7 is high and relay 8 is low") check enough time has gone by ( I can do this now)

Set relay 8 high

How do I import the state of relays to use in my decision making process?


If you're the one controlling them, you should just be able to do a digitalRead() on the pins you're interested in.

if (millistimehaspassed && relay1State == HIGH) { // if all conditions are met
digitalWrite (pinSomething, HIGH);

Grumpy_Mike (member of this forum) has a write-up about a state machine here:

Both of you thanks.
Ah relay1state == HIGH. figures.
I figured out the == HIGH part but couldn't find the relay1state. Tried relay1 == HIGH, relaystate1 == HIGH. All kinds of variations.

So the && is the same as "and" so like

if(blabla && (is the same as and) blabla2 && blabla3) then
do my thing here

I will try this when I get back home later this week.


So the && is the same as "and" so like

Look at "Comparison Operators" and "Bitwise Operators" in the Learning>Reference section of this site.

You can have more than two conditions between the brackets, or cascade multiple if statements.