Monitor Your Room/Office Safe From Fire or Not on Desktop

Monitor Your Room/Office Safe From Fire or Not on Desktop © CC BY

Using Wemos D1, GSM module, MQ5/MQ6 sensor and IoT platform (ThingsIO.AI). Here it will give message on your phone also when fire detected.

  • 185 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

Using Wemos D1, GSM Module, MQ5/MQ6 Sensor and IoT platform (ThingsIO.AI).

Here it will give message on your phone also when fire detected.

YouTube: https://youtu.be/_Ejhi311fj0

Wemos D1 :

Features

  • 11 digital input/output pins, all pins have interrupt/pwm/I2C/one-wire supported(except for D0)
  • 1 analog input(3.2V max input)
  • Micro USB connection
  • Power jack, 9-24V power input.
  • Compatible with Arduino
  • Compatible with nodemcu

Technical specs

Microcontroller --> ESP-8266EX

Operating Voltage --> 3.3V

Digital I/O Pins --> 11

Analog Input Pins --> 1(Max input: 3.2V)

Clock Speed --> 80MHz/160MHz

Flash --> 4M bytes

Length --> 68.6mm

Width --> 53.4mm

Weight --> 25g

Pin

Pin | Function | ESP-8266

TX | TXD | TXD

RX | RXD | RXD

A0 | Analog input, max 3.3V input | A0

D0 | IO | GPIO16

D1 | IO, SCL | GPIO5

D2 | IO, SDA | GPIO4

D3 | IO, 10k Pull-up | GPIO0

D4 | IO, 10k Pull-up, BUILTIN_LED | GPIO2

D5 | IO, SCK | GPIO14

D6 | IO, MISO | GPIO12

D7 | IO, MOSI | GPIO13

D8 | IO, 10k Pull-down, SS | GPIO15

G | Ground | GND

5V | 5V | -

3V3 | 3.3V | 3.3V

RST | Reset | RST

GSM :

GSM is a mobile communication modem; it is stands for global system for mobile communication (GSM). The idea of GSM was developed at Bell Laboratories in 1970. It is widely used mobile communication system in the world. GSM is an open and digital cellular technology used for transmitting mobile voice and data services operates at the 850MHz, 900MHz, 1800MHz and 1900MHz frequency bands.

GSM system was developed as a digital system using time division multiple access (TDMA) technique for communication purpose. A GSM digitizes and reduces the data, then sends it down through a channel with two different streams of client data, each in its own particular time slot. The digital system has an ability to carry 64 kbps to 120 Mbps of data rates.

GSM Modem

There are various cell sizes in a GSM system such as macro, micro, pico and umbrella cells. Each cell varies as per the implementation domain. There are five different cell sizes in a GSM network macro, micro, pico and umbrella cells. The coverage area of each cell varies according to the implementation environment.

Features of GSM Module:

  • Improved spectrum efficiency
  • International roaming
  • Compatibility with integrated services digital network (ISDN)
  • Support for new services.
  • SIM phonebook management
  • Fixed dialing number (FDN)
  • Real time clock with alarm management
  • High-quality speech
  • Uses encryption to make phone calls more secure
  • Short message service (SMS)

MQ5 --> LPG, Natural Gas, Town Gas :

Features

  • Wide detecting scope
  • Stable and long life
  • Fast response and High sensitivity

Relay :

This is a LOW Level 5V 2-channel relay interface board, and each channel needs a 15-20mA driver current. It can be used to control various appliances and equipment with large current. It is equiped with high-current relays that work under AC250V 10A or DC30V 10A. It has a standard interface that can be controlled directly by microcontroller.

Features

  • Relay Maximum output: DC 30V/10A, AC 250V/10A
  • 2 Channel Relay Module with Optocoupler LOW Level Triger expansion board, which is compatible with arduino
  • Standard interface that can be controlled directly by microcontroller ( 8051, AVR, *PIC, DSP, ARM, ARM, MSP430, TTL logic)
  • Relay of high quality loose music relays SPDT. A common terminal, a normally open, one normally closed terminal
  • optocoupler isolation, good anti-jamming

Input:

VCC : Connected to positive supply voltage (supply power according to relay voltage)

GND : Connected to negative supply voltage

IN1: Signal triggering terminal 1 of relay module

IN2: Signal triggering terminal 2 of relay module

Output:

Each submodular of the relay has one NC(nomalclose), one NO(nomalopen) and one COM(Common). So there are 2 NC, 2 NO and 2 COM of the channel relay in total. NC stands for the normal close port contact and the state without power; No stands for the normal open port contact and the state with power. COM means the common port. You can choose NC port or NO port according to whether power or not.

Code

CodeArduino
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include "WiFiManager.h"          //https://github.com/tzapu/WiFiManager

int sms_count=0;
int redLed = D5;
int buzzer = D6;
int smokeA0 = A0;
// Your threshold value
int sensorThres = 60;
int openclose = 0;
int redled = 0;

int count=0,i,m,j,k;


//////////////////////////////////////// ALL DECLARATIONS for CLOUD //////////////////////////////
const char* host = "api.thingsio.ai";                                 // OR host = devapi2.thethingscloud.com
const char* post_url = "/devices/deviceData";       // OR /api/v2/thingscloud2/_table/data_ac
const char* time_server = "baas.thethingscloud.com";             //this is to convert timestamp
const int httpPort = 80;

char timestamp[10];

WiFiClient client;
  


/////////////////////////////////////////////////////////////////////////////////////////////////////////
void configModeCallback (WiFiManager *myWiFiManager) 
{
  Serial.println("Entered config mode");             //*-*-*-*-*-*-*-*-*-*-*-*-*-*if control enters this function then net is not connected
  Serial.println(WiFi.softAPIP());                  // "WiFi.softAPIP() is for AP" , "WiFi.localIP() is for STA",
                                                                
  Serial.println(myWiFiManager->getConfigPortalSSID());             //if you used auto generated SSID, print it
}
/////////////////////////////////////// TIMESTAMP CALCULATION function///////////////////////////////////////
int GiveMeTimestamp()
{
  unsigned long timeout = millis();

  while (client.available() == 0)
  {
    if (millis() - timeout > 50000)
    {
      client.stop();
      return 0;
    }
  }

while (client.available())
      {
        String line = client.readStringUntil('\r');                    //indexOf() is a funtion to search for smthng , it returns -1 if not found
        int pos = line.indexOf("\"timestamp\"");                       //search for "\"timestamp\"" from beginning of response got and copy all data after that , it'll be your timestamp
        if (pos >= 0)                                                     
        {
          int j = 0;
          for(j=0;j<10;j++)
          {
            timestamp[j] = line[pos + 12 + j];
          }
        }
      }
}  
////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() 
{
  Serial.begin(115200);     //(19200,SERIAL_8E1) - data size = 8 bits , parity = Even , stop bit =  1bit
  mySerial.begin(115200);
  WiFiManager wifiManager;
 
  wifiManager.setAPCallback(configModeCallback);
                                                                                                    
  if(!wifiManager.autoConnect("DDIK Makadia","kidd123456789"))                   //wifiManager.autoConnect("AP-NAME", "AP-PASSWORD"); (OR) wifiManager.autoConnect("AP-NAME"); only ID no password (OR) wifiManager.autoConnect(); this will generate a ID by itself
  {
    Serial.println("failed to connect and hit timeout");     //control comes here after long time of creating Access point "NodeMCU" by NodeMCU and still it has not connected
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  } 

  //if you come here you have connected to the WiFi
  Serial.println("connected...");

  pinMode(redLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  delay(500);
 
}

void loop() 
{
  
/////////////////////////////////////// SEND THE QUERY AND RECEIVE THE RESPONSE///////////////////////  
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  
  if (analogSensor > sensorThres)
  {
    digitalWrite(redLed, HIGH);
    openclose = 1;
    redled=1;
    tone(buzzer, 4000, 400);
    if(sms_count<=1)
    {
      mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
      delay(1000);
      mySerial.println("AT+CMGS=\"+91xxxxxxxxxxx\"\r"); // change to the phone number you using 
      delay(1000);
      mySerial.println("Gas Leaking!");//the content of the message
      delay(200);
      mySerial.println((char)26);//the stopping character
      delay(1000);
      mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // change to the phone number you using 
      delay(1000);
      mySerial.println("Gas Leaking!");//the content of the message
      delay(200);
      mySerial.println((char)26);//the message stopping character
      delay(1000);
      sms_count++;
    }
    else
    {
      mySerial.println("Nothing Happen");
    }
  }
  else
  {
    digitalWrite(redLed, LOW);
    noTone(buzzer);
    openclose = 0;
    redled=0;
  }
  delay(100);
  
  Serial.println("connecting to ");
  Serial.println(host);                          //defined upside :- host = devapi2.thethingscloud.com or 139.59.26.117

///////////////////////////////////// TIMESTAMP CODE SNIPPET /////////////////////////
  Serial.println("inside get timestamp\n");
  if (!client.connect(time_server, httpPort)) 
  {
    return;                                                        //*-*-*-*-*-*-*-*-*-*
  }

  client.println("GET /api/timestamp HTTP/1.1");                            //Whats this part doing, i didnt get
  client.println("Host: baas.thethingscloud.com");
  client.println("Cache-Control: no-cache");
  client.println("Postman-Token: ea3c18c6-09ba-d049-ccf3-369a22a284b8");
  client.println();

  GiveMeTimestamp();                        //it'll call the function which will get the timestamp response from the server
  Serial.println("timestamp receieved");
  Serial.println(timestamp);
///////////////////////////////////////////////////////////////////////////////

// Use WiFiClient class to create TCP connections
  if (!client.connect(host, httpPort))            //host = devapi2.thethingscloud.com , port = 80
  {
    Serial.println("connection failed");                  // *-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-
    return;
  }
  
  client.print("Content-Length: ");
  client.println(); 

  unsigned long timeout = millis();
  while (client.available() == 0) 
  {
    if (millis() - timeout > 50000) 
    {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  Serial.println("***********************************************");
  Serial.println();
  Serial.println("closing connection");

  Serial.println("inside ThingsCloudPost");
  int timestamp1 =0;
  timestamp1 = 1542800778;
 
  String PostValue = "{\"device_id\":  xxxxxx, \"slave_id\": 1";
  PostValue = PostValue + ",\"dts\":" +timestamp;
  PostValue = PostValue +",\"data\":{\"Water Flow\":" + openclose +",\"Led On=1/Off=0\":" + redled +"}"+"}";
    
  Serial.println(PostValue);

//////////////////////////////// try to connect to server again and POST the data on the cloud //////////////////////////
  if (!client.connect(host, httpPort)) 
  {
    return;
  }

  client.print("POST ");
  client.print(post_url);               /// POST api/device-datas         HTTP/1.1     Host: baas.thethingscloud.com      Content-Type: application/json        Cache-Control: no-cache
  client.println(" HTTP/1.1");           //Authorization:          Content-Length: 
  client.print("Host: ");
  client.println(host);
  client.println("Content-Type: application/json");
  client.println("Cache-Control: no-cache");
  client.print("Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IjViZTc5ZjRiNDAyYjlkNGI5MDdiZGRmZCI.hBa2XTagbf56p_E83PeMZHaoJO4EUrbwGcmWTU0j0-w");
  client.println();
  client.print("Content-Length: ");
  client.println(PostValue.length());
  client.println();
  client.println(PostValue);
  
//////////////////////////////////POSTING the data on to the cloud is done and now get the response form cloud server//////////////////
  while (client.available() == 0) 
  {
    if (millis() - timeout > 50000) 
    {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  Serial.println("Response From Server");
  while(client.available())
  { 
    String line2 = client.readStringUntil('\r');   
    Serial.print(line2);
    
  }
    
  Serial.println("//////////////////////    THE END     /////////////////////");
  delay(3000);
  
}

Schematics

Diagram
Gas leakage veaa6ucboh
Step By Step Process

Comments

Similar projects you might like

Monitor Fire and Temperature Using ARTIK Cloud

Project tutorial by Samsung IoT

  • 2,585 views
  • 0 comments
  • 21 respects

Safe City: A Device to Keep You Safe

Project tutorial by Patel Darshil

  • 7,561 views
  • 0 comments
  • 24 respects

Monitor Your Garage Door

Project showcase by victormarinus

  • 4,395 views
  • 1 comment
  • 11 respects

Event Monitor for Independent Senior Citizens

Project tutorial by Rethink IoT

  • 3,655 views
  • 4 comments
  • 26 respects

Sump Level Monitor

Project tutorial by Kevin Strain

  • 5,235 views
  • 8 comments
  • 18 respects
Add projectSign up / Login