Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Parijat Kundu
Published © GPL3+

LPG gas detecting and alerting system using BOLT IOT

This project uses Internet of Things technology to detect and alert LPG gas leakage.

IntermediateShowcase (no instructions)5 hours1,552
LPG gas detecting and alerting system using BOLT IOT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Buzzer
Buzzer
×1
PHPoC Bread Board
PHPoC Bread Board
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
DIGITAL OCEAN
Mailgun - Email Api

Story

Read more

Schematics

Circuit connections

The BOLT IOT MODULE has 5 GPIO pins from 0 to 4 and 1 analog pin A0 . The GND of the BOLT IOT is connected to the BREAD BOARD to which the GND of the GAS SENSOR is further connected. Similarly the VCC and A0 pin are connected together. Now for the buzzer the positive terminal is connected to the GPIO pin 1 and negative terminal to the GND of the BREAD BOARD.

Code

LPG gas detecting and alerting code

Python
import gas1
from boltiot import Sms, Bolt,Email
import json, time
import requests


maximum_limit =800


mybolt = Bolt(gas1.API_KEY, gas1.DEVICE_ID)
sms = Sms(gas1.SID, gas1.AUTH_TOKEN, gas1.TO_NUMBER, gas1.FROM_NUMBER)
mailer = Email(gas1.MAILGUN_API_KEY, gas1.SANDBOX_URL, gas1.SENDER_EMAIL, gas1.RECIPIENT_EMAIL)






while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') 
    data = json.loads(response) 
    print("Sensor value is: " + str(data['value']))
    my = Bolt(gas1.API_KEY, gas1.DEVICE_ID)
    res = my.digitalWrite('1', 'LOW')
    print(res)

    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit:
            my = Bolt(gas1.API_KEY, gas1.DEVICE_ID)
            res = my.digitalWrite('1', 'HIGH')
            print(res)

            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("There is a gas leakage and the current gas sensor value is " +str(sensor_value))

            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))


  
            print("Making request to Mailgun to send an email")
            response = mailer.send_email("Alert", "There is a gas leakage and the current gas sensor value is " +str(sensor_value))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
 

        except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

Credits

Parijat Kundu

Parijat Kundu

1 project • 6 followers

Comments