Introduction

  • In this article I have explained about testing the Life of Battery in Arduino Mega 2560.
  • It can be used in TV remotes and Flash lights and can also be used to check the power of battery.
Parts Of Lists
  • Arduino Mega 2560
  • Battery
  • LEDs
  • Hookup Wires
Connections
Step 1: Connection of Battery to Arduino Board
  • Connect the Battery positive pin to the Analog pin of 03 to the board.
  • Connect the negative pin to the GND to the board.
Step 2 : Connections Of LEDs to Arduino Board
LED 1
  • Connect the positive pin to the 13 of the board.
  • Connect the negative pin to the Gnd
LED 2
  • Connect the positive pin to the 12 of the board.
  • Connect the negative pin to the Gnd
LED 3
  • Connect the positive pin to the 11 of the board.
  • Connect the negative pin to the Gnd
Programming
  1. int led1 13;
  2. int led2 12;
  3. int led3 11;
  4. int analogValue = 0;
  5. float voltage = 0;
  6. int ledDelay = 2000;
  7. void setup()
  8. {
  9. pinMode(led1, OUTPUT);
  10. pinMode(led2, OUTPUT);
  11. pinMode(led3, OUTPUT);
  12. }
  13. void loop()
  14. {
  15. analogvalue = analogRead(0);
  16. voltage = 0.0048 * analogvalue;
  17. if (voltage >= 1.6)
  18. {
  19. digitalWrite(led1, HIGH);
  20. delay(ledDelay);
  21. digitalWrite(led1, LOW);
  22. }
  23. else if (voltage < 1.6 && voltage > 1.4)
  24. {
  25. digitalWrite(led2, HIGH);
  26. delay(ledDelay);
  27. digitalWrite(led2, LOW);
  28. }
  29. else if (voltage < = 1.4)
  30. {
  31. digitalWrite(led3, HIGH);
  32. delay(ledDelay);
  33. digitalWrite(led3, LOW);
  34. }
  35. }
    Explanation:
    • In this article, I have explained about testing the Life Of Battery in Arduino Mega 2560.
    • When the voltage is <1.6 volt, it can have the power
    • When the voltage is <=1.4 volt, it cannot have the power.