I have a circuit that is normally battery powered. I would like to add a charger circuit (I have already chosen a 5-pin SMD - http://ww1.microchip.com/downloads/en/DeviceDoc/20001984F.pdf). I would also like the arduino to know when I am charging, so that it can turn off all the LED's (they draw a lot of current) and possibly go to sleep.
The battery is normally about 3.7V, and USB is 5V. So could I figure out if the arduino is plugged in, by running a line from the battery positive terminal to the analog input. The Battery positive terminal is already connected to VCC through a Schottky diode.
I figure:
If arduino is NOT plugged into 5V. The Vcc will be ~3.5V. The Analog input will be 3.7V, so the reading should be approximately 1023.
If arduino IS plugged into 5V. The VCC will be +5V or so. The Analog input will still be 3.7V so the reading should be about 750.
So if this is true, I should be able to take this analog reading and have the Arduino shut down the LED's if it sees a reading below 850 or so.
Does anyone see a flaw in my reasoning?
BTW here is a quick schematic of my proposed circuit:
analogRead doesn't return 750 from Vcc, if Vcc is 3.7V, it returns 1023. Same as if Vcc is 5V. The number 1023 is returned if the analog pin is equal to the Vcc pin. Thus, on its own, you cannot work out what Vcc is.
Unless you use an external reference or the internal 1.1V reference.
I actually have a shottky diode between the 3.7V battery and VCC. Thus the 3.7V at the battery's positive terminal is always (roughly) 3.7V. If I am plugged into USB VCC is 5V and battery+ is 3.7V. If not, VCC is (roughly) 3.5V and battery+ is 3.7V.
I don't know if the AI pin being .2v over VCC/AREF will kill anything but it may be a good idea to add another diode to the signal going to the AI so it's the same level as VCC/AREF.