Hi. I hope some of you guys are still around to help me with this.
I have tried the battery voltage monitoring technique described in the opening post without any success on an ATMega328p running at 1Mhz. Instead of connecting R2 of the voltage divider directly to GND, R2 is connected to D12 and set low just before reading the battery voltage. The analogRead function always returns the maximum, 1024. Initially, I thought it was the sketch looping too fast, so I introduced a 10 ms delay after the analogRead function so that D12 can be properly 'grounded' before the battery voltage is read but that still didn't work.
My voltage divider circuit resembles this: Vin(3v) -- 1M(R1) -- A1 (Vo) -- 300K(R2) -- D12
D12 is the BATTERY_ENABLE_PIN.
My AnalogRefence is set to INTERNAL(1.1v).
Here's the code:
pinMode(BATTERY_ENABLE_PIN, OUTPUT);
digitalWrite(BATTERY_ENABLE_PIN, LOW);
voltage = analogRead(A1);
delay(10);
pinMode(BATTERY_ENABLE_PIN, INPUT);
BTW, the battery monitor works if R2(300K) is connected directly to GND. Problem is when it is connected to D12, to save energy consumed by the divider as described above.