Aa/aaa Battery Charger

About the project

Build your own AA/AAA Battery Charger

Project info

Difficulty: Easy

Platforms: Espruino

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

2621  ARM Espruino Pico 2621 ARM Espruino Pico x 1
Breadboard Breadboard http://www.espruino.com/Breadboard x 1
A PCD8544 LCD display A PCD8544 LCD display http://www.espruino.com/PCD8544 x 1
Some patch wire (normal solid core wire is fine) Some patch wire (normal solid core wire is fine) x 1
AVT20020E100R0KE  Chassis Mount 225watt 100ohm 10% AVT20020E100R0KE Chassis Mount 225watt 100ohm 10% x 1
2469CN Cylindrical Battery Contacts, Clips, Holders & Springs 2 AAA... 2469CN Cylindrical Battery Contacts, Clips, Holders & Springs 2 AAA... x 1

Software apps and online services

Espruino Web IDE Espruino Web IDE

Story

Introduction


Many AA or AAA battery chargers charge batteries in pairs, but plenty of devices use 1 or 3 batteries, meaning that some of your batteries get overcharged and some get undercharged. NiCd and NiMH batteries also benefit from an occasional full discharge, which most normal battery chargers won't do.




If you're anything like me you'll end up with a lot of rechargeable batteries, none of which end up being charged properly, and some of which turn out to be completely unusable. It'd be perfect if you had a low-power battery charger that you could leave on all the time, that would charge your batteries individually, automatically discharge them, and give you an idea of their real capacity. That's what you'll make in this tutorial!


Note: To make this nice and simple, the charger uses Espruino's GPIO pins to directly charge and discharge the batteries. This means it can't charge batteries very quickly (it can take days to charge and discharge them!).

You'll Need

  • One Espruino Pico
  • A long Breadboard
  • PCD8544 LCD display
  • Some patch wire (normal solid core wire is fine)
  • 4x 100 Ohm resistors
  • AA or AAA battery holders with pins (available from Rapid Electronics: AA or AAA)


Wiring Up


  • Place the breadboard with the - row of pins right at the bottom, and the + row right at the top.
  • Plug the Espruino Pico into the breadboard as far left as it will go (as in the picture)
  • Add a wire from Espruino's GND pin (on the far left) straight down to the bottom - row of pins. You can't see this in the picture because it's under the LCD screen.
  • Plug the PCD8544 into the breadboard below the Pico, with 2 pins sticking out to the right of the Pico (it should overlap the GND wire)
  • Take a patch wire and connect from pin B1 on the Pico to the top of a column 5 pins to the right of the Pico (see the picture)
  • Fold a 75 Ohm resistor, cut it to length, and add it diagonally between the 5th column right of the Pico and the 6th.
  • Now add 3 more sets of wires and resistors, from pins A7A6 and A5, to new columns, each with 7 columns of pins between it and the last. Note: This works for AAA batteries - for AA you will need to space the columns out a bit more.
  • Cut the pins on your battery holders down so they'll fit in the breadboard, and then place the battery holders in the breadboard at an angle: With the + contact relative to the resistor (as shown below), and with the - contact in the bottom - row of pins on the breadboard.


  • Now add 2 wires for the LCD: B10 to the pin nearest the Pico, and B13 to the pin right on the edge.

And you're done!

Software

Connect to the Web IDE, copy the following software into the right-hand side, and upload it:


  1. var g;
  2.  
  3. B3.write(0); // GND
  4. // B4.write(1); // Backlight
  5. B5.write(1); // VCC
  6.  
  7. // The pins each battery is connected to
  8. var BATS = [ B1, A7, A6, A5 ];
  9.  
  10. // The resistor's value
  11. var RESISTOR_VALUE = 100;
  12.  
  13. // Are we charging or discharging batteries?
  14. var batCharge = [ 0, 0, 0, 0 ];
  15.  
  16. // How much charge has gone into batteries (in mAh-ish)
  17. var cntCharge = [ 0, 0, 0, 0 ];
  18.  
  19. // How much have batteries been discharged (in mAh-ish)
  20. var cntDischarge = [ 0, 0, 0, 0 ];
  21.  
  22. function getBatteryVoltages() {
  23. var voltages = [0,0,0,0];
  24. // read voltages multiple times, and take an average
  25. var N = 20;
  26. for (var i=0;i= 0) {
  27. g.drawStringCenter(batCharge[i] ? "CHG" : "DIS", x, 20);
  28. g.drawStringCenter(volts[i].toFixed(2), x, 28);
  29. g.drawStringCenter(cntDischarge[i] ? (cntDischarge[i]|0) : "-", x, 36);
  30. g.drawStringCenter(cntCharge[i] ? (cntCharge[i]|0) : "-", x, 42);
  31. } else {
  32. g.drawStringCenter("-", x, 20);
  33. }
  34. }
  35. g.flip();
  36. }
  37. function onInit() {
  38. var spi = new SPI();
  39. spi.setup({ sck:B6, mosi:B7 });
  40. g = require("PCD8544").connect(spi, A8 /*DC*/, B10 /*CE*/, B13 /*RST*/, function() {
  41. g.setRotation(2);
  42. g.clear();
  43. g.drawString("Loading...",0,0);
  44. g.drawLine(0,10,84,10);
  45. g.flip();
  46. });
  47. g.drawStringCenter = function(txt,x,y) {
  48. this.drawString(txt, x-this.stringWidth(txt)/2, y);
  49. };
  50. lastInterval = getTime();
  51. setInterval(onInterval, 2000);
  52. }
  53. // What happens when we press a button
  54. setWatch(function() {
  55. if (batCharge=="0,0,0,0") batCharge.fill(1);
  56. else batCharge.fill(0);
  57. cntCharge.fill(0);
  58. cntDischarge.fill(0);
  59. onInterval();
  60. }, BTN, { repeat: true, edge:"rising", debounce:50});



Code

Source code

Credits

Photo of Espruino

Espruino

Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules that form a complete solution for embedded software development.

   

Leave your feedback...