Computing stuff tied to the physical world

Battery level on JeeNode USB

In Hardware on Mar 26, 2010 at 00:01

The new JeeNode USB v3 includes a resistor divider to track the voltage level before the voltage regulator. This signal is connected to the otherwise-unused A6 input of the ATmega328 SMD chip.

Here’s a little sketch to see what it does:

Screen shot 2010-03-24 at 01.02.16.png

In prose: read out analog pin 6 once a second, and broadcast the measured value as wireless data packet on netgroup 2. The readings are also sent to the serial port.

Since a 1:2 voltage divider is used, the full-scale of the ADC (i.e. 3.3V in) is 6.6V, a value which can never be reached on the JeeNode USB. The map() function is used to scale this back to an integer in the range 0..660, i.e. hundredths of a volt.

Here is the serial output while connected:

Screen shot 2010-03-24 at 01.04.19.png

This is exactly as expected: the LiPo charger outputs 4.2 Volt when no battery is connected, which then goes into the on-board voltage regulator.

Here’s the serial output when a fully charged LiPo battery is connected (still plugged into USB):

Screen shot 2010-03-24 at 01.04.36.png

Again as expected: the battery pulls down the voltage slightly to 4.17 Volt.

But the interesting bit of course is when unplugging the USB cable. That’s why the RF part was included in this example: we can’t use the serial port anymore, and have to pick up the packets with a second JeeNode or JeeLink.

Sample output:

Screen shot 2010-03-24 at 00.52.51.png

That’s two bytes in each packet, forming a little-endian 16-bit int. The corresponding value is 161 + 256 * 1 = 417. The battery is still charged, so we’re still getting the same 4.17 Volt readout.

By leaving this sketch running on the LiPo battery for a while, it will slowly discharge. Output after one hour:

Screen shot 2010-03-24 at 01.27.15.png

Not much difference: 4.16 Volt.

Here’s a different LiPo battery which has been lying around unused for several months:

Screen shot 2010-03-24 at 01.24.23.png

Still a very respectable 126 + 256 * 1, i.e. 3.82 Volt!

So there you go. The node can run off a LiPo battery, and track its charge state. This could be used to power down the node when the voltage becomes critically low – perhaps 3V or so. LiPo’s don’t like being run down completely, and this is how a node can avoid doing so.

You may be wondering why the voltage readings were not immediately stable on startup, as seen in the first two output screens. Even if restarted, this same behavior will be observed, i.e. even if there was no power dip.

I think this is due to the fact that two very high impedance 1 MΩ resistors are being used for the voltage divider. These cannot supply a lot of current, which means the input charge for the ADC’s sample-and-hold isn’t being built up quickly enough. This will probably happen each time the ADC is switched over from another channel.

But there is a good reason for this: with 1 MΩ resistors, the leakage from this voltage divider is only 2 µA. For a battery-powered application, where every constant current drain affects its total lifetime, this matters.

  1. this way the node could also report that it needs “juice” before it’s actually shutting itself down.

    nice work

  2. If you have another spare port pin, you could use that as a low-side switch for the voltage divider. This would extend the battery life time even when using much smaller resistor values to increase stability and noise immunity.

    BTW, I think the AVR manuals say somewhere that the first ADC readout after switching channels should always be descarded.

  3. Once the battery level drops, what kind of circuit does one use to shut off the battery ?

    • Just put the ATmega in power off state, and stop waking up periodically. The remaining power draw will be in the order of a few microamps, and won’t drain the battery any further.

  4. Awesome. THX for the replay. What about an external sensor or something like a GPS ?

  5. Awesome, great you added this feature

  6. Not sure if this is the right place to be asking, but do you have a rough estimate of battery life for regular (non-usb) battery-powered JeeNodes? Say from regular AA cells? I’m considering using some for a project, but the nodes need to be active for a month. I imagine lipo’s would be better for such an application but I’d like to avoid those if possible (due to cost/charging) since its feasible to run wired power to the nodes (though I’d love to reduce wiring if possible).

    Thanks in advance!

  7. Looking forward to the JeeNodeV5 with Lipo charger and battery level resistor divider. Will buy ten as soon as available.

    • Heh :) – but the LiPo charger chip is SMD, so I don’t see how I can make that happen on a JeeNode, which is 100% through-hole parts …

Comments are closed.