Reading Voltage
Hello,
I am a beginner with Microcontrollers and the BASIC Stamp.· I am using the BS2.· I created a simple series circuit with a 10k resistor and a bend sensor.· I wanted to measure the voltage through the bend sensor when it is bent and have it displayed in the DEBUG terminal.· How do I go about doing this?·· The code that I have so far is:
' {$STAMP BS2}
' {$PBASIC 2.5}
voltage VAR byte
DO
DEBUG DEC ? IN6 , voltage
PAUSE 2000
DEBUG "The voltage through the bend sensor is ", ? voltage, CR
PAUSE 2000
LOOP
Post Edited (HEDGE) : 6/26/2008 2:22:28 PM GMT
I am a beginner with Microcontrollers and the BASIC Stamp.· I am using the BS2.· I created a simple series circuit with a 10k resistor and a bend sensor.· I wanted to measure the voltage through the bend sensor when it is bent and have it displayed in the DEBUG terminal.· How do I go about doing this?·· The code that I have so far is:
' {$STAMP BS2}
' {$PBASIC 2.5}
voltage VAR byte
DO
DEBUG DEC ? IN6 , voltage
PAUSE 2000
DEBUG "The voltage through the bend sensor is ", ? voltage, CR
PAUSE 2000
LOOP
Post Edited (HEDGE) : 6/26/2008 2:22:28 PM GMT
Comments
Your code will result in a 0 if the voltage on the pin is below 1.4V and a 1 when the voltage is above 1.4V...You definitely need a different approach. There are the options Mike has mentioned. With me, even though there are other methods I almost always go with an ADC chip such as the ADC0831. A simple SHIFTIN command supplies me with an 8-bit value for my voltage. There are examples of using this chip in several texts available on our website. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Also, I understand that the DEBUG command displays the information but is there a way to make the computer do something in response to the information presented. For instance, if I develop a CASE for a certain voltage range, will I be able to tell the computer to press a keyboard letter? This pressed letter will be used in a game engine such as XNA to make an object perform a certain function. Is that possible?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support