Project Report:
Smoke and natural gas detector (notification on mobile app)
Submitted From
Adnan Nasir (17139019)
Hassan Ali Butt (17139023)
Ubaid Ullah (17139029)
Supervisor:
Sir Muneeb Abrar
Introduction
Pakistan is a developing country. Here people are advancing their lives by every means but
while doing this they often neglect safety measures even there, where they shouldn’t. Like the
one we are trying to compensate.
In Pakistan there are great resources of natural gases , and in many places people use other
means like wood & cylinders too where natural gas isn’t available. Especially in Northern Areas
of Pakistan where in winters temperature drops up to -10. But the thing is both this things are
silent killers too.
Smoke contains carbon monoxide, carbon dioxide, nitrogen oxide, irritant volatile organic
compounds, air toxics and very small particles. All these elements together suffocate a human to death
in sleep without even realizing its victim that something is wrong.
Same kind of dangers are attach with natural gas too. In Natural Gas most prominent element is
Methane (CH4). That is a combustible gas and responsible for most of the explosions occur in houses
and gas leakage is not just a problem of Pakistan but a worldwide problem. Like a person is out and
somehow gas leakage occurs, they return home lights a bulb and BOOOOM!
So these were the factors that were in our mind while choosing this project. To make a safety system
that is affordable as well as easy to install in houses, schools and anywhere where it is necessary.
Project Objectives:
1) Make a system that can detect Natural Gas and Smoke
2) It uses Wi-Fi to send a msg to the mobile of user once it detects anything no matter where
ever user is.
3) It triggers alarm once it sense anything and keep ringing until leakage is fixed.
4) It should be able to Power on Water Shower (If necessary)
5) It should be cheap and easy to install.
Components Used
1) PIC 18F452
2) NodeMCU
3) MQ2 (Smoke Sensor)
4) MQ5 (Gas Sensor)
5) 6V Relay’s
6) ULN2003AN
7) Buzzer
1) PIC 18F452
PIC (usually pronounced as "pick") is a family of microcontrollers made by Microchip Technology,
originally developed by General Instrument's Microelectronics Division. The name PIC initially referred
to Peripheral Interface Controller and is currently expanded as Programmable Intelligent Computer. We
are here using PIC18 family and using MPLAB IDE v8.92.
2) NodeMCU
The NodeMCU (Node Microcontroller Unit) is an open source software and hardware development
environment that is built around a very inexpensive System-on-a-Chip (SoC) called the ESP8266.It is an
open form of IoT.It is a type of Arduino and use the same compiler to do its programming The
ESP8266, designed and manufactured by Espressif Systems, contains all crucial elements of the
modern computer: CPU, RAM, networking (Wi-Fi), and even a modern operating system and SDK.
3) MQ5 (Smoke Sensor)
The Grove - Gas Sensor (MQ2) module is useful for gas leakage detection (home and industry). It is
suitable for detecting H2, LPG, CH4, CO, Alcohol or Propane. Due to its high sensitivity and fast response
time, measurement can be taken as soon as possible. The sensitivity of the sensor can be adjusted by
potentiometer.
4) MQ2 (Gas Sensor)
MQ2 is another sensor of MQ sensor series. It is can detect smoke of any kind around its surroundings
and its sensitivity can also be changed and adjusted
5) 6V Relay’s
Relay is an electromechanical device to control Electrical Circuits. It works on DC power and can be used
to control AC or DC power sources.
7) ULN2003A
The ULN2003 is known for its high-current, high-voltage capacity. The drivers can be paralleled for even
higher current output. Even further, stacking one chip on top of another, both electrically and physically,
has been done .We are using it here to prevent our relays from back EMF.
Block Diagram
Working
Project consists of 3 Parts
1) Input from sensors
2) PIC18 Reading data and giving NodeMCU Further Signal
3) NodeMCU sending massage
Input from sensors;
The primary or starting point of Project are sensors. Sensors take input from room or wherever they are
planted. We are taking Digital output from them and it is acting as Input for PIC18. Sensor can work on
two ways.
1) Give 5V on conducting and 0V on normal conditions
2) Give 0V on conducting and 5V on normal conditions
We are using 2nd form our sensors are normally on 5V but when they sense anything like smoke or gas it
gives 0V that act as input for PIC18 that perform further functions.
PIC18 Reading data and giving NodeMCU Further Signal
PIC18 receive digital signal from sensors. We are using its PORTB as Input from Sensors and PORTC as
Output that will give further signal to NodeMCU. PIC18 has the code that compare and make decision
that weather give signal to NodeMCU to send text Msg to Phone or not. If sensors are not detecting
anything PIC will receive 5V means logic 1. When sensors sense anything like smoke or gas it will receive
logic 0 thus will instantly trigger alarm and tell NodeMCU to send msg.PIC18 is the master.
NodeMCU sending massage
NodeMCU is our Wi-Fi module and it is responsible for communication between our project and Phone
on any location. We are using Blynk app for that.
NodeMCU is the slave microcontroller that depends upon PIC18. While programming it we need to
enter Wi-Fi name and its code. WiFi source can only be changed with programming.
Proteus Simulation
Breadboard Patching
Final Look
Power Calculation
Both Microcontrollers operate on 5V DC. We have separate supply for it. 5V and 1A.
Power =5Vx1A=5W
5W/1000=0.005 per hour Unit consumption
0.005x24=0.12 per day Unit consumption
Cost:
Sr. No. Product Quantity Prize
1 PIC18F452 1 700
2 NodeMCU 1 450
3 MQ2 1 250
4 MQ5 1 250
5 Resistors 5 2
6 6V Relay 3 3*35=105
7 Buzzer 1 100
8 Supply 12V 2A 1 130
9 Supply 5V 1A 1 150
10 ULN2003AN 1 35
Total = 2172/-
Code(For PIC18F452)
#include<p18f452.h>
#pragma config OSC = XT
#pragma config WDT = OFF
#pragma config OSCS=OFF
#define MQ2 PORTBbits.RB0
#define MQ5 PORTBbits.RB1
#define OP PORTCbits.RC0
#define OP1 PORTCbits.RC1
#define OP2 PORTCbits.RC2
void Tdelay(void);
void main(void)
{
unsigned int i=0;
TRISBbits.TRISB0=1;
TRISBbits.TRISB1=1;
TRISCbits.TRISC0=0;
TRISCbits.TRISC1=0;
TRISCbits.TRISC2=0;
while(1)
{
if(MQ2==0)
{OP1=1;
OP=1;
}
for(i=0;i<3;i++)
Tdelay();
if(MQ5==0)
{
OP2=1;
OP=1;
}
for(i=0;i<3;i++)
Tdelay();
OP1=0;
OP2=0;
OP=0;
Tdelay();
}
}
void Tdelay(void)
{
T0CON=0x05;
TMR0H=0x83;
TMR0L=0xD6;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;
}
Code For NodeMCU
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "e6d9vOa43g7D1gJCvSO2L-cPFGnhGPzb";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "GIFT-FMGT";
char pass[] = "";
void setup()
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D5,INPUT);
pinMode(D6,INPUT);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
Blynk.run();
int s1 = digitalRead(D5);
int s2 = digitalRead(D6);
Serial.println(s1);
Serial.println(s2);
delay(1000);
if (s1== HIGH)
{Serial.print("hi");
Blynk.notify("Alert! Smoke or Gas Leakage in Room1.");
// Serial.print("Alert! Smoke or Gas Leakage in Room1.");
if(s2 ==HIGH)
Serial.print("ooh");
Blynk.notify("Alert! Smoke or Gas Leakage in Room2.");
// Serial.print("Alert! Smoke or Gas Leakage in Room2.");