Integrating LPG Gas Sensor Module with RN-42 Bluetooth Module
KyleALindsay
Posts: 4
I am working with a Basic Stamp 2.
I would like to use the LPG Gas Sensor Module with RN-42 Bluetooth Module to take gas readings wirelessly.
I have the example program for both but am having trouble combining these together.
Any help would be appreciated.
This is what i have so far.
'GAS SENSOR #1 - PROPANE
HSW PIN 6 ' Heater Switch Control
ALR PIN 7 ' Alarm Input Sense
index VAR Word ' Counter Variable
RX PIN 0 ' RX of the Easy Bluetooth
TX PIN 2 ' TX of the Easy Bluetooth
Baud CON 84 ' Baud set at 9600
myByte VAR Byte ' Byte to establish connection & used for workspace
PAUSE 250 ' Waits 1/4 second
SERIN RX, Baud, [myByte] ' Waiting for byte
myByte = 0 ' Clear the byte value
SEROUT TX, Baud, [ CLS] ' Send instructions to the Debug Terminal
DO
DO UNTIL myByte > 0 ' Wait until byte is valid
SERIN RX, Baud, [myByte] ' Receive byte
LOOP
HIGH HSW ' Turn Heater ON
FOR index = 59 TO 0 ' Count Down 60 Seconds
SEROUT TX, Baud, ["PURGE MODE...", DEC2 index, " "]
myByte = 0
PAUSE 1000 ' 1 Second Pause
NEXT
index = 1710 ' Approximately 90 Seconds
DO ' Of Iterations On BS2
SEROUT TX, Baud, ["SENSE MODE...", DEC2 index / 19]
myByte = 0
HIGH HSW ' Turn Heater ON
PAUSE 15 ' For 15 mS
LOW HSW ' Turn Heater OFF
PAUSE 3 ' For 3 mS
index = index - 1 ' Decrement Counter
IF ALR = 1 THEN ' Check For Alarm Condition
DEBUG " ***ALARM***" ' Display Alarm Condition
FREQOUT 4, 2000, 3000
ELSE
DEBUG " " ' Clear Alarm Condition
ENDIF
LOOP UNTIL index = 0 ' End Of Sense Mode Loop
LOOP
I would like to use the LPG Gas Sensor Module with RN-42 Bluetooth Module to take gas readings wirelessly.
I have the example program for both but am having trouble combining these together.
Any help would be appreciated.
This is what i have so far.
'GAS SENSOR #1 - PROPANE
HSW PIN 6 ' Heater Switch Control
ALR PIN 7 ' Alarm Input Sense
index VAR Word ' Counter Variable
RX PIN 0 ' RX of the Easy Bluetooth
TX PIN 2 ' TX of the Easy Bluetooth
Baud CON 84 ' Baud set at 9600
myByte VAR Byte ' Byte to establish connection & used for workspace
PAUSE 250 ' Waits 1/4 second
SERIN RX, Baud, [myByte] ' Waiting for byte
myByte = 0 ' Clear the byte value
SEROUT TX, Baud, [ CLS] ' Send instructions to the Debug Terminal
DO
DO UNTIL myByte > 0 ' Wait until byte is valid
SERIN RX, Baud, [myByte] ' Receive byte
LOOP
HIGH HSW ' Turn Heater ON
FOR index = 59 TO 0 ' Count Down 60 Seconds
SEROUT TX, Baud, ["PURGE MODE...", DEC2 index, " "]
myByte = 0
PAUSE 1000 ' 1 Second Pause
NEXT
index = 1710 ' Approximately 90 Seconds
DO ' Of Iterations On BS2
SEROUT TX, Baud, ["SENSE MODE...", DEC2 index / 19]
myByte = 0
HIGH HSW ' Turn Heater ON
PAUSE 15 ' For 15 mS
LOW HSW ' Turn Heater OFF
PAUSE 3 ' For 3 mS
index = index - 1 ' Decrement Counter
IF ALR = 1 THEN ' Check For Alarm Condition
DEBUG " ***ALARM***" ' Display Alarm Condition
FREQOUT 4, 2000, 3000
ELSE
DEBUG " " ' Clear Alarm Condition
ENDIF
LOOP UNTIL index = 0 ' End Of Sense Mode Loop
LOOP
Comments
Hello Chris,
Thank you for your prompt response.
Yes, perhaps I chose my words incorrectly.
I have been able to test the gas sensor but only via serial connection. I would like to use the gas sensor with the RN-42 Bluetooth module (which i have also tested RX/TX capabilities independently). Basically, I would like for the information shown in the debug screen of the Gas Sensor program above to be displayed via bluetooth connection (similar to the Test Bluetooth file above but the RN-42 will only be transmitting and not receiving I think).
Eventually, I am planning to add three more gas sensor boards as well (alcohol, methane, co2) and ideally will see on the laptop debug screen if any are in "ALARM" mode.
Thank you,
Kyle
http://learn.parallax.com/project/rn-42-bluetooth-pc-demo
Thanks for your help. I was a bit confused about what to include along with SEROUT. I was able to get it to work replacing "DEBUG HOME," with "SEROUT TX, Baud, [..."
I am now attempting to display the status of all four gas sensors in the debug screen at the same time. I have also added an audio signal for the alert.
Here is my code:
HSW1 PIN 6 ' Heater 1 Switch Control
ALR1 PIN 7 ' Alarm 1 Input Sense
HSW2 PIN 8 ' Heater 2 Switch Control
ALR2 PIN 9 ' Alarm 2 Input Sense
HSW3 PIN 10 ' Heater 3 Switch Control
ALR3 PIN 11 ' Alarm 3 Input Sense
HSW4 PIN 12 ' Heater 4 Switch Control
ALR4 PIN 13 ' Alarm 4 Input Sense
TX PIN 2 ' RX of the Easy Bluetooth
index VAR Word ' Counter Variable
Baud CON 84 ' Baud set at 9600
Main:
DO
HIGH HSW1 ' Turn Heater 1 ON
HIGH HSW2 ' Turn Heater 2 ON
HIGH HSW3 ' Turn Heater 3 ON
HIGH HSW4 ' Turn Heater 4 ON
FOR index = 10 TO 0 ' Count Down 10 Seconds
SEROUT TX, Baud, [CLS, "ALCOHOL PURGE MODE...", DEC2 index,CR,
"CO2 PURGE MODE...", DEC2 index,CR,
"PROPANE PURGE MODE...", DEC2 index,CR,
"METHANE PURGE MODE...", DEC2 index]
PAUSE 1000 ' 1 Second Pause
NEXT
index = 1710 ' Approximately 90 Seconds
DO ' Of Iterations On BS2
SEROUT TX, Baud, [CLS, "ALCOHOL SENSE MODE...", DEC2 index / 19, CR,
"CO2 SENSE MODE...", DEC2 index / 19, CR,
"PROPANE SENSE MODE...", DEC2 index / 19, CR,
"METHANE SENSE MODE...", DEC2 index / 19]
HIGH HSW1 ' Turn Heater 1 ON
HIGH HSW2 ' Turn Heater 2 ON
HIGH HSW3 ' Turn Heater 3 ON
HIGH HSW4 ' Turn Heater 4 ON
PAUSE 15 ' For 15 mS
LOW HSW1 ' Turn Heater 1 OFF
LOW HSW2 ' Turn Heater 2 OFF
LOW HSW3 ' Turn Heater 3 OFF
LOW HSW4 ' Turn Heater 4 OFF
PAUSE 3 ' For 3 mS
index = index - 1 ' Decrement Counter
IF ALR1 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" ***ALCOHOL ALARM*** "] ' Display Alarm Condition
FREQOUT 4, 2000, 2000 ' Play audible alarm
PAUSE 5000 ' 5 Second Pause
ELSE
SEROUT TX, Baud, [CLS, " "] ' Clear Alarm Condition
ENDIF
IF ALR2 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" ***CO2 ALARM*** "] ' Display Alarm Condition
FREQOUT 4, 2000, 3000 ' Play audible alarm
PAUSE 5000 ' 5 Second Pause
ELSE
SEROUT TX, Baud, [CLS, " "] ' Clear Alarm Condition
ENDIF
IF ALR3 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" ***PROPANE ALARM*** "] ' Display Alarm Condition
FREQOUT 4, 2000, 4000 ' Play audible alarm
PAUSE 5000 ' 5 Second Pause
ELSE
SEROUT TX, Baud, [CLS, " "] ' Clear Alarm Condition
ENDIF
IF ALR4 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" ***METHANE ALARM*** "] ' Display Alarm Condition
FREQOUT 4, 2000, 5000 ' Play audible alarm
PAUSE 5000 ' 5 Second Pause
ELSE
SEROUT TX, Baud, [CLS, " "] ' Clear Alarm Condition
ENDIF
LOOP UNTIL index = 0 ' End Of Sense Mode Loop
LOOP
Purge mode is working correctly, but for some reason the sense mode is appearing for only a brief second before disappearing and looping back to purge mode. Any idea why this is? Also, would it be possible to display multiple "alarms" at once?
Thank you!
Thank you for the information, I did not realize that ONLY the CO gas sensor needed to be purged.
I have now been able to get all four gas sensors to work and send alarm simultaneously via Bluetooth.
I am now trying to make the Boe-Bot use the PING sensor for movement / obstacle avoidance while it transmits whether each gas sensor is in alarm condition via Bluetooth.
I feel like I am very close but when I add the code for the PING sensor, the CO gas sensor stops alerting me when the alarm condition is reached but the other gas sensors continue to work.
Here is my code:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' I / O
' =========================================================================
HSW1 PIN 6 ' Heater 1 Switch Control -- ALCOHOL
ALR1 PIN 7 ' Alarm 1 Input Sense
HSW2 PIN 8 ' Heater 2 Switch Control -- PROPANE
ALR2 PIN 9 ' Alarm 2 Input Sense
HSW3 PIN 10 ' Heater 3 Switch Control -- METHANE
ALR3 PIN 11 ' Alarm 3 Input Sense
HSW4 PIN 12 ' Heater 4 Switch Control -- CO
ALR4 PIN 13 ' Alarm 4 Input Sense
TX PIN 2 ' RX of the Easy Bluetooth
Ping PIN 15
PingServo PIN 14
LeftServo PIN 13
RightServo PIN 12
' VARIABLES
' =========================================================================
index VAR Word ' Counter Variable
Baud CON 84 ' Baud set at 9600
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
' MAIN
' =========================================================================
Main:
DO
HIGH HSW1 ' Turn Heater 1 ON
HIGH HSW2 ' Turn Heater 2 ON
HIGH HSW3 ' Turn Heater 3 ON
HIGH HSW4 ' Turn Heater 4 ON
FOR index = 10 TO 0 ' Count Down 10 Seconds
SEROUT TX, Baud, [CR,CR, "ALCOHOL SENSE MODE "]
IF ALR1 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** ALCOHOL ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 2000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["METHANE SENSE MODE "]
IF ALR2 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** METHANE ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 3000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["PROPANE SENSE MODE "]
IF ALR3 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** PROPANE ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 4000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["CO PURGE MODE...", DEC2 index]
PAUSE 1000
NEXT
HIGH HSW1 ' Turn Heater 1 ON
HIGH HSW2 ' Turn Heater 2 ON
HIGH HSW3 ' Turn Heater 3 ON
FOR index = 10 TO 0 ' Count Down 10 Seconds
SEROUT TX, Baud, [CR,CR, "ALCOHOL SENSE MODE "]
IF ALR1 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** ALCOHOL ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 2000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["METHANE SENSE MODE "]
IF ALR2 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** METHANE ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 3000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["PROPANE SENSE MODE "]
IF ALR3 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** PROPANE ALARM *** ", CR] ' Display Alarm Condition
FREQOUT 4, 2000, 4000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" ", CR] ' Clear Alarm Condition
ENDIF
SEROUT TX, Baud, ["CO SENSE MODE...", DEC2 index]
HIGH HSW4 ' Turn Heater 4 ON
PAUSE 15 ' For 15 mS
LOW HSW4 ' Turn Heater 4 OFF
PAUSE 3 ' For 3 mS
IF ALR4 = 1 THEN ' Check For Alarm Condition
SEROUT TX, Baud, [" *** CO ALARM *** "] ' Display Alarm Condition
FREQOUT 4, 2000, 5000 ' Play audible alarm
ELSE
SEROUT TX, Baud, [" "] ' Clear Alarm Condition
ENDIF
PAUSE 1000
NEXT
LOOP
' SUBROUTINES
' =========================================================================
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 3
PULSOUT LeftServo, 750
PULSOUT RightServo, 750
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 650
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
I want to insert the code below after the second FOR statement above so that the Boe-Bot explores using PING sensor only when all gas sensors are in SENSE mode.
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 550 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
For some reason when I add the code for the PING sensor, the CO gas sensor stops alerting me when the alarm condition is reached but the other gas sensors continue to work.
Thank you!