Pages: [1]   Go Down
Author Topic: Tell the difference between 3.7V battery power and USB power - will this work?  (Read 661 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

 


* charger_schematic.png (17.55 KB, 1185x640 - viewed 37 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged


Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Vcc will change when you plug in USB?
Logged

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

Skype Brighteyes3333
(262) 696-9619

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Then his idea might work?
Logged

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

Skype Brighteyes3333
(262) 696-9619

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8497
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He is measuring the same Vbatt with 2 different Vcc's (Vref).
Logged

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

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8497
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: