Go Down

Topic: Tell the difference between 3.7V battery power and USB power - will this work? (Read 808 times) previous topic - next topic

stevethatsmyname

Hi folks, 

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:

1) 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.
2) 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:

 

Er, yes. The analog reading will read (roughly) 1023 if the analog pin is equal to Vcc. So it won't change.

See: http://www.gammon.com.au/power

Scroll down to "Detecting low voltage".
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

sbright33

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

He said it would, in his case:

Quote
1) If arduino is NOT plugged into 5V.  The Vcc will be ~3.5V.  ...
2) If arduino IS plugged into 5V.  The VCC will be +5V or so.  ...
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

sbright33

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Graynomad

If VREF is tied to VCC on the module I think it will work.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com


Then his idea might work?


No, as I was trying to explain.

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

sbright33

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

stevethatsmyname



Then his idea might work?


No, as I was trying to explain.

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.


Thanks for the advice so far.

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 haven't given this a try yet but I will soon. 

I just want to point out that you are not supposed to put more than the reference voltage into an analog input pin.

So if Vcc is 3.5V you shouldn't try to measure 3.7V. You could use a voltage divider to divide it down but my earlier remarks still apply.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Graynomad

Quote
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.

My earlier remarks also still apply :)

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up