Breathalyzer using RCTIME
Tim2009K
Posts: 1
in BASIC Stamp
Hello all. I am a complete novice to programming and electronics so please ignore my ignorance and please keep the responses as simple as possible.
I am attempting to create a device that only opens if you have a BAC over a certain amount (Its kinda a gag gift for someone).
I have a Basic stamp with an MQ-3 Alcohol sensor: https://www.sparkfun.com/products/8880. I am using the RCTIME command and I think (not positive) that I have everything wired correctly.
My problem is that the reading from the sensor is not consistent. The result in the debug screen from RCTIME is not consistent. Sometimes when I execute the program I will get a reading of 11,000, then I will turn it off, turn it back on the next day and it will be 1,000. Its like its switching by an order of magnitude from day to day. I am trying to get a baseline for what ambient air would read on the sensor but I can't even get that because the value is fluctuating erratically.
I have a theory that variable I am saving the RCTIME result to is having some type of overrun error and resetting or something, but I am not sure about that. Could you guys please review my code and let me know what is going on? It might be something simple, but unfortunately I have extremely limited experience with this stuff. Any thing helps, thanks!
Here is the code: (Note I am not concerned about the LEDs, I know how to get those to light up how I want. I am concerned with the RCTIME result)
' {$STAMP BS2}
' {$PBASIC 2.5}
result VAR Word
DO
HIGH 0 'Charges the capacitor on pin 0
PAUSE 1000 'This gives the capacitor time to charge,originally I had this at "1" but changed it to "100" based on a tutorial
RCTIME 0,1,result 'Measurese RC discharge time on pin 0
DEBUG HOME, DEC result 'Displays value
PAUSE 50
IF (result >= 1400) THEN
GOTO Blueled
ELSEIF (1399 > result > 1200) THEN
GOTO Yellowled1
ELSEIF (1199 > result > 0) THEN
GOTO Greenled3
ELSE : GOTO Greenled1
ENDIF
Blueled:
HIGH 4
HIGH 15
HIGH 14
HIGH 13
HIGH 12
HIGH 11
HIGH 10
HIGH 9
HIGH 8
HIGH 7
HIGH 6
PAUSE 3000
LOW 15
LOW 14
LOW 13
LOW 12
LOW 11
LOW 10
LOW 9
LOW 8
LOW 7
LOW 6
LOW 4
GOTO Finish
Yellowled1:
HIGH 9
HIGH 8
HIGH 7
HIGH 6
PAUSE 500
LOW 9
LOW 8
LOW 7
LOW 6
GOTO Finish
Greenled3:
HIGH 8
HIGH 7
HIGH 6
PAUSE 500
LOW 8
LOW 7
LOW 6
GOTO Finish
Greenled1:
HIGH 6
PAUSE 500
LOW 6
GOTO Finish
Finish:
LOOP
I am attempting to create a device that only opens if you have a BAC over a certain amount (Its kinda a gag gift for someone).
I have a Basic stamp with an MQ-3 Alcohol sensor: https://www.sparkfun.com/products/8880. I am using the RCTIME command and I think (not positive) that I have everything wired correctly.
My problem is that the reading from the sensor is not consistent. The result in the debug screen from RCTIME is not consistent. Sometimes when I execute the program I will get a reading of 11,000, then I will turn it off, turn it back on the next day and it will be 1,000. Its like its switching by an order of magnitude from day to day. I am trying to get a baseline for what ambient air would read on the sensor but I can't even get that because the value is fluctuating erratically.
I have a theory that variable I am saving the RCTIME result to is having some type of overrun error and resetting or something, but I am not sure about that. Could you guys please review my code and let me know what is going on? It might be something simple, but unfortunately I have extremely limited experience with this stuff. Any thing helps, thanks!
Here is the code: (Note I am not concerned about the LEDs, I know how to get those to light up how I want. I am concerned with the RCTIME result)
' {$STAMP BS2}
' {$PBASIC 2.5}
result VAR Word
DO
HIGH 0 'Charges the capacitor on pin 0
PAUSE 1000 'This gives the capacitor time to charge,originally I had this at "1" but changed it to "100" based on a tutorial
RCTIME 0,1,result 'Measurese RC discharge time on pin 0
DEBUG HOME, DEC result 'Displays value
PAUSE 50
IF (result >= 1400) THEN
GOTO Blueled
ELSEIF (1399 > result > 1200) THEN
GOTO Yellowled1
ELSEIF (1199 > result > 0) THEN
GOTO Greenled3
ELSE : GOTO Greenled1
ENDIF
Blueled:
HIGH 4
HIGH 15
HIGH 14
HIGH 13
HIGH 12
HIGH 11
HIGH 10
HIGH 9
HIGH 8
HIGH 7
HIGH 6
PAUSE 3000
LOW 15
LOW 14
LOW 13
LOW 12
LOW 11
LOW 10
LOW 9
LOW 8
LOW 7
LOW 6
LOW 4
GOTO Finish
Yellowled1:
HIGH 9
HIGH 8
HIGH 7
HIGH 6
PAUSE 500
LOW 9
LOW 8
LOW 7
LOW 6
GOTO Finish
Greenled3:
HIGH 8
HIGH 7
HIGH 6
PAUSE 500
LOW 8
LOW 7
LOW 6
GOTO Finish
Greenled1:
HIGH 6
PAUSE 500
LOW 6
GOTO Finish
Finish:
LOOP
Comments
Going under the presumption (not Smileumption, that's dangerous) that you've wired it correctly, could this paragraph have any impact?
Otherwise, be prepared. Forumistas will be asking for the schematic used, pictures of the wiring, etc.