View Full Version : Voltage monitor of BS2 power source
02-23-2010, 07:07 AM
I was wondering if it was possible to measure the battery voltage (of the 9 volt battery) that powers the basic stamp 2.
I want to flash some led’s or turn an alarm when the 9 volt supply to the bs2 goes below a certain (set-point) level.
(I am operating a device that is sensitive in that battery failures and will cause disruptions in operation of the device causing me problems I wish to avoid!)
The other thing I have in mind is: I integrated the bs2 into a device that uses 4 double A Batteries. I would also like it if the bs2 could·monitor those batteries, and consequently flash led’s or turn on an alarm when that battery set goes below a set-point level.
Could you please advise your thoughts on what might be a way on how to do this?
- schematic,· program, or simply a link to reference work within this forum or online so I can review it.
Thanks in advance -·"we can make the world a better place using electronics!"
02-23-2010, 09:40 AM
RCTIME is the only way I know how you could do it without added parts. Look it up in the reference section of the editor.
02-23-2010, 12:03 PM
There's good information on the RCTIME statement and its use in measuring voltages at www.emesystems.com (http://www.emesystems.com). Click on the "app-notes" link at the bottom of the page.
02-24-2010, 03:04 AM
Hello guys. A different idea...
I came across this link http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol6/col/nv120.pdf
However, the code appears to be for a bs1, not a bs2. Also, the other thing is the pot command does not work.
I have in mind, to use an LCD display to warn a user that their battery is low. The display will be a simple 3 pin connected to pin 0. What are your guys thoughts?
So, to summarize, what I want to do is to still be able to measure a low voltage condition, but to output it to an lcd display. Can we still use the optocoupler method in the attached link?
What about the lcd panel as both devices say that you tie·into pin 0.
Please advise what you think about the link, and also if a work around can be found for pot command, would you say that the pin 0 issue can be resolved by using a different pin.
02-25-2010, 01:47 AM
I posted the wrong link. It should have been:
Now, the above question applies. Oops.
So, can we replace pot command with rctime?
Maybe something like...
rctime 0, 0, batt
If I use this device I am going to try to incorporate it into an LCD such as the simple 3 pin unit. I will try and display text low voltage on the display. What say you guys?
Good or not?
summary of problem: Using BS2 parallax, came across old link article from 1995 that uses an neat optocoupler but code is old. Need help to fix code for bs2, want to be able to display low voltage warning on parallax 3 pin lcd display
02-25-2010, 02:15 AM
Try getting your program to turn on an LED when the voltage gets to the 'low' level and post that. Then we can go from there.
My thoughts on the LCD is it is going to be a power hog and won't run very long if you are powering your circuit with a 9v batery.
For starters, see if these 2 links help
02-25-2010, 03:37 AM
Hi, the two links were a huge help!
Also, I will try to implement the led and sound warnings first. I have one of thoselccd displays already in transit. I may implement something other than a 9 volt battery...The idea behind the display was maybe not necessary. Wasted money.
Anyway, I like the optocoupler all in one device and wish to give that a go like the link in the article. My code looks like this:
'Low Battery Warning
· 'Use CDS optocoupler CLM6000
· 'Uses 47K resistor across cell and .1uF cap to gnd
· 'Uses a high value resistor in series with optocoupler in series w/ battery
· 'When voltage drops, Cds resistance increases
· 'Set scale of pot function under the low bat condition
· 'Determine setpoint using a power supply and dmm
· 'Ref website http://www.arttec.net/Press/Battery/BatteryMonitor.pdf
·Batt······ VAR····· Byte
·LoBatt··· VAR····· Byte
·PAUSE 1··············· ' 1 is the time in mS...may need to experiment and change this '
·RCTIME 0, 0, Batt····· ' represents 0...may need to be a 1, the pin number, and the variable name
·IF Batt > LoBatt THEN GOTO Alarm
··· ' if less than established value
··· HIGH 10······································ ' turn on a red led at pin 10
··· PAUSE 1000··································· ' stay on for 1000mS
··· LOW 10······································· ' turn off the red led at pin 10
··· FREQOUT 8, 250*/ TmAdj, 1500 */ FrAdj········ ' sound the
··· FREQOUT 8, 350, 1250························· ' alarm
··· GOTO Alarm
··· 'send a messsageto the lcd display "low voltage"
02-25-2010, 05:57 AM
I think the LED/Optocoupler battery sensor is wasteful of energy. There's no way to turn it off or not use it. It's always going to be drawing some amount of current, mostly when the battery voltage is above whatever threshold you set and it will be several mA there. It's much better to use the RCTIME statement as described at EmeSystems. When you set the Stamp I/O pin to input mode, it draws essentially no current. When you use the I/O pin to sense the voltage, it can give you a better idea of the battery voltage than the optocoupler.
In terms of using a LCD, the current drain can be very low, particularly if you get a non-backlit device. The backlight draws most of the current. This one draws only 2-3mA: www.seetron.com/bpk216_1.htm (http://www.seetron.com/bpk216_1.htm).
02-25-2010, 06:03 AM
I see, makes total sense to not use opto coupler, and look for a low power lcd as described.
For the sake of discussion , why couldn't you pulse the led of a photocoupler just long enough to take a reading?
Also for discussion, here is an analog photocoupler:
02-27-2010, 02:20 AM
i had tried this in a different way and it worked.. but in a slight different way..
i used the LM3914 Dot/Bar display driver IC..
check this link:
it's an ic which can accuratly indicate a DC voltage level in a TTL output which can be represented with leds..
hope that helps,,
02-27-2010, 09:55 AM
What about using something like this?
CMOS LSIs for Voltage Detection
I haven't used one but it looks like you could monitor the out put.
I haven't used one of these so I'm just throwing out ideas.
02-28-2010, 11:13 AM
Gentleman - thanks.
I am new to the forum so I typically won't reply until I have the problem solved. I will initally say that I am very glad to be on this forum. Impressed by the support, and just pleased you guys are helping. I have reviewed the ideas and from the simplicity standpint and low current draw, use of an lcd display makes sense to go with a non-backlit. To display voltage, etc... The issue of a low voltage alarm is easily resolved with the rctime command, and some resistor cap components. I breifly reviewed the other links and liked the ideas. Later in my career (from days to years from now) - this gives me the mindset to look at all opportunities, and could resolves cost impact, or reduction, and make a person meet their goals. I am not doing a work project by the way, but was recently laid off. We were constanty on cost reduction efforts, and I see now that knowing all the possible methods to do soemething allows you to make smart decisions. I am working on a differerent issue on my project, and will return to this one with an update on what I have done and although I kind of know which one I will use do not wish to speculate until it is assembled and actually working!
Thanks so much you guys
03-04-2010, 06:57 AM
How do we calculate the Scaling factor for a 9 volt power supply if I am going to go ahead with the Optocoupler method?
I arbitrarily from a tip used LoBatt CON 741
This came from our tech line but I may not have explained clearly, that I am using a 9 VOLT source!!! (Not the 12V source used in the nuts and volts column).
I know this plan I used is/was not the ideal concept, but I happened to have 20 of these exact optocouplers on hand, and everyhting else I needed. I breadboarded the circuit, and it works all "too well". It comes on, and will not turn off it's alarm...no matter what voltage I sweep.
I built the circuit with a series resistor as described in the "nuts and volts" column # 5 listed a few posts up. It is a little confusing to my why it says that the series resistor is (Source Voltage - LED voltage Drop)/ Expected current...then they use an entirely different resistor??
They wrote in the article "So in the case of a 9 volt battery, a 1.9V led drop, and a 10mA current we have"
(9-1.9)/10e-3 = about 700 ohms resistor.
What confuses me is that the author said that he built the circuit for a 12 VOLT system, and he says I used a 100K series resistor??
I am not building the basic RCTime cct we all should have used...I know, I know - Should have listened but wanted to try this anyway so please don't suggest abandon it...or at least just yet.
My questions are:
1. What should the scaling factor be for a 9 Volt system?
2. What should the series resistor be for a 9 volt system?
3. How is it you arrive at that value, is there a formula to show us how to calculate this?
The CON 741 (value of 741 came from a call I made into tech support but I might have missed exactly stating I was at 9Volts, and I did not ask how they arrived at that number)...
Summary of problem:
I built circuit in the nuts and volts colum exactly as figure shows, using the exact p/n optocoupler in the article. The alarm instantly turns on and will not turn off no matter what I do with the variable bench power supply (between the ranges of 4 volts and 12.5 volts it stays on). I did not crank it higher.
Here is my BS2 code that I came up with as the original article was written for BS1:
LoBatt CON 741 'Provided by tech support
'LoBatt CON 220 ' The bs 1 value was 220.
Batt VAR Word
RCTIME 0, 1, Batt
DEBUG DEC ? Batt
IF Batt > LoBatt THEN
FREQOUT 2, 250, 1150
FREQOUT 2, 350, 1250
03-07-2010, 05:31 AM
I was wondering if anyone has had a chance to review my previous post question and provide and answer?
I have been working with Parallax tech support, and they have not been able to come up with an answer.
As mentioned, I built the optocoupler circuit as referenced in my above post.
The alarm comes on and won't turn off no matter what voltage between 4.0 volts and 12.5 volts.
My guess is I built the circuit as described for a 12 volt system but I am supplying only 9 volts.
As I asked tech support:
What should the series resistor be, and what value would we assign to·CON, and how did you arrive at that value.
Above listing provided my sample code, and was for a BS2.
I built this circuit as I happen to have on hand 20 or so the exact optocoupler. Thre rest was basic resistors, a .1 uF cap, some basic breadboarding. Convert BS1 program to BS2, and I am stuck with the series resistor and what CON value should be.
I noticed that your alarm routine has you returning to the alarm; thus the alarm continues.··Whereas it should return to the beginning of the main routine; in order for the alarm to stop.
The main routine·does not have a looping directive. Therefore the program goes through the voltage checking process only once and, regardless of the outcome of the voltage comparison, always goes into the alarm routine.
hopes this helps. cheers, David
03-14-2010, 04:33 PM
That did not work.
two things; Number 1:
There is an error in my code. First off, I told it that if Batt > LoBatt
THEN Goto Alarm.
LoBatt = 1052
This should have been If Batt < LoBatt then goto Alarm.
Number 2: There is still a problem.
In my code I added a line to ouput the value of Batt (which is declared as Batt VAR Word) to the DEBUG and also on my LCD display.
I saw that the value of my RCTime Batt is always = to 0. It never comes up with a tangible value to compare with LoBatt ????.
Can someone please advise (and this should apply to any type of RCTIME application). JUST HOW IS IT THAT THE RCTIME VALUE GETS CREATED IN THE MICROCONTROLLER IN A BUILT up CIRCUIT SO THAT IT CAN COMPARE THE Batt VALUE WITH LoBatt?
It logically makes sense to me that if Batt is registering, then the microcontroller can perform the logic. Example. Say it finds Batt is equal to a tangible RCTIME value of 750. upon comparison it would see this is less than LoBatt and not sound an alarm.
The reason even after fixing my code, that the alarm stays on all the time is that the RCTIME is not working. It finds my declared variable name BATT to be equal to zero all the time.
What could this be???
03-14-2010, 06:16 PM
Ignore my last post. It was a bad soler connection at the wire leading to the bs2 pin 0. Problem solved, it works!
So what's wrong with a simple voltage divider? 10K or better yet 100K (less current) trimpot across the battery, and adjust it so the voltage at the center contact drops below 1.4V at whatever you want your dropout/alarm voltage to be. Feed that center contact voltage into a Stamp pin and monitor it occasionally. When the pin reads high, your battery voltage is above your cutoff voltage. When it drops below cutoff, the input pin will read low because the applied pin voltage is lower than the 1.4V high/low transition voltage.
So this can use one adjustable pot or two fixed resistors as a voltage divider. And you can monitor 9V, 6V, 3V, 12V, anything. Just tie all of your grounds together, and make sure you never feed more than 5V to a Stamp pin.
·"If you build it, they will come."