SiTeGas: Sistem Pendeteksi Gas
By: Muhammad Daffa Ramadhani, Tagreg Wiryo Nursalim, & Vadrick Ferdinand Fu - Computer Engineering - Binusian 2024 - Bina Nusantara University.
SiTeGas: Sistem Pendeteksi Gas is a device that notifies you whenever gas can be detected in the vicinity of the device. It has 2 features which includes gas detection and rain detection which will collect data and notifies the user in the case of any detection. For example, it will notify the user "Gas Detected" whenever the gas sensor detects some gas, and "Rain Detected" whenever the rain sensor hits water or raindrops.
For this device, the Blynk App is used which can be downloaded from the Play Store of the App Store.
Supplies
Software:
- Blynk
- Arduino IDE
Hardwares:
- ESP32 or NodeMCU
- MQ2 Gas sensor
- Rain sensor module
- 1k 1/4 watt resistors (2 Pcs)
- 5-mm LEDs (2 Pcs)
- Jumper wires.
Blynk IoT Cloud Setup
- Create a Blynk account and log in.
- Create Blynk Template and select ESP 32 as hardware.
- Create Datastreams in Blynk Cloud for each sensor (in this case 2 datastreams).
- Add 2 new events on Blynk (GAS and RAIN).
- Create a web dashboard, click and drag Gauge and Label widgets according to the number of sensors (2), and click save.
- Now add new device using the template that we just made
- We can add the firmware configuration in other words, the blynk authentication token from the device info to our code
Coding
- Install Arduino IDE and open the application.
- Go to File => Preferences => Additional Board Manager URLs => Paste this link (https://dl.espressif.com/dl/package_esp32_index.json)
- Go to Tools => Board => Board Manager => Search "esp32" => Install "esp32".
- Go to Sketch => Include Library => Manage Libraries => Search "Blynk" => Install "Blynk".
- Type this code in Arduino IDE
/* Fill-in your Template ID (only if using Blynk.Cloud) */ #define BLYNK_TEMPLATE_ID "" #define BLYNK_DEVICE_NAME "" #define BLYNK_AUTH_TOKEN "" // Your WiFi Credentials. // Set password to "" for open networks. char ssid[] = ""; char pass[] = ""; // define the GPIO connected with Sensors & LEDs #define MQ2_SENSOR 35 #define RAIN_SENSOR 34 #define GREEN_LED 14 #define RED_LED 25 #define WIFI_LED 2 //#define BLYNK_PRINT Serial #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> BlynkTimer timer; int MQ2_SENSOR_Value = 0; int RAIN_SENSOR_Value = 0; bool isconnected = false; char auth[] = BLYNK_AUTH_TOKEN; #define VPIN_BUTTON_1 V1 #define VPIN_BUTTON_2 V2 void checkBlynkStatus() { // called every 2 seconds by SimpleTimer isconnected = Blynk.connected(); if (isconnected == true) { digitalWrite(WIFI_LED, HIGH); sendData(); //Serial.println("Blynk Connected"); } else{ digitalWrite(WIFI_LED, LOW); Serial.println("Blynk Not Connected"); } } void getSensorData() { MQ2_SENSOR_Value = map(analogRead(MQ2_SENSOR), 0, 4095, 0, 100); RAIN_SENSOR_Value = digitalRead(RAIN_SENSOR); if (MQ2_SENSOR_Value > 50 ){ digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, HIGH); } else if (RAIN_SENSOR_Value == 0 ){ digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, HIGH); } else{ digitalWrite(GREEN_LED, HIGH); digitalWrite(RED_LED, LOW); } } void sendData() { Blynk.virtualWrite(VPIN_BUTTON_1, MQ2_SENSOR_Value); if (MQ2_SENSOR_Value > 50 ) { Blynk.logEvent("gas", "Gas Detected!"); } else if (RAIN_SENSOR_Value == 0 ) { Blynk.logEvent("rain", "Water Detected!"); Blynk.virtualWrite(VPIN_BUTTON_2, "Water Detected!"); } else if (RAIN_SENSOR_Value == 1 ) { Blynk.virtualWrite(VPIN_BUTTON_2, "No Water Detected."); } } void setup() { Serial.begin(9600); pinMode(MQ2_SENSOR, INPUT); pinMode(RAIN_SENSOR, INPUT); pinMode(GREEN_LED, OUTPUT); pinMode(RED_LED, OUTPUT); pinMode(WIFI_LED, OUTPUT); digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, LOW); digitalWrite(WIFI_LED, LOW); WiFi.begin(ssid, pass); timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds Blynk.config(auth); delay(1000); } void loop() { getSensorData(); Blynk.run(); timer.run(); }
Setup Mobile Dashboard in Blynk IoT App
- Download the Blynk App on Play Store or App Store.
- Log in to your account.
- Open the Blynk IoT app, and select the Template.
- Tap on the 3-dash icon and add 1 Gauge & 1 Value Display from the widget Box.
- Tap on the Gauge widget and select the Datastream.
- Tap on the Value Display widget and select the related Datastream. Select Front Size as AUTO.
- Then exit from the EDIT mode.
Block Diagram
This is the block diagram of SiTeGas: Sistem Pendeteksi Gas.
Flow Chart
This is the flow chart of SiTeGas: Sistem Pendeteksi Gas.
Schematic
This is the schematic of SiTeGas: Sistem Pendeteksi Gas.
Assembly
- Connect 5V and GND from Power Supply to a breadboard.
- Connect the MQ-2 Gas sensor analog output to the GPIO D35, the Vcc to the Vin pin and to the (+) on the breadboard, and the GND to the GND pin and to the (-) on the breadboard.
- Connect the rain sensor module’s digital output to the GPIO D34, the Vcc to the Vin pin and to the (+) on the breadboard, and the GND to the GND pin and to the (-) on the breadboard.
- The Indicator LEDs are connected with GPIO D14 & D25, and to 1k resistors connected to the GND pin and to the (-) on the breadboard.
- The ESP32 board LED connected with GPIO D2 is used as the Wi-Fi indicator.
- Make a casing.