Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <StopWatch.h>
- #include <Time.h>
- /*
- A battery life cycle tester using an Lcd as output
- */
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd( 12, 11, 6, 5, 4, 3 );
- int sensorPin = 15; // input battery sensor reading
- int sensor2Pin = 14; // input voltage reading
- int ledPin = 13; // output trigger for MOSFET/Transistor/relay
- int sensorValue = 0; // this holds the value that the sensor reads
- 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 BatVolt = 5000;
- boolean done = false;
- float mah = 0.0;
- StopWatch sw_secs(StopWatch::SECONDS);
- void CL2(){
- lcd.setCursor(0, 1);// Second line first char
- lcd.print(" ");
- lcd.setCursor(0, 1);// Second line first char
- }
- void setup() {
- pinMode(ledPin, OUTPUT); // makes it so the IC knows this is an output pin
- lcd.begin(16,2); // sets up the LCD display, first is vertical pixel count second is rows
- lcd.print("Batt Test ON"); // prints a message to the LCD
- lcd.setCursor(0,1); //second line first character
- lcd.print("Det. Bat Type"); //print the voltage value
- delay(2000);
- lcd.setCursor(0,1); // second line first character
- lcd.print (" ");
- lcd.setCursor(0,1);
- digitalWrite(ledPin, HIGH); // makes the MOSFET/Transistor/relay/LED on
- sensorValue = analogRead(sensorPin); // reads the voltage value from the sensor
- digitalWrite(ledPin, LOW);
- BatVolt = sensorValue*3.27*2;
- if (BatVolt > 4500){
- lcd.print("Too High");
- done = true;}
- else if (BatVolt > LiMinThreshold){
- lcd.print("Li-Ion");
- SelectedMinThreshold = LiMinThreshold;
- }
- else if (BatVolt > NmhMinThreshold){
- lcd.print("NiCd/Alk ");
- SelectedMinThreshold = NmhMinThreshold;}
- else{
- lcd.print("Unknown Bat");
- done = true;}
- lcd.print("V=");
- lcd.print(sensorValue*3.27*2); // prints voltage value
- delay(3000);
- }
- void loop(){
- if (BatVolt > SelectedMinThreshold && !done){
- digitalWrite(ledPin, HIGH); // sets the transistor on
- sensorValue = analogRead(sensorPin);
- BatVolt = (sensorValue*3.27*2);
- sw_secs.start();
- CL2();
- lcd.print(BatVolt);
- lcd.print("mV ");
- mah = ((sensorValue*3.27*2/4.7)*(sw_secs.elapsed())/360); // this is the mAh equation I'm confused about
- lcd.print(mah);
- lcd.print(" mAh ");
- delay(40);
- }
- else
- {
- done=true;
- digitalWrite(ledPin, LOW); //turn the transistor/mosfet/relay/led off
- lcd.setCursor(0,0);
- lcd.print("Bat Tester Done");
- sensorValue = analogRead(sensorPin);
- BatVolt = (sensorValue*3.27*2);
- lcd.setCursor(0,1);
- lcd.print(BatVolt);
- lcd.print("mV I=");
- lcd.print(mah);
- lcd.print("mAh ");
- for (int i=0; i<100 ; i++){
- }
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement