Techatronic
Published

Blynk Smart Smoke Detector | MQ-2 Gas Sensor

This is a smart smoke detector that uses an MQ-2 gas sensor for detecting the smoke.

BeginnerFull instructions provided1 hour3,542
Blynk Smart Smoke Detector | MQ-2 Gas Sensor

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
 //TECHATRONIC.COM  
 // BLYNK LIBRARY  
 // https://github.com/blynkkk/blynk-library  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <SimpleTimer.h>  
 #define BLYNK_PRINT Serial  // Comment this out to disable prints and save space  
 char auth[] = "446r8LYJMJnXYrYqyEItR31Eh0jlH2m2"; //Enter Authentication code sent by Blynk  
 char ssid[] = "DESKTOP"; //Enter WIFI Name  
 char pass[] = "asdfghjkl"; //Enter WIFI Password  
 SimpleTimer timer;  
 int mq2 = A0; // smoke sensor is connected with the analog pin A0   
 int data = 0;   
 void setup()   
 {  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
  timer.setInterval(1000L, getSendData);  
 }  
 void loop()   
 {  
  timer.run(); // Initiates SimpleTimer  
  Blynk.run();  
 }  
 void getSendData()  
 {  
 data = analogRead(mq2);   
  Blynk.virtualWrite(V2, data); // Blynk INPUT Connect V2 Pin  
  if (data > 700 )  
  {  
   Blynk.notify("Smoke Detected!");   
  }  
 }  

Code snippet #2

Plain text
 //TECHATRONIC.COM  
 // BLYNK LIBRARY  
 // https://github.com/blynkkk/blynk-library  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <SimpleTimer.h>  
 #define BLYNK_PRINT Serial  // Comment this out to disable prints and save space  
 char auth[] = "446r8LYJMJnXYrYqyEItR31Eh0jlH2m2"; //Enter Authentication code sent by Blynk  
 char ssid[] = "DESKTOP"; //Enter WIFI Name  
 char pass[] = "asdfghjkl"; //Enter WIFI Password  
 SimpleTimer timer;  
 int mq2 = A0; // smoke sensor is connected with the analog pin A0   
 int data = 0;   
 void setup()   
 {  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
  timer.setInterval(1000L, getSendData);  
 }  
 void loop()   
 {  
  timer.run(); // Initiates SimpleTimer  
  Blynk.run();  
 }  
 void getSendData()  
 {  
 data = analogRead(mq2);   
  Blynk.virtualWrite(V2, data); // Blynk INPUT Connect V2 Pin  
  if (data > 700 )  
  {  
   Blynk.notify("Smoke Detected!");   
  }  
 }  

Github

https://github.com/ekstrand/ESP8266wifi

Github

https://github.com/jfturcot/SimpleTimer

Github

https://github.com/blynkkk/blynk-library

Credits

Techatronic

Techatronic

72 projects • 126 followers
Electronic engineer

Comments