/* Author: Joselio Carneiro AKA Kantrys Brasília, Brazil. This is my very first project with Fritzing and Arduino. It is a simple battery level indicator that uses three LED. According the amount of charge in the battery, all LEDS are on or, two, or one, or none. With a simple resistive divider, a battery up to 10volts can be measured. Actually, the capacity of the battery can be increased according to the resistive divider used. To mount it, follow the design in the Fritizing project attached. Be confortable to change anything you need. */ int GreenLedPin = 12; int YellowLedPin = 11; int RedLedPin = 10; int GreenLedState = 0; int YellowLedState = 0; int RedLedState = 0; int sensorPin = 3; int minutos = 0; float sensorValue = 0; void setup() { pinMode(GreenLedPin, OUTPUT); pinMode(YellowLedPin, OUTPUT); pinMode(RedLedPin, OUTPUT); Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); sensorValue /= 1024; sensorValue *= 7.5; if (sensorValue >= 4) { digitalWrite(GreenLedPin, HIGH); } else { digitalWrite(GreenLedPin, LOW); } if (sensorValue >= 2.4) { digitalWrite(YellowLedPin, HIGH); } else { digitalWrite(YellowLedPin, LOW); } if (sensorValue > 1.6) { digitalWrite(RedLedPin, HIGH); } else { digitalWrite(RedLedPin, LOW); Serial.print(" Substitua a bateria. "); } delay(60000); minutos +=1; Serial.print("Apos "); Serial.print(minutos); Serial.print(" Minuto(s), a carga atual e: "); Serial.println(sensorValue); }