AA battery load tester

Posted on
  • Circuit is simple. AA battery holder connected to ground on the negative side, and to 2 1W resistors on the positive side. Each resistor is connected to the drain of a beefy N-channel mosfet (controlled by Espruino - pins A1 and A0). Voltage is monitored before the resistors, and after each resistors, in order to measure current (so I can calculate current without knowing the resistance of the fet).

    Logs are kept on SD card for graphing in excel. The idea is to be able to generate a discharge curve under various conditions, to get an idea what kind of battery to buy for every-day household electronics.

    The idea of using analog write is that I could later expand it to try to keep the current constant.

    I also have some constant current sinks coming I may try with this.

    Untested, so far.

    //Analog inputs
    //C3: Battery positive voltage
    //C2: Voltage after R1
    //C1: Voltage after R2
    
    //A1: R1 switch
    //A0: R2 switch
    
    
    var fetstate=[0,0];
    var resistance=[4.7,15];
    var endV;
    var inter;
    var timeout;
    var Wsec=0.0;
    var Asec=0.0;
    var runtime=0;
    var logname="logtest.txt"
    var fs=require("fs")
    
    function getMeasure() {
    	var retobj={};
    	var vbat=analogRead(C3)*E.getAnalogVRef();
    	var cur=0.0;
    	var pwr=0.0;
    	if (fetstate[0] > 0) {
    		var tv=vbat-analogRead(C2)*E.getAnalogVRef()­;
    		tcur=(tv/resistance[0])
    		pwr+=tcur*vbat;
    		cur+=tcur;
    	} 
    	if (fetstate[1] > 0) 
    		var tv=vbat-analogRead(C1)*E.getAnalogVRef()­;
    		tcur=(tv/resistance[0])
    		pwr+=tcur*vbat;
    		cur+=tcur;
    		cur+=(tv/resistance[1])
    	}
    	retobj.cur=cur;
    	retobj.pwr=pwr;
    	retobj.vbat=vbat;
    	return retobj;
    }
    
    function upfet() {
    	analogWrite(A1,fetstate[0]);
    	analogWrite(A1,fetstate[1]);
    }
    
    function startTest(fetst,endV,maxtime) {
    	fetstate=fetst;
    	runtime=0;
    	Asec=0.0;
    	Wsec=0.0;
    	var timeout=setTimeout("if (inter) {clearInterval(inter);endTest();}",maxti­me*1000);
    	var inter=setInterval(runTest,1000);
    }
    
    function runTest() {
    	runtime+=1;
    	var obj=getMeasure();
    	var logstr=runtime+","+obj.vbat+","+obj.cur+­","+obj.pwr+","+fetstate[0]+","+fetstate­[1]+"\n"
    	console.log(logstr);
    	fs.appendFile(logname,logstr);
    	Wsec+=obj.pwr;
    	Asec+=obj.cur;
    	if (obj.vbat < endV) {
    		clearInterval(inter);
    		clearTimeout(timeout);
    		console.log("minimum voltage reached")
    	}
    }
    
    function endTest() {
    	digitalWrite(A0,0);
    	digitalWrite(A1,0);
    	console.log("Power: "+Wsec/3.6+" mWh Current: "+Asec/3.6+" mAh")
    }
    
    
  • Looks like a really good idea - do you have a graph yet?

    I love the idea of controlling the current draw by varying the voltage on the FET.

    I'd actually really like to do an Espruino battery charger/conditioner - it'd be great to have something that'd keep my NiCd electric drill batteries in a good condition. It could even do cool things like cycle them while always making sure that one of them was fully charged :)

  • Nope. Haven't looked at this since I posted this. I've been kinda busy this week - last week before I'm on vacation, and will have more time to play with this stuff. I'll try to remember to bring the parts with me.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

AA battery load tester

Posted by Avatar for DrAzzy @DrAzzy

Actions