I'm running some Arduino clones on 3 AAA or 4 AA batteries using HT7333. I de-soldered the onboard regulators and feed the 3.3V directly to VCC of the µC.
To measure the voltage of the battery pack I could have used a simple voltage divider but that would draw current all the time. Hence, I'm using a pin of the µC and drive it active low to provide ground when needed, see attached (schematic top circuit).
Unfortunately, I measured more than the expected 3.3V of the HT7333 on the µC. It was something around 3.5V. Maybe it does have nothing to do with the way I measure the voltage and there is a mistake elsewhere.
However, is the bottom circuit a better solution to my problem or is there a better solution of some kind?
How do you read A0? What analog reference do you use? Show your sketch, please.
What does a multimeter at A0 say?
You may use a voltage divider with 1M/1M instead of 10k, you then need an additional capacitor (about 100n) at pin A0 but can get rid of the pull-down-pin at D3
Your way of measuring is correct, but there will be a voltage drop across the MOSFET, which you have to take into account. The MOSFET acts as a resistor with value Rds (check spec sheet for this). Multiply this resistance by the current and you can get the voltage drop across it. However, this should be really small since the resistance is usually less than 100 mOhm.
androidfanboy:
Multiply this resistance by the current and you can get the voltage drop across it. However, this should be really small since the resistance is usually less than 100 mOhm.
Thanks for the feedback. The dropout should be really low and negligible, Rds(on) is 0.130 Ohm and max current 10 mA.
One question to clarify, the upper circuit of my schematic, the one I used till now, does explain why I have higher voltage "behind" the voltage regulator and this is solved using the lower circuit?
Standard voltage reference, did not change it. The DMM reads half the voltage of the battery pack.
I thought that very high resistor pose a problem. I guess the additional capacitor solves it? The cap goes from A0 to GND?
The cap goes from A0 to GND, right. It keeps the voltage stable in the very short moment when A0 is connected to the internal S/H capacitor (of 14pF).
Where does the 3333.0 come from? your reference voltage is 3300 assuming a perfect voltage regulator. What does the multimeter say when connected to the AREF pin? You have a capacitor on the AREF pin, too, don't you?
BTW do not use float variables. analogRead returns an int, the other constants are ints as well. Just change the order of execution (first multiply, then divide). You may have intermediate results that are 32 bits wide, hence one cast to long is needed.
What are the tolerances on the 10k resistors? I always try to stick with 1% tolerance since they're usually not any more expensive than 5% tolerance. Also, how are you converting the voltage? Nick Gammon recommends to add 0.5 to the analogRead then divide by 1024:
olf2012:
Where does the 3333.0 come from? your reference voltage is 3300 assuming a perfect voltage regulator.
Oh, you are right. My fault.
olf2012:
What does the multimeter say when connected to the AREF pin? You have a capacitor on the AREF pin, too, don't you?
Actually, no, I don't use the AREF pin at all. Well, the Arduino ProMini clones I have do not provide a AREF pin. Funny I never noticed that. I looked up the pin on the atmega328p itself and measured it on the chip leg. It showed always the same voltage as on VCC.
olf2012:
BTW do not use float variables. analogRead returns an int, the other constants are ints as well. Just change the order of execution (first multiply, then divide). You may have intermediate results that are 32 bits wide, hence one cast to long is needed.
Thanks, didn't know that.
@androidfanboy
I've 5% smd resistor. Well, I measured resistance of several of them with my DMM and it always showed 9.99k. No idea what error margin my DMM has. It's over 25 years old and I don't have the manual anymore.
Thanks for the advice and reference to Nick Gammon but I don't need that extra precision. Just a curious hobbyist here
EDIT: Where is the limit for the resistors and how can I determine it? Say, would two 10MOhm also work? Sure, no need to push it but I've plenty 10MOhm resistors at hand
At this point I'm not really sure what else could be wrong with it besides the 3333mV. I think it's just ADC error. For example, I tried your first schematic on an ESP8266 board with 2k and 10k resistors and it read 4.73V instead of 4.96V (measured by multimeter). A lot of times I get values that are 5% off, and yours is about 6% off so that's not out of the ordinary.
Yea I think the best thing to do at this moment is just to measure the actual voltage with your multimeter and multiply a calibration constant (cal = V_meas / V_ADC)
terraduino:
EDIT: Where is the limit for the resistors and how can I determine it? Say, would two 10MOhm also work? Sure, no need to push it but I've plenty 10MOhm resistors at hand
Thanks all & best
10M should also work if you have the cap at A0. Just make sure the PCB is free of any soldering residue and moisture which would distort the resistor values
terraduino:
One question to clarify, the upper circuit of my schematic, the one I used till now, does explain why I have higher voltage "behind" the voltage regulator and this is solved using the lower circuit?
Yes, the upper circuit is BAD! When the divider is "off" there is (Vcc+Vbat)/2 on the analog pin. It is more than Vcc and so current flows through internal protection diode of the pin to the Vcc rail behind regulator. If this current is "large" (over hundreds of uA probably) it may damage the pin. If the current is higher than current draw of your application the regulator gets "out of regulation" and voltage grows: basicly all current is supplied via upper resistor of the divider (and the poor analog pin) and the resistor is only thing "regulating" voltage.
terraduino:
Thanks for the advice and reference to Nick Gammon but I don't need that extra precision.
You are lucky - Arduino is nowhere near such precision. The mentioned code is only wasting of the CPU time (and so power).
Second circuit is "equally bad".
Both circuits dump current from the top resistor (R7, R9) via the pin protection diode onto VCC when the ground connection is missing.
Circuit #1 could be better for measuring, since it uses a mosfet (in the MCU) to switch to ground.
This article explains how to measure VCC internally.
Leo..
Wawa:
Second circuit is "equally bad".
... This article explains how to measure VCC internally.
Leo..
You are right, both are bad! They are dangerous and may lead to the magic smoke one day.
...
I did not read the linked article carefully but I suspect it won't work: OP wants to measure (unregulated) voltage of battery by MCU powered from regulated supply.
@Smajdalf
Thanks for the explanation I love to learn about such things.
@Wawa
Actually, I'm using the cited method to measure the voltage applied to the µC. This gives me approx. 3300 mV coming from my voltage regulator to Vcc of the µC. But, in addition, my intention is to measure the unregulated voltage of the battery pack. In the end I have a value for regulated voltage and battery pack voltage.
Hence, I don't understand how the cited method gives any advantages over and above a voltage divider with, say, two 1MOhm resistors with the latter always connected to ground.
terraduino:
...Hence, I don't understand how the cited method gives any advantages over and above a voltage divider with, say, two 1MOhm resistors with the latter always connected to ground.
Should work well as a low battery detector.
When battery drops below "normal VCC + regulator dropout".
@Wawa
Nice, thanks, learned even more today.
Although I really like the referred idea, using both another MOSFET and another pin is not to appealing to me.
But great to know that this is a way to do it, link printed and archived.
Finally, I had time to build the 10MOhm+10MOhm voltage divider to measure the voltage of my battery packs.
I used 2 SMD 0805 "1005" resistors. Measured resistance 9.90 MOhm and 9.87 MOhm, respectively. As explained here I added a capacitor, 100nF SMD 0805, in parallel to the GND-analog pin resistor in approx. 2mm distance.
I attached a 4.02 battery pack (3 AAA) and my DMM showed 1.34 Volt. Ok? I tried a 2.70 Volt (2 AA) battery pack and DMM showed 0.90 Volt.
I build a second voltage divider on a second PCB with the same specs and components, respectively. Same result. The ratio of the voltage divider is exactly 1:3 instead of 1:2. Well, it's no big deal, right? Simply adjust the numbers in my sketch.
Anyways, I'm curious if this is a result of bad solder wire or bad contacts or whatever? Maybe it has something to do with the 100nF capacitor? Maybe it is not 100nF and, hence, explains the readings?
I'd be happy to understand what happened here.
Thanks & best