How long will your project run on batteries? To answer that question you need to understand the capacity of your batteries and the amount of current consumed by your project.
Battery capacity is measured in milliamp-hours (abbreviated as mAh) which are a measure of how many hours a battery can sustain a constant draw of current. For example an 800 mAh battery can in theory provide 800 mA of current for an hour. However, in reality as current draw increases battery capacity decreases. Look for a datasheet from your battery manufacturer to see what the capacity of your batteries are at various current draws. For more information on batteries and battery capacity, check out this battery guide.
With the battery capacity and average current consumption, you can compute the expected runtime of your project by solving the equation:
Battery capacity (in mAh) / Average current consumption (in mA) = Hours of expected runtime
For example if your project consumes 150 mA and your batteries are rated at 800 mAh at that current draw, you can can compute:
800 mAh / 150 mA = 5.33 hours expected runtime
For simple projects with a fairly constant current draw, a multimeter might be all you need to measure average current consumption. If you aren't familiar with how to use a multimeter to measure current, take a look at this multimeter guide for a great overview.
For more complex projects which have changing current demands, like this project, you'll want to measure current consumption over time. Using a series of current measurements you can compute an accurate estimate of average current consumption.
A great way to measure current over time is using this INA219-based current sensor breakout. If you aren't familiar with the INA219, be sure to read the guide on it's usage. The INA219 can be attached directly in series with the power input of your project and queried over an I2C interface to read current consumption. Using a device that can speak I2C, such as an Arduino, Raspberry Pi, or Beaglebone Black, you can record the current consumption of your project over time.
For this project I used an Arduino Yun connected to the INA219 breakout to log current consumption. A sketch running on the Yun talks to the INA219 and uses the Yun bridge library's Console class to send data to my computer over my WiFi network. A simple Python script runs on my computer to periodically record current measurements from the Yun.
The Yun is not very good at being a low-power device since its running Linux! For that reason we're using it just for tracking the power usage of our CC3000 setup
- The Yun_INA219_Datalogger subdirectory is the Arduino sketch that should be loaded on the Yun hardware.
- The Scripts/yun_ina219_datalogger.py file is the Python code to record measurements from the INA219 datalogger.