Hi, i want to run my arduino pro mini with 3.3 V battery and want to read the battery status, so i can replace it when its almost empty. The problem is, there are many differnt versions and i am kind of confused. Can somebody show me a code that works and explain it a bit. I tried for example this code and understood what it does but i get wrong results. Thank you for your help.
int adc_low, adc_high;
long adc_result;
long vcc;
void setup() {
ADMUX |= (1<<REFS0);
ADMUX |= (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
delay(10);
ADCSRA |= (1<<ADEN);
}
// the loop routine runs over and over again forever:
void loop() {
ADCSRA |= (1<<ADSC);
while (bitRead(ADCSRA, ADSC));
adc_low = ADCL;
adc_high = ADCH;
adc_result = (adc_high<<8) | adc_low;
vcc = 1125300L / adc_result; // (1100mV * 1023 = 1125300)
Serial.println("Battery status");
Serial.println(vcc);
delay(500);
}