battVolts = analogReading * 0.0032 * dividerRatio;
This circuit divides your battery voltage through a 1Meg and 470K ratio. So your Moteino analog pin sees [470k/(1000k+470k)] of your battery voltage, or ~0.32 of it. This would allow a max range of 10.31v before the analog pin sees 3.3v and maxes out the 10bit analog range. For instance a hypothetical 5V battery would divide to 1.6v into the analog pin, which will give a reading of about (1024 * 1.6v/3.3v) ~= 496 from analogRead(batteryMonitorPin).
So to get the actual voltage of your battery you have to multiply the analog reading to 0.0032 (=3.3v / 1024, ie 10bits resolution of analog reads). This gives you the voltage at the divider point, or the 1.6v in the hypothetical example of the 5V battery. Then you multiply that result to the inverse of the ratio of the divider (1/0.32), to arrive at the input voltage of 5V:
1.6v =====> 32% (at dividing point)
X =====> 100% (at input point/battery)
So solving X = 1.6 * 100/32 = ~5V as expected :)
The division by 10 in the code shown is just an average of 10 analog samples (to even out any differences in analog reads).
The code you pasted is not using the same ratio since 1/0.32 != 1.42, that was probably more like a 1Meg:2Meg ratio. So each resistor divider ratio will have that third term different, you will have to determine that from your resistors:Code: [Select]battVolts = analogReading * 0.0032 * dividerRatio;
The details of this post all make perfect sense, a simple circuit we should all become familiar with. But I'm wondering - since this is in the Low Power Techniques category - Has anyone done measurements on what attaching a circuit of this nature does to the battery life?It depends on the battery voltage and the threshold of the max voltage you want to measure.
At what size of resistor combination does the current draw become negligible and therefore useful to implement in ultra low power applications?
I think in general use a 1MEG:2MEG division plus a 0.1uF will give good stable readings while keeping a low drain current. If you want a zero drain current then add a mosfet to only enable the circuit for a few microseconds while you do your reading.
Could an NPN transistor (2N3904 ) be used to turn the circuit on/off? Much like was done in the original Mail Box notifier that used an NPN transistor to turn on/off the hall effect sensor.
The NPN is only needed if you want to drive your load from an active HIGH logic. Otherwise you can directly do it from a digital pin with inverted logic (p-fet is active low). It's a bit less intuitive and the pin has to be left HIGH-z (arduino pin set to INPUT, and write HIGH to it to turn the pfet switch OFF).
But yeah otherwise use a NPN to drive it just as any other active high load.