# How to detect how much battery power is drawn?

I'm programming a small device using a microcontroller. I'd like to optimize it to use less battery. How can I detect how much power uses over time as I run it through some tests? Based on the tests I can optimize the code to use less battery life.

If I can't get an amount of power used over time, then what's the easiest way to see if the sleep is really working and if it is using any power at all?

In laymen's (or at least programmer) terms please! I'm definitely heavier on the software side of things.

At least what pins do I connect the voltage meter too. Sorry for noobiness.

I would measure current:

• Remove the red lead from the multimeter
• Set the multimeter to milliamps
• Plug the red lead into the milliamps socket
• Disconnect the power from VCC of the microcontroller (which may be multiple pins)
• Connect the multimeter probes in series with the power source and the VCC pin(s).

If the sleep state is very low current I would turn the range switch to microamps range (if the meter has one).

To measure current, you need a multimeter (technically just an ammeter). Some bench multimeters have a graphing or datalogging function which allow you to connect a device and let it run for a while and examine measured values later.

The basic current measurement involves inserting the meter in the circuit in a series connection: simulate this circuit – Schematic created using CircuitLab

This provides a measurement of the current draw of the device in real time. But if you're interested in knowing the long-term power consumption, you need to record the current draw at regular intervals and average it out.

For example, if you want to know how much power your refrigerator uses, you have to measure its current draw (using a Kill-a-Watt meter, for example) when the compressor is running, again when it is off, and then figure out how long the compressor runs versus how long it is idle. It gets more complicated because these durations will vary based on the ambient temperature of your house, etc.

If you don't have a datalogging multimeter, you can take measurements from various behaviors of your device and determine the time that each behavior or state is active. For example, if your device sleeps for 59 minutes, wakes up for one minute to do something, then you can take two measurements and calculate based on a 59:1 ratio. For example, if the device draws 2mA while sleeping and 10mA while working, you would have ($59 * 2 + 10 * 1$) 128 mAh.

For something that is more variable, you'll just have to take measurements at regular intervals and average it out.

• 128mAh, not mA/h. Mar 3, 2014 at 17:45