hello peeps. im using raspberry pi 3 b+. and im doing a fire and gas detection project by using ir flame sensor and mq5 gas sensor. my project also have 2 outputs which are buzzer and fan.
i’ll be needed to use blynk for the iot application. i need help anyone to edit my coding so that when my ir flame sensor detect fire, my labeled value showing high and if not detect fire it will show low. same goes with my gas sensor. and then, i need to put 2 button for on and off my buzzer and fan manually. please anyone help me with my coding. much appreciated.
import RPi.GPIO as GPIO
import time
import sys
import signal
#import picamera
import blynklib
frame=1
channel=25
channel2=18
#camera=picamera.PiCamera()
BLYNK_AUTH='QbOZRQporo7sF4B_U8brb_cKb1e699d5'
blynk=blynklib.Blynk(BLYNK_AUTH)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel,GPIO.IN)
GPIO.setup(channel2,GPIO.IN)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
def firee(channel):
if FlameSensor == 1:
global frame
GPIO.output(4,1)
print("Gaiss!! API Gaiss!! APIIII!!")
time.sleep(5)
#camera.start_recording('/home/pi/Desktop/psm/Frame %d.h264'%frame)
#time.sleep(3)
#camera.stop_recording()
#print("Video Frame %d Recorded!"%frame)
#frame+=1
GPIO.output(4,0)
time.sleep(1)
else:
time.sleep(1)
GPIO.add_event_detect(channel,GPIO.BOTH,bouncetime=300)
GPIO.add_event_callback(channel,firee)
def gass(channel2):
if GasSensor == 1:
GPIO.output(4,1)
GPIO.output(17,1)
print("Gaiss!! GAS Gaiss!! GASSSS!!")
time.sleep(5)
GPIO.output(4,0)
GPIO.output(17,0)
time.sleep(1)
else:
time.sleep(1)
GPIO.add_event_detect(channel2,GPIO.BOTH,bouncetime=300)
GPIO.add_event_callback(channel2,gass)
while True:
blynk.run()
FlameSensor=GPIO.input(channel)
GasSensor=GPIO.input(channel2)
print("Save Environment :)")
time.sleep(2)