How To Make Battery Capacity Tester
Nowadays fake Lithium and NiMH batteries are everywhere which is sold by advertising with higher capacities than their true capacity. So it is really difficult to distinguish between a real and a fake battery. Similarly, it is difficult to know the capacity retained in the salvaged 18650 laptop batteries. So, a device is required to measure the true capacity of the batteries.
Diagram:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
#include<JC_Button.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); const float Low_BAT_level = 3.0; //Current steps with a 3R load (R7) const int Current [] = {0,100,200,300,400,500,600,700,800,900,1000}; const byte PWM_Pin = 10; const byte Buzzer = 9; const int BAT_Pin = A1; int PWM_Value = 0; unsigned long Capacity = 0; int ADC_Value = 0; float Vcc = 4.28; // Voltage of Arduino 5V pin ( Mesured by Multimeter ) float BAT_Voltage = 0; float sample =0; byte Hour = 0, Minute = 0, Second = 0; bool calc = false, Done = false; Button UP_Button(2, 25, false, true); Button Down_Button(3, 25, false, true); void setup () { // Serial.begin(9600); pinMode(PWM_Pin, OUTPUT); pinMode(Buzzer, OUTPUT); analogWrite(PWM_Pin, PWM_Value); UP_Button.begin(); Down_Button.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(2); display.setCursor(12,25); display.print("EASY TECH"); display.display(); delay(2000); display.clearDisplay(); display.setTextSize(2); display.setCursor(2,15); display.print("Adj Curr:"); display.setCursor(2,40); display.print("UP/Down:"); display.print("0"); display.display(); } //************************* End of Setup function ******************************* void loop() { UP_Button.read(); Down_Button.read(); if (UP_Button.wasReleased() && PWM_Value < 256 && calc == false) { PWM_Value = PWM_Value + 25; if(PWM_Value > 256){ PWM_Value=PWM_Value-25; } analogWrite(PWM_Pin,PWM_Value); display.clearDisplay(); display.setCursor(2,25); display.print("Curr:"); display.print(String(Current[PWM_Value / 25])+"mA"); display.display(); Serial.println(String(Current[PWM_Value / 25])); Serial.print(PWM_Value); } if (Down_Button.wasReleased() && PWM_Value > 1 && calc == false) { PWM_Value = PWM_Value - 25; analogWrite(PWM_Pin,PWM_Value); display.clearDisplay(); display.setCursor(2,25); display.print("Curr:"); display.print(String(Current[PWM_Value / 25])+"mA"); display.display(); Serial.println(String(Current[PWM_Value / 25]) + "mA"); } if (UP_Button.pressedFor (1000) && calc == false) { digitalWrite(Buzzer, HIGH); delay(100); digitalWrite(Buzzer, LOW); display.clearDisplay(); timerInterrupt(); } } //************************* End of Loop function ******************************* void timerInterrupt(){ calc = true; while (Done == false) { Second ++; if (Second == 60) { Second = 0; Minute ++; } if (Minute == 60) { Minute = 0; Hour ++; } //************ Measuring Battery Voltage *********** for(int i=0;i< 100;i++) { sample=sample+analogRead(BAT_Pin); //read the Battery voltage delay (2); } sample=sample/100; BAT_Voltage = sample * Vcc/ 1024.0; //********************************************* display.clearDisplay(); display.setTextSize(2); display.setCursor(20,5); display.print(String(Hour) + ":" + String(Minute) + ":" + String(Second)); display.setTextSize(1); display.setCursor(0,25); display.print("Disch Curr: "); display.print(String(Current[PWM_Value / 25])+"mA"); display.setCursor(2,40); display.print("Bat Volt:" + String(BAT_Voltage)+"V" ); Capacity = (Hour * 3600) + (Minute * 60) + Second; Capacity = (Capacity * Current[PWM_Value / 25]) / 3600; display.setCursor(2, 55); display.print("Capacity:" + String(Capacity) + "mAh"); display.display(); if (BAT_Voltage < Low_BAT_level) { Capacity = (Hour * 3600) + (Minute * 60) + Second; Capacity = (Capacity * Current[PWM_Value / 25]) / 3600; display.clearDisplay(); display.setTextSize(2); display.setCursor(2,15); display.print("Capacity:"); display.setCursor(2,40); display.print(String(Capacity) + "mAh"); display.display(); Done = true; PWM_Value = 0; analogWrite(PWM_Pin, PWM_Value); digitalWrite(Buzzer, HIGH); delay(100); digitalWrite(Buzzer, LOW); delay(100); digitalWrite(Buzzer, HIGH); delay(100); digitalWrite(Buzzer, LOW); delay(100); } delay(1000); } } |