Mike86
Published

Gboard with MQ2 Gas Sensor: DIY Home Fire-Alarm System

This is a tutorial about how to make a home-alarm system for gas leak by using GBoard and MQ2.

IntermediateFull instructions provided1 hour784
Gboard with MQ2 Gas Sensor: DIY Home Fire-Alarm System

Things used in this project

Hardware components

Itead Gboard
×1
Itead MQ - 2 Gas Sensor Brick
×1
Itead Electronic Brick - Lighting Emitting Diode
×1
Itead FOCA
×1
Dupont Lines
×1
9V/2A Adapter
×1
SIM Card
×1

Story

Read more

Schematics

Schematics of Gboard

Schematics of Electronic Brick

Schematics of Foca

Schematics of MQ2-Gas Sensor

Code

Untitled file

C/C++
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); 

const int thresholdvalue=700; //700 is the objective date of MQ2. Generally, the value of average air condition is 100

void setup()
{

pinMode(6, OUTPUT); //D6 is the run pin of sim900 in Gboard,the codes contrl Boot
pinMode(A1, OUTPUT);
digitalWrite(6,HIGH);
delay(1000);
digitalWrite(6,LOW);
delay(10000);
delay(5000);  

Serial.begin(9600);
mySerial.begin(9600);
}

void loop()
{
int sensorValue = analogRead(A0); //Use AO to read the value of MQ2
if(sensorValue>thresholdvalue)
{
digitalWrite(A1,HIGH);//Use A1 to show the status of LED, HIGH means light

Serial.println("ATD12345678900;\r");//Only change the numbers: 12345678900 into your phone number that you want to recieve the alarm call
mySerial.print("ATD12345678900;\r");//The serial monitor will show the phone call it makes

delay(5000);
//following script is to avoid repeat phone calls. when the value is over 700, make call once; when fall to 650 or even less, go back to main program and keep monitoring
 while((analogRead(A0)-thresholdvalue)>0)
 Serial.println(analogRead(A0));
while((thresholdvalue-analogRead(A0))<50)
Serial.println(analogRead(A0));
}

else 
{
Serial.println(analogRead(A0));     
digitalWrite(A1,LOW);//The value of MQ2 is less than 700, LED turns off
 }
}

Credits

Mike86

Mike86

15 projects • 12 followers

Comments