Hey geeks, hope you are doing fine. This article will make our own smart smoke detector with an MQ2 gas sensor and NodeMCU. We can call it smart as it automatically detects the smoke and sends an alert notification to our smartphones. For controlling the MQ2 gas sensor we are using the Blynk app. You can read the full article on our website.
How Does it Work?You have to provide your network’s SSID and PASSWORD in the code so that NodeMCU can able to send data over the internet. Also, you have to write the unique token in the code. Just follow the steps which are given below.
You can see the values taken by the MQ2 gas sensor on the gauge.
This is how the system works remotely.
Please install the Blynk IoT app on your smartphone. After installation opens the app.
Create a new project and name it what you want. Select the device as NodeMCU and the connection type as WiFi.
The app will ask you to provide your email address. A unique token id is sent by the app to your email address.
Open the widget box to add some graphical representations to your blynk page. Tap on the marked button to open the widgets menu.
Now add a gauge and a notification widget from the menu. These widgets are given in the images below.
Open the configuration settings of the gauge and set the pin value to the virtual-2 and set the range of the sensor. You can also provide the name of the gauge and set the color of it.
Now just upload the code and connect the NodeMCU to the internet. Once the NodeMCU is connected to the Blynk server you can see the data on the gauge as given in the image below.
- NodeMCU esp8266 board
- USB cable for uploading the code
- MQ2 gas sensor
- breadboard and jumper wires
- Smartphone with a good internet connection
Make the connections according to the given diagram.
Positive pin of the MQ2 gas sensor -> VIN pin of the NodeMCU
Negative pin of the MQ2 gas sensor -> GND pin of the NodeMCU
Analog pin of the MQ2 gas sensor -> Analog-0 pin of the NodeMCU
smart smoke detector CodeNOTE: Please upload the code given below to the NodeMCU as it is.
//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!");
}
}
You can also check the tutorials on Arduino and Rasberry Pi on our website.
HAPPY LEARNING!
Comments