## LOW BATTERY WARNING

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

sgvideo
Flowcode V4 User
Posts: 9
Joined: Tue Mar 17, 2009 10:14 am
Contact:

### LOW BATTERY WARNING

Hi, I am new to this and did have a few problems with sleep and TMR0 issues on my project that Ben helped me on outside of the forum. At the end of the suggestions and test code, the solution was to not use an existing file and modify for my needs. it turned out to be best to start with a clean and empty file. (things can get corrupted)

Anyway now that it works, I want to add a feature that will flash an LED warning that its own battery is getting low. On searching this forum, there are only 3 references to this and I was hoping someone can point me in the right direction.

I am not very good at C and am learning ASM now.

A pretty clear solution or explanation (sample code would be great)would be greatly appreciated.

Mitch

Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: LOW BATTERY WARNING

Hello Mitch.

A simple potential dividor circuit using 2 resistors and an analogue pin should be enough to detect the battery voltage.

Simply connect two large resistors in series between your batter voltage and ground and then feed a trace from between the resistors to your analogue pin. If the battery voltage is 5V for example then if the two resistors share the same value then you will expect 2.5V on the analogue pin. If this voltage starts to drop then you know the battery is running our of power. Using large resistors eg 10K will help to reduce any wasted current used by the detection circuit.

--------Battery V
|
10K
|
----------------uC Analogue
|
10K
|
--------GND

Remember not to feed more then 5V into the analogue pin. If your voltage is more then the 10V that this circuit can handle then change your resistor values accordingly.

sgvideo
Flowcode V4 User
Posts: 9
Joined: Tue Mar 17, 2009 10:14 am
Contact:

### Re: LOW BATTERY WARNING

Thanks Ben

Worked perfectly

tanlipseong
Posts: 31
Joined: Thu Aug 27, 2009 3:11 pm
Location: Malaysia
Contact:

### Re: LOW BATTERY WARNING

Benj,

If the Vref is configure to VDD, the 2 resistor voltage divider will always be 1/2 of the VDD.

don't understand why we can detect battery low with this method.

TanLS

medelec35
Valued Contributor
Posts: 9015
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

### Re: LOW BATTERY WARNING

Hello tanlipseong. I would not connect the two resistors across +5V and 0 of PIC, Instead I would connected across the supply of the batteries which are 6V or greater.
The Pic is connected to battery supply via a 5V regulator(low voltage dropout are best for batteries. As the battery voltage will start to drop since it is greater than 5V, then the voltage to PIC will still be a constant 5V, so long as i/p to regulator stays above min recommended voltage.
All you do then is connect the o/p from 2-resistor divider to an analogue i/p. When V/out form divider falls below a ADC set amount, you can get an o/p on the PIC to change.
Martin

tanlipseong
Posts: 31
Joined: Thu Aug 27, 2009 3:11 pm
Location: Malaysia
Contact:

### Re: LOW BATTERY WARNING

Medelec35,

I am developing an application that is battery operated, 3 pcs of AAA battery =4.5V, this applies to the PIC VDD.
in this case i guess i cannot use the method discribe earlier.

may be need to select PIC that has build in fixed reference 0.6V for detecting battery low condition.

if can detect using PIC that do not have above feature, please explain the method how.

TanLS

medelec35
Valued Contributor
Posts: 9015
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

### Re: LOW BATTERY WARNING

here is the situation as I see it.

If Vref is connected to +5V, and you got resistors connected to supply which is same as Vref, then if batt voltage drops, then vref will drop, and Voltage o/p form PD will drop by same ratio, hence lower battery voltage will not be detected. However, if you use an external pin as ref, then use a low current voltage reference (e.g 3V) on this external pin, then as batt voltage drops this Vref will stay steady. This would mean the voltage ratio will change, hence low batt voltage could now be detected.
This is only my theory, and I could be wrong?
Martin

tanlipseong
Posts: 31
Joined: Thu Aug 27, 2009 3:11 pm
Location: Malaysia
Contact:

### Re: LOW BATTERY WARNING

It should work, however it require external components.
how nice if do not need external components

Regards