Fire Alarm Working Sample Based On IoT

Introduction

 
This article demonstrates how to make a fire alarm working sample based on IoT using Pushetta Service, working with MQ2 Gas Sensor. The MQ-2 Gas Sensor module detects a gas leak in the home and industry. They are sensitive to a range of gases and are used indoors at room temperature. The output is an analog signal and can be read with an analog input of the Raspberry Pi. 
 
Pushetta 
 
Pushetta is made to make it simple to broadcast communications to groups of subscribers. It works in a really simple way: As a publisher, you create a thematic group and every user that subscribes to this group receives a notification every time you push a message. It can be compared to SMS with many advantages.
 
Installation
 
You can learn Raspberry Pi installation from my previous article.
 
Pin Diagram 
 
Send A Notification When On Mq2 Gas Sensor Detection 
 
Step 1
 
First, go to the Pushetta website "http://www.pushetta.com/my/dashboard " and then log into this site to get the API.
 
Send A Notification When On Mq2 Gas Sensor Detection 
 
After that, create a new channel for subscribers. This channel is used to identify my API. I have already created and subscribed to my channel "RaviIoT".
 
Send A Notification When On Mq2 Gas Sensor Detection 
 
Step 2
 
Next, go to install the mobile app "https://play.google.com/store/apps/details?id=com.gumino.pushetta". Go to the search bar to search for the channel name and click the subscribe button.
 
Send A Notification When On Mq2 Gas Sensor Detection 
 
Step 3
 
Open the python IDE 3.0, File >> New save the name as gas.py, then follow the given code.
 
Syntax 
 
 {
sendNotification ("Your API","Channel Name","Alert Message")
 }
  1. sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7""RaviIoT""Ravi your home leaked out the LPG Gas be alert !!!!!")  
Full Package Code
  1. import RPi.GPIO as GPIO  
  2. import time  
  3. import urllib2  
  4. import json  
  5.   
  6. GPIO.setmode(GPIO.BCM)  
  7. GPIO.setwarnings(False)  
  8.   
  9. GPIO.setup(26, GPIO.IN)  
  10. #GPIO.setup(3, GPIO.OUT)  
  11.   
  12. def sendNotification(token, channel, message):  
  13.  data = {  
  14.   "body" : message,  
  15.   "message_type" : "text/plain"  
  16.  }  
  17.   
  18.  req = urllib2.Request('http://api.pushetta.com/api/pushes/{0}/'.format(channel))  
  19.                          
  20.  req.add_header('Content-Type''application/json')  
  21.  req.add_header('Authorization''Token {0}'.format(token))  
  22.   
  23.  response = urllib2.urlopen(req, json.dumps(data))  
  24.   
  25. while True:  
  26.               
  27.             i=GPIO.input(26)  
  28.             if i==0:                 #When output from LPG sensor is LOW  
  29.                 print("No Gas Leakage Detected",i)  
  30.                 #GPIO.output(3, 0)  #Turn OFF LED  
  31.                 time.sleep(0.5)  
  32.             elif i==1:               #When output from LPG sensor is HIGH  
  33.                 #print("Intruder detected",i)  
  34.                 print("LPG Detect",i)  
  35.                 sendNotification("7230ffbdd10f0db0a740a6b3865f9082105e58d7""RaviIoT""Ravi your home leaked out the LPG Gas be alert!)
  36.                 #GPIO.ocdutput(3, 1)  #Turn ON LED  
  37.                 time.sleep(0.5)           
  38.           
Raspberry Pi and Mq2 Sensor Connection
 
Send A Notification When On Mq2 Gas Sensor Detection 
 
Step 4
 
Next, we need to update the Raspberry Pi. So, install the latest packages. You can do that using the following commands.
  1. sudo apt-get update  
  2. sudo apt-get upgrade  
  3. sudo apt-get install python3  
Run the program,
  1. sudo python Program/gas/gas.py  
Send A Notification When On Mq2 Gas Sensor Detection
 
When the sensor is detected immediately send the alert notification to channel subscribers.
 
Send A Notification When On Mq2 Gas Sensor Detection
 
Output 
 
Get alert notifications. The alert message is Ravi your home leaked out the LPG Gas be alert !!! 
 
Send A Notification When On Mq2 Gas Sensor Detection
 

Summary

 
Finally, we have successfully sent a notification for an mq2 gas sensor detection using Pushetta.