Arduino Diecimila 1602单色屏 制做简单的锂电、镍镉、镍锰电池容量测试仪,转自网友moris-zen。
这个东西,能够根据待测电池的电压自动判断放电类型。使用的一块arduino diecimila板子,这里作者
就直接使用了一块atm168配合几个外围元件代替。放电假负载用的是一个2.2 欧姆的 10W的水泥电阻。所以
可以测量大功率电池,例如 18650 锂电池。
数据采集就是使用单片机两个AD数模单元分别采集电压、电流,然后计算得出最后的容量。
放电电路简单,就是下图,2.2欧姆 10W水泥电阻做负载,穿上个开关管,由单片机控制开关。
测试时,直接将两个单片机的两个A/D脚接到水泥电阻两端即可。电压直接读取,电流 I = Delta V / R。
具体参看代码。
(开关管的G端接单片机的19脚)
这个模块可以通过串口向计算机发送数据,可以例如Excel将所得到的数据统计”成图”
代码如下:
// include the library code:
#include<liquidcrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// initialize the library with the numbers of the interface pins
int sensorPin = 0; // select the input pin for the potentiometer (pin 23)
int sensor2Pin = 2; // select the input pin for the potentiometer (pin 23)
int ledPin = 13; // select the pin for the LED
int SPKPin = 6;
int sensorValue = 0; // variable to store the value coming from the sensor
int sensor2Value = 0; // variable to store the value coming from the sensor
float LiMinThreshold = 2700; // Lithium Minimal Voltage for load removal
float LiMaxThreshold = 4200; // Lithium Max Voltage for load removal
float NmhMinThreshold = 950; // NMH Minimal Voltage for load removal
float NmhMaxThreshold = 1600; // NMH Max Voltage for load removal
float SelectedMinThreshold = 5000;
int i;
int BatVoltage = 5000;
int FetVoltage = 5000;
long TotalCurrent = 0;
boolean done = false;
unsigned long PrevMillis ;
unsigned long MillisPassed ;
void CL2(){
lcd.setCursor(0, 1);// Second line first char
lcd.print(" ");
lcd.setCursor(0, 1);// Second line first char
}
void setup() {
Serial.begin(9600);// start serial port to send data during run to the PC
pinMode(ledPin, OUTPUT);//activation led and enable for FET
pinMode(SPKPin, OUTPUT);//activation led and enable for FET
lcd.begin(24, 2);// set up the LCD's number of rows and columns:
lcd.print("Bat PWR Tester[Active]"); // Print a message to the LCD.
lcd.setCursor(0, 1);// Second line first char
lcd.print("Detecting Bat Type..."); // print voltage value
delay(2000);
lcd.setCursor(0, 1);// Second line first char
lcd.print(" ");
lcd.setCursor(0, 1);// Second line first char
digitalWrite(ledPin, HIGH); // set the LED on
sensorValue = analogRead(sensorPin); // read the value from the sensor:
digitalWrite(ledPin, LOW); // set the LED off
// Detecting battery type
BatVoltage = sensorValue*4.887;
if (BatVoltage > 4500){
lcd.print("Warning high-V! ");
done = true;}
else if (BatVoltage > LiMinThreshold){
lcd.print("Type:Li-Ion Bat ");
SelectedMinThreshold = LiMinThreshold;}
else if (BatVoltage > NmhMinThreshold){
lcd.print("Type:NiMH/Cd Bat ");
SelectedMinThreshold = NmhMinThreshold;}
else{
lcd.print("Unknown Bat V<1 ");
done = true;}
lcd.print("V=");
lcd.print(sensorValue*4.887); // print voltage value
Serial.print("DT[ms]");
Serial.print("\t");
Serial.print("Bat[mV]");
Serial.print("\t");
Serial.print("Fet[mV]");
Serial.println("");
delay(3000);
CL2();
PrevMillis = millis();
}
void loop() {
if (BatVoltage > SelectedMinThreshold && !done) {
digitalWrite(ledPin, HIGH); // set the LED on
sensorValue = analogRead(sensorPin); // read the value from the sensor:
sensor2Value = analogRead(sensor2Pin); // read the value from the FET:
FetVoltage = (sensor2Value*4.887);
BatVoltage = (sensorValue*4.887);
CL2();
lcd.print("V=");
lcd.print(BatVoltage); // print voltage value
lcd.print("mV");
//lcd.print(FetVoltage); // print voltage value
TotalCurrent=TotalCurrent+MillisPassed/1000*(BatVoltage-FetVoltage)/2.2/3.6;
lcd.print(" I=");
lcd.print(TotalCurrent/1000);
lcd.print("mAH ");
delay(1000);
MillisPassed = millis()- PrevMillis;
PrevMillis = millis();
Serial.print(int(MillisPassed));
Serial.print("\t"); // prints a tab
Serial.print(BatVoltage);
Serial.print("\t"); // prints a tab
Serial.print(FetVoltage);
Serial.println(""); // prints a tab
CL2();
}
else
{
done=true;
digitalWrite(ledPin, LOW); // set the LED off - stop loading
lcd.setCursor(0, 0);// First line first char
lcd.print("Bat Power Tester [DONE] "); // Print a message to the LCD.
CL2();//clear line 2
sensorValue = analogRead(sensorPin); // read the value from the sensor:
BatVoltage = (sensorValue*4.887);
lcd.setCursor(0, 1);// Second line first char
lcd.print("V=");
lcd.print(BatVoltage); // print voltage value
lcd.print("mV I=");
lcd.print(TotalCurrent/1000);
lcd.print("mAH ");
for (int i=0; i<100 ; i++){
digitalWrite(SPKPin, HIGH);
delay(1);
digitalWrite(SPKPin, LOW);
delay(1);
}
delay(1000);
}
}
有网友利用类似的设计,做出来的4通道电池容量测试仪,屏幕用是手机彩屏。
可惜没有公布代码