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
- int led1 13;
- int led2 12;
- int led3 11;
- int analogValue = 0;
- float voltage = 0;
- int ledDelay = 2000;
-
- Void setup()
- {
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- }
- void loop()
- {
- analogvalue = analogRead(0);
- voltage = 0.0048*analogvalue;
- if ( voltage >= 1.6 )
- {
- digitalWrite(led1, HIGH);
- delay(ledDelay);
- digitalWrite(led1, LOW);
- }
- else if ( voltage < 1.6 && voltage >
- {
- digitalWrite(led2, HIGH);
- delay(ledDelay);
- digitalWrite(led2, LOW);
- }
- else if ( voltage < = 1.4 )
- {
- digitalWrite(led3, HIGH);
- delay(ledDelay);
- digitalWrite(led3, LOW);
- }
- }
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.