Naveenkumar Paramasivam
Published

Home Safety Alert System Using Bolt IoT

This main purpose of this project is to protect your home from any LPG gas leakage and fire accidents.

AdvancedProtip7 hours1,262
Home Safety Alert System Using Bolt IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Arduino UNO
Arduino UNO
×1
Arduino Mega 2560
Arduino Mega 2560
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Gravity: Analog Flame Sensor For Arduino
DFRobot Gravity: Analog Flame Sensor For Arduino
×1
Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Relay module
×1
Jumper wires (generic)
Jumper wires (generic)
×10
Buzzer
Buzzer
×1
Axial Fan, 12 VDC
Axial Fan, 12 VDC
×1
9V battery (generic)
9V battery (generic)
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Packing box
Use to build a sample home in this project
×1
Mini steel rod
Used to open and close windows attach with servo motor
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Arduino IDE
Arduino IDE
SMS Messaging API
Twilio SMS Messaging API
Mailgun
Python IDLE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering
Tape, Double Sided
Tape, Double Sided

Story

Read more

Schematics

Circuit Full Sketch

Code

Arduino_mega_2560_code

Arduino
This code used to get sensor values and control the relay module to turn on and of the exhaust motor. Its enables the digital signal to both Arduino UNO and Bolt Module.
//Home Safety Alert System Using Bolt IoT
#include<Servo.h>
#define MQ2_Gas_sensor A0
#define Flame_sensor 8
#define Relay_pin 7
#define servo_pin 6
#define buzzer 9
#define bolt_communication_pin_for_Gasleak 11
#define bolt_communication_pin_for_fire_detection 12
#define servo_close_position 150
#define servo_open_position 80
void setup() {
  Serial.begin(115200);
  Serial.println("Servo postion Ok...");
  pinMode(Flame_sensor,INPUT);
  pinMode(Relay_pin,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(servo_pin,OUTPUT);
  pinMode(bolt_communication_pin_for_Gasleak,OUTPUT);
  pinMode(bolt_communication_pin_for_fire_detection,OUTPUT);
  Serial.println("System Ready.....");
}
void loop() {
int gas_value = analogRead(MQ2_Gas_sensor);
int flame_is_available =digitalRead(Flame_sensor);
Serial.print("Gas value:");
Serial.println(gas_value);
if((gas_value >= 150)||(flame_is_available == LOW)){
if(gas_value >= 150){
if(flame_is_available == LOW){
digitalWrite(bolt_communication_pin_for_Gasleak,HIGH);
digitalWrite(bolt_communication_pin_for_fire_detection,HIGH);
Serial.println("Gas and Fire leakage detected");
alert_system_control_activate();
}
else{
digitalWrite(bolt_communication_pin_for_Gasleak,HIGH);
digitalWrite(bolt_communication_pin_for_fire_detection,LOW);
Serial.println("Gas leakage detected");
alert_system_control_activate();
}}
else if(flame_is_available == LOW){
if(gas_value >= 150)
{
digitalWrite(bolt_communication_pin_for_Gasleak,HIGH);
digitalWrite(bolt_communication_pin_for_fire_detection,HIGH);
Serial.println(" Fire and Gasleakage detected");
alert_system_control_activate();
      }
      else{
      digitalWrite(bolt_communication_pin_for_fire_detection,HIGH);
       digitalWrite(bolt_communication_pin_for_Gasleak,LOW);
      alert_system_control_activate();
     Serial.println(" Firedetected");
      }}}
  else
  {
    Serial.println("No Thread can be detected inside of your home");
alert_system_control_deactivate();
    }
    delay(4000);
    }
void alert_system_control_activate()
{
  digitalWrite(Relay_pin,LOW);
  digitalWrite(buzzer,HIGH);
  digitalWrite(servo_pin,HIGH);
}
void alert_system_control_deactivate()
{
  digitalWrite(Relay_pin,HIGH);
  digitalWrite(buzzer,LOW);
 digitalWrite(servo_pin,LOW);
 digitalWrite(bolt_communication_pin_for_Gasleak,LOW);
    digitalWrite(bolt_communication_pin_for_fire_detection,LOW);
}

Arduino_uno_code

Arduino
This code can reads digital signal from arduino Mega board. if digital signal is enable, servo motor direction will be changed to open our home windows.
#include<Servo.h>
#define servo_pin 6
#define servo_signal 7
Servo windowservo;
void setup() { 
Serial.begin(9600);
pinMode(servo_signal,INPUT);
windowservo.attach(servo_pin);
}
void loop() {
 int signal_value = digitalRead(servo_signal);
if(signal_value == HIGH)
{
   windowservo.write(180);
   Serial.println("Motor Open Mode Activated");
}
else
{
  windowservo.write(80);
   Serial.println("Motor Close Mode Activated");
}}

Python_code_configuration_file

Python
This python code file contains an API keys,SSID and all related codes are written in this file
MAILGUN_API_KEY='7b29xxxxxxe63538f42ecbace6xxxxxx-e470a504-bf4705ea' #Get from mailgun website

SANDBOX_URL='sandbox049xxxxxx6cd475fbbfe59xxxxxx61b6.mailgun.org' #Get from mailgun website

SENDER_EMAIL='test@sandxxxxxxcd53b46cd475fbbfe5922eaxxxxxx.mailgun.org' #get from mailgun website

RECIPIENT_EMAIL='naveenxxx@gmail.com' #Alert Receiving mail Id

API_KEY='5075xxxx-4cae-xxxx-xxxx-976037c8xxxx' #Get from bolt site

SID='AC135b0xxxx72bdf977xxxx24f95c49xxxx' # Get from twilio

AUTH_TOKEN='a145xxxx513f8030a54ef9f85c50xxxx' # Get from twilio

FROM_NUMBER='+19712642984' # this number get from twilo website

TO_NUMBER='+9179xxxxxx99' # Enter your Mobile number to receive SMS

DEVICE_ID='BOLT564xxxx' # Your  

Python_code_to_send_alert_message

Python
This python code will be run on Linux VPS server, it send an alert message through SMS and Email.
import safety_system_config
from boltiot import Email,Bolt,Sms
import json,time
mybolt = Bolt(safety_system_config.API_KEY,safety_system_config.DEVICE_ID)
mailer = Email(safety_system_config.MAILGUN_API_KEY,safety_system_config.SANDBOX_URL,safety_system_config.SENDER_EMAIL,safety_system_config.RECIPIENT_EMAIL)
sms = Sms(safety_system_config.SID,safety_system_config.AUTH_TOKEN,safety_system_config.TO_NUMBER,safety_system_config.FROM_NUMBER)
print(safety_system_config.MAILGUN_API_KEY)
print(safety_system_config.SANDBOX_URL)
print(safety_system_config.SENDER_EMAIL)
print(safety_system_config.RECIPIENT_EMAIL)
while True:
    print("Getting Signal from Arduino Micro controller")
    gas_response=mybolt.digitalRead('1')
    flame_response=mybolt.digitalRead('2')
    gas_data=json.loads(gas_response)
    flame_data=json.loads(flame_response)
    print("Gas Response is :"+str(gas_data['value']))
    print("Flame Response is :"+str(flame_data['value']))
    try:
        gas_signal_value=int(gas_data['value'])
        flame_signal_value=int(flame_data['value'])
        if (gas_signal_value == 1) or (flame_signal_value == 1):
            if gas_signal_value == 1 :
                if flame_signal_value == 1:
                    print("Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to mailgun to send a Email")
                    response1=sms.send_sms("Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to Twilo to send a Email")
                    response2=mailer.send_email("Alert","Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                else:
                    print("Gas Leaking Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to mailgun to send a Email")
                    response1=sms.send_sms("Gas Leaking Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to Twilo to send a Email")
                    response2=mailer.send_email("Alert","Gas Leaking Detected in your Home \n Go and visit your Home Immidietly")
            elif flame_signal_value == 1:
                if gas_signal_value == 1:
                    print("Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to mailgun to send a Email")
                    response1=sms.send_sms("Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to Twilo to send a Email")
                    response2=mailer.send_email("Alert","Gas Leaking and Fire Detected in your Home \n Go and visit your Home Immidietly")
                else:
                    print("Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to mailgun to send a Email")
                    response1=sms.send_sms("Fire Detected in your Home \n Go and visit your Home Immidietly")
                    print("Making Request to Twilo to send a Email")
                    response2=mailer.send_email("Alert","Fire Detected in your Home \n Go and visit your Home Immidietly")
        else:
            print("Your Home is Safe\n")   
    except Exception as e:
        print("Unexpected Error Accoured in our safety system")


    time.sleep(20)
            
            

Credits

Naveenkumar Paramasivam

Naveenkumar Paramasivam

1 project • 1 follower
My specific area of interest is in Android app development, IoT, Cloud Computing and Salesforce.

Comments