So I would like to use my Arduino as a "smart" NiMh battery charger. I am powering it using a 9 volt wall wart plugged into the arduino and then powering a breadboard using the Vin pin on the arduino.
On the breadboard, I am using an LM317 to provide a constant 800 mA to the NiMh batteries and measuring the voltage every 20 seconds or so using a voltage divider connected to an arduino analog pin. I am using a Tip120 transistor to turn it off and on.
A couple of quick questions:
I am currently measuring the voltage while the batteries are charging. Should I turn the charger off, measure the voltage, then back on? If so, should I do this every 20 seconds?
Anyone see anything wrong with what I have done so far?
I would like to be able to throttle the LM317 down to a trickle charge of about 50 mA or so. How can I accomplish this? PWM comes to mind, but in order to control the current using the LM317, I would have to adjust the resistance between the out/adj pins and don't know how to do that with PWM.
Here is a ghetto schematic:
and a pic of my current setup:
and my code:
int ledPin = 13; // LED connected to digital pin 13
int tranPin = 2; // Digital pin used to
int voltPin = 5; // Analog pin used to measure load voltage
float voltage = 0; //these should all be ints.... need to fix
float val = 1;
float maxVal = 0;
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(tranPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600); // setup serial
digitalWrite(tranPin, HIGH); // start charging
//delay(240000); // Charge for 6 minutes to allow voltage to settle
}
void loop() // run over and over again
{
while((val+10)>maxVal) //charge until voltage drops about 10 millivolts
{
digitalWrite(ledPin, HIGH); // sets the LED on
val = analogRead(voltPin); //get current raw voltage value val is approximately equiv to millivolt
voltage = 5 * val / 512; //calculate voltage
Serial.println(val);
Serial.println(voltage);
maxVal = val;
delay(21000);
val = analogRead(voltPin);
Serial.println(val);
}
digitalWrite(tranPin, LOW); //stop charging
val = 0;
maxVal = 1;
digitalWrite(ledPin, LOW); //blink led to indicate stopped charging
delay(1000);
digitalWrite(ledPin, HIGH);
delay(1000);
}
I know that there is a "pullup resistor" in analog pins which can be activated by digitalWrite HIGH the analog in pins. But I have completely no idea what are they for .... (sorry, i'm new)
a dump idea comes up that what about putting 1 more set of LM317 with different resistors, then control which will provide power by digital pins and another transistor ? (sounds silly...but might work...)
I am currently measuring the voltage while the batteries are charging. Should I turn the charger off, measure the voltage, then back on? If so, should I do this every 20 seconds?
No, you should measure the voltage while the batteries are charging. You are looking for a "dip" in voltage indicating that charge is complete, and you won't see it with the charging process stopped.
Anyone see anything wrong with what I have done so far?
I'm not really getting the point of the 0.47 ohm resistor. I'm also not seeing the voltage divider setup as working.
Here's the circuit I would suggest as a starting point. Don't think about controlling the current -- think about controlling its voltage. The higher the voltage output of the LM317, the more current you will be pumping into the batteries. Monitor that current and keep it steady, adjusting the voltage as necessary, then monitor the voltage and look for the "dip".
To do 50mA trickle charge, just dial down the voltage until you see 50mA.
Ideally you would also use a thermistor to measure battery temperature and make sure they're not getting too hot (<55C or so).
Note that for only 1-2 cells, the LM317 will be dropping a lot of voltage and therefore dissipating a lot of power. You're going to need a really good heat sink to prevent it from burning up.
That's a good schematic, very clearly explained, thank you.
But I am wondering, why not go for a dedicated IC, cheaper, tested and true, rather than bother with an expensive (for this purpose) arduino + its programming?
Thanks for taking the time to do the nice schematic. It really helps quite a bit.
I'm not really getting the point of the 0.47 ohm resistor. I'm also not seeing the voltage divider setup as working.
The purpose of the 1.0 and .47 ohm resistors was to have the lm317 provide a constant 850 mA or so current (1.25V/1.47Ohm). Everything I have read suggests charging NiMh batteries at a constant current. Is this not right?
My voltage divider on my ugly sketch wasn't drawn correctly. I did have it implemented correctly though...
Ideally you would also use a thermistor to measure battery temperature and make sure they're not getting too hot (<55C or so).
Yeah, that was going to be the next part of my plan. I wanted to get the rest working first. When I was charging my batteries, they never got warm to the touch, but that is definitely something I will implement.
Your design has an op-amp to adjust the voltage. I have never played around with op-amps before and really don't understand how they work. I am going to have to study up on them before going too much farther.
That's a good schematic, very clearly explained, thank you.
But I am wondering, why not go for a dedicated IC, cheaper, tested and true, rather than bother with an expensive (for this purpose) arduino + its programming?
I just started with the arduino and wanted a project that would do something useful. I got started with linux in much the same way. I wanted to install the OS and do something useful with it so I built myself a MythTV DVR back when it was much harder to get it all to work (with modern package management systems like yum or apt-get, it's almost trivial to setup a MythTV box).
RuggedCircuits, have you actually built the circuit you posted?
RuggedCircuits, have you actually built the circuit you posted?
No! No warranty expressed or implied I think the basic structure is sound but the devil is in the details so if you do build it, start carefully with a load resistor instead of a battery, for example, so you don't damage anything. Ramp up the current a little at a time, check voltages/currents etc. and make sure everything works and makes sense. Good way to learn about how everything works, too.
Besides, I tend to use the single-chip solutions that florinc suggested, especially because they implement a much more efficient (but relatively complicated) switching regulator approach.