
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>Denis Hennessy</title>
  <meta name="author" content="Denis Hennessy">

  
  <meta name="description" content="I needed a couple of AA batteries and found the display at the supermarket where they were
all arrayed. Normally when I&#8217;m shopping in the &hellip;">
  

  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  <link rel="canonical" href="http://denishennessy.com">
  <link href="/favicon.png" rel="icon">
  <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  <script src="/javascripts/modernizr-2.0.js"></script>
  <script src="/javascripts/ender.js"></script>
  <script src="/javascripts/octopress.js" type="text/javascript"></script>
  <link href="/atom.xml" rel="alternate" title="Denis Hennessy" type="application/atom+xml">
  <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">

  
  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-1895212-16']);
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>


</head>

<body   >
  <header role="banner"><hgroup>
  <h1><a href="/">Denis Hennessy</a></h1>
  
    <h2>Nothing to see here. Move along.</h2>
  
</hgroup>

</header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
  
</ul>
  
<form action="http://google.com/search" method="get">
  <fieldset role="search">
    <input type="hidden" name="q" value="site:denishennessy.com" />
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
  
<ul class="main-navigation">
  <li><a href="/">Blog</a></li>
  <li><a href="/blog/archives">Archives</a></li>
</ul>

</nav>
  <div id="main">
    <div id="content">
      <div class="blog-index">
  
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/2012/04/08/measuring-battery-capacity-with-an-arduino/">Measuring Battery Capacity With an Arduino</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2012-04-08T22:25:00+01:00" pubdate data-updated="true">Apr 8<span>th</span>, 2012</time>
        
      </p>
    
  </header>


  <div class="entry-content"><p>I needed a couple of AA batteries and found the display at the supermarket where they were
all arrayed. Normally when I&#8217;m shopping in the supermarket, I tend to look at the price/kg
or price/l when comparing similar products. In the case of the batteries, there was no such
indicator. Fine, I thought, I&#8217;ll work it out myself. I grabbed a few different makes and
scanned the packaging for some measure of their capacity.  Nothing. Not a single one of
the batteries had any indicator of how much energy they would provide. Instead, they all
had terms like &#8216;PLUS&#8217;, &#8216;SUPER&#8217;, &#8216;ULTRA&#8217; and of course had wildly differing prices. So, I
decided that it was time for an experiment and bought one pack of every type I could find.
<img src="/images/bat_batteries.png"></p>

<h2>The Plan</h2>

<p><img class="right" src="/images/bat_front.png">
My idea was really simple: I would make a circuit that would fully discharge each of the
batteries while measuring how much energy it produced (displayed in Joules and in
Watt-Hours. I had an Arduino and an LCD panel left over from a different project so I
thought I&#8217;d make a standalone unit. As the design evolved, I let two additional features
creep in:</p>

<ol>
<li>Add a temperature sensor to track ambient temperature during the test since that certainly
affects battery capacity.</li>
<li>Add a USB logging capability so that I could capture all the data to plot terminal voltage
as the battery discharges.</li>
</ol>


<p>Note: This was never intended to be a scientific instrument to measure how long a battery
would power your circuit - it&#8217;s designed to provide a relative comparison of different
batteries using a similar load.</p>

<h2>The Design</h2>

<p>The circuit works by measuring the voltage across a fixed load every second until the
voltage drops to less than 0.2V. For simplicity, I used a resistive load (the original
plan was to use a 4.7R resistor but I didn&#8217;t have any high power resistors to hand so I
used 4 22R resistors in parallel instead giving me an effective load of 5.5R. Here&#8217;s the
final circuit:
<img src="/images/bat_schematic.png">
<a href="http://www.adafruit.com/products/271">This case</a> from adafruit ended up being perfect
because it already has cutouts and standoffs for the arduino and the LCD. All that was left
was to add a little bit of stripboard to hold the extra components. Note that the whole
circuit is powered from the USB connection (or the DC jack) - all the power from the battery
is consumed by the load resistors.
<img src="/images/bat_inside_case.png"></p>

<h2>The Software</h2>

<p>When the unit resets, it waits until a battery is connected before starting any measurements.
Once it detects a battery, it measures the temperature and voltage once a second and displays
the cumulative energy in Joules and Watt-Hours on the display.
<img src="/images/bat_display.png">
It also logs the readings to the USB port once per second. You can capture these to a text
file with any terminal emulator but I found the easiest thing to do was to use screen:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>screen -L /dev/tty.usbmodemfd131 9600
</span></code></pre></td></tr></table></div></figure>


<p>Once the voltage drops below 0.2V, it will stop measuring and display the total energy
produced. If you&#8217;re using screen to capture the data, quit it with ^A ^K and rename the
logfile to something more memorable:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mv screenlog.0 duracell-simply.csv
</span></code></pre></td></tr></table></div></figure>


<p>The CSV file has a line for every second of the test. For graphing, it&#8217;s easier to make
a version of the file with an entry sampled every minute:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>awk <span class="s1">&#39;NR % 60 == 1&#39;</span> duracell-simply.csv &gt; duracell-simply-mins.csv
</span></code></pre></td></tr></table></div></figure>


<h2>The Results</h2>

<p>So far, I&#8217;ve captured the data from 10 brands of alkaline battery. In each case, I took
1 battery from the pack and measured its capacity. Obviously, it would be better to take
a selection of each and average the results but I didn&#8217;t want to waste all my batteries
on the test.</p>

<p><img src="/images/bat_graph.png"></p>

<p>In most cases, I bought the batteries in packs of 4. It&#8217;s interesting to take the cost of
each battery (pack cost / pack size) and combine that with the measured capacity:</p>

<p><img src="/images/bat_grid.png"></p>

<p>This lets us compare each of the batteries in terms of the cost per Watt-Hour (which is
really all you should care about when buying them). Obviously, lower is better:</p>

<p><img src="/images/bat_summary.png"></p>

<p>There&#8217;s a difference of over 9X between the best value (RS Power Ultra) and the worst
value (Panasonic Evolta).</p>

<p>I&#8217;ve posted the schematic, source code and results files on
<a href="https://github.com/dhennessy/BatteryCapacityTester">GitHub</a>. If you build one,
please share your results&#8230;</p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/2012/04/06/blog-reboot/">Blog Reboot</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2012-04-06T20:47:00+01:00" pubdate data-updated="true">Apr 6<span>th</span>, 2012</time>
        
      </p>
    
  </header>


  <div class="entry-content"><p>My old personal blog had been a bit neglected, especially since I did most of the
software-related posts on my <a href="http://www.peerassembly.com/blog.html">work blog</a>. That blog
is probably going to continue to get the majority of my blogging energy (such as it is)
but I thought it might be interesting to have a place to post about non-software topics as
well.</p>

<p>This kitten has absolutely nothing to do with the blog but I read somewhere that people
are 43.5% more likely to bookmark a site with a cute picture.
<img src="http://placekitten.com/890/280">
Image courtesy of <a href="http://placekitten.com">Place Kitten</a></p>
</div>
  
  


    </article>
  
  <div class="pagination">
    
    <a href="/blog/archives">Blog Archives</a>
    
  </div>
</div>
<aside class="sidebar">
  
    <section>
  <h1>Recent Posts</h1>
  <ul id="recent_posts">
    
      <li class="post">
        <a href="/2012/04/08/measuring-battery-capacity-with-an-arduino/">Measuring Battery Capacity with an Arduino</a>
      </li>
    
      <li class="post">
        <a href="/2012/04/06/blog-reboot/">Blog Reboot</a>
      </li>
    
  </ul>
</section>
<section>
  <h1>My Work</h1>
  <p>I develop iPhone and iPad applications at 
  <a href="http://www.peerassembly.com">Peer Assembly</a>. 
  You can see some of my work <a href="http://www.peerassembly.com/portfolio.html">here</a>.
  The best way to contact me is by <a href="mailto:denis@peerassembly.com">email</a>.
</section>

<section>
  <h1>GitHub Repos</h1>
  <ul id="gh_repos">
    <li class="loading">Status updating&#8230;</li>
  </ul>
  
  <a href="https://github.com/dhennessy">@dhennessy</a> on GitHub
  
  <script type="text/javascript">
    $.domReady(function(){
        if (!window.jXHR){
            var jxhr = document.createElement('script');
            jxhr.type = 'text/javascript';
            jxhr.src = '/javascripts/libs/jXHR.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(jxhr, s);
        }

        github.showRepos({
            user: 'dhennessy',
            count: 0,
            skip_forks: true,
            target: '#gh_repos'
        });
    });
  </script>
  <script src="/javascripts/github.js" type="text/javascript"> </script>
</section>


<section>
  <h1>Latest Tweets</h1>
  <ul id="tweets">
    <li class="loading">Status updating&#8230;</li>
  </ul>
  <script type="text/javascript">
    $.domReady(function(){
      getTwitterFeed("denishennessy", 4, false);
    });
  </script>
  <script src="/javascripts/twitter.js" type="text/javascript"> </script>
  
    <a href="http://twitter.com/denishennessy" class="twitter-follow-button" data-show-count="false">Follow @denishennessy</a>
  
</section>





  
</aside>

    </div>
  </div>
  <footer role="contentinfo"><p>
  Copyright &copy; 2012 - Denis Hennessy -
  <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>

</footer>
  

<script type="text/javascript">
      var disqus_shortname = 'denishennessy';
      
        
        var disqus_script = 'count.js';
      
    (function () {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    }());
</script>







  <script type="text/javascript">
    (function(){
      var twitterWidgets = document.createElement('script');
      twitterWidgets.type = 'text/javascript';
      twitterWidgets.async = true;
      twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
      document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
    })();
  </script>





</body>
</html>
