Go Down

### Topic: Voltage Divider (Read 4273 times)previous topic - next topic

#### aarg

#30
##### Sep 18, 2015, 09:47 pmLast Edit: Sep 18, 2015, 10:02 pm by aarg
The purpose of this is to measure voltage and current from a 9V battery and the percentage of power remaining in the battery.
Well, how did you end up using 10k resistors? That won't load the battery very much. A weak battery will still show almost full voltage with that.

Also, to measure the remaining power, you must employ some mathematical battery model based on the voltage and current. The voltage is a function of current. So varying the voltage and current will not get you a single reading, it will give you a function (a curve). You can't do that with a simple voltage divider. You have to have a current sink, vary the current, and measure the resultant voltage.

That would give you a very good picture of the battery's health (you would still need a profile for the battery, because types differ).

On the other hand, a simple battery tester approximates those readings by choosing a point along the curve, using a fixed current sink (a resistor). So your talk about measuring the current is a huge "red herring" (irrelevant fact considered to be of paramount importance).

You really need to process this concept before you go on. If you really expect to measure battery capacity with 12 bit accuracy, the simple resistive divider will be a complete failure. In fact, even the first method can't be that accurate.

Also, there is some confusion in this thread about battery life. Are you considering making periodic measurements, or one measurement, or continuous measurement? Because the measuring device is measuring its own battery, then current consumption will be an issue. If not, then not really.

Perhaps I should have asked you for details of the implementation, rather than the purpose.
... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

#### dwightthinker

#31
##### Sep 18, 2015, 10:18 pm
You might look into an analog switch method or even
a relay to do periodic sampling.
As an analog switch, you could use a P-channel mosfet
with its source on the 9V and the drain on the divider.
Put a 10K resistor from 9V to the gate.
Add a npn transistor from the gate to ground ( collector to gate ).
Put a 10K from a digital output port to the transistors base.
The transistor is just a level shifter.
Most P-channel mosfets have a low enough threshold that 7
volts should be enough to turn is on enough to keep it from
effecting a 10K or so divider, much.
7 volts is most likely the end of life of the battery, anyway.
Dwight

#### Wawa

#32
##### Sep 18, 2015, 11:18 pm
Do you have a sketch without Aref(a simpler one)?
Is this simple enough.
Don't expect it to be as accurate with default Aref.
Leo..
Code: [Select]
`// 10k resistor from A0 to ground, and 10k resistor from A0 to +battint value;float voltage; // converted to voltvoid setup() {  Serial.begin(9600);}//void loop() {  value = analogRead(A0); // read pin  voltage = value * 10.00 / 1024; // convert to volt // change 10.xx slightly to calibrate  // print to serial monitor  Serial.print("The battery is ");  Serial.print(voltage);  Serial.println(" volt");    delay(1000); // readout delay}`

#### SagarDev

#33
##### Sep 19, 2015, 10:35 am
But that Aref sketch shows an error in my IDE.
Shakespeare's pen is an Electronics Engineer's Soldering Iron...

#### Wawa

#34
##### Sep 19, 2015, 01:23 pm
But that Aref sketch shows an error in my IDE.
What is the error.
The sketch from post#25 and post#32 both compile without errors here.
Post a screenshot of the error.
Leo..

#### aarg

#35
##### Sep 19, 2015, 04:08 pm
What is the error.
The sketch from post#25 and post#32 both compile without errors here.
Post a screenshot of the error.
Leo..
Why a screenshot and not a dump? There is a huge button on the right hand side of the compile window, "Copy Error Message".
... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

#### SagarDev

#36
##### Sep 19, 2015, 06:16 pm
I compiled it and it shows-->

Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega ADK"

sketch_sep19a.ino: In function 'void setup()':
sketch_sep19a:13: error: 'INTERNAL' was not declared in this scope
'INTERNAL' was not declared in this scope

"Show verbose output during compilation"
enabled in File > Preferences.

Shakespeare's pen is an Electronics Engineer's Soldering Iron...

#### Wawa

#37
##### Sep 20, 2015, 12:39 am
A Mega has two internal references. 1.1volt and 2.56volt.

Change (INTERNAL) to (INTERNAL1V1) when you use a Mega.
Leo..

#### SagarDev

#38
##### Sep 20, 2015, 12:48 pm
Okay. How do I measure the percentage of power left?
Shakespeare's pen is an Electronics Engineer's Soldering Iron...

#### aarg

#39
##### Sep 20, 2015, 09:12 pm
Okay. How do I measure the percentage of power left?

... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

#### dwightthinker

#40
##### Sep 20, 2015, 10:10 pm
Okay. How do I measure the percentage of power left?

With an alkaline, you can't determine the percentage.
Do a search on the web for discharge curves of alkalines.
With a carbon/zink, the discharge voltage curve is relatively constant.
You can get an idea from voltage.
Many laptop batteries have a NVRAM of some type to keep the
history of how much current has been used and past response to
discharge or charge.
These are only estimates and can be as much as 50% off at times.
They are just numbers to make the user happy.
Dwight

#### Wawa

#41
##### Sep 20, 2015, 11:57 pm
AFAIK, coulomb counters are reasonably accurate, but they rely on the user to fully charge and discharge the battery.
The counter could loose track of the charge with infrequent use (self-discharge) and top-up charges.
Leo..

#### dwightthinker

#42
##### Sep 21, 2015, 02:24 am
AFAIK, coulomb counters are reasonably accurate, but they rely on the user to fully charge and discharge the battery.
The counter could loose track of the charge with infrequent use (self-discharge) and top-up charges.
Leo..

Yep! Still more useful than trying to look at the voltage of an alkaline
battery. Their curve is almost flat until near the end of life then they
drop like a rock.
Not too useful to tell a person when to make plans to change the battery.
You can still give a warning that the battery is failing.
You can use a discharge curve but realize, that is with a constant current
load. If the load is changing or you turn the unit on or off without saving
some history, you won't be getting many useful readings.
Most rechargeable types of batteries also have a flat discharge curve.
Dwight

#### raschemmel

#43
##### Sep 21, 2015, 11:12 pmLast Edit: Sep 21, 2015, 11:12 pm by raschemmel
This is an awfully long thread for a "Voltage Divider". Has anyone mentioned Ohm's Law yet ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#44
Quote