Welcome to the Gas Level Monitoring System project! This system leverages the MQ2 gas sensor and ESP8266 to monitor gas levels, with data visualization available on the ThingSpeak cloud platform. The data from the gas sensor is sent wirelessly to ThingSpeak using the ESP8266, enabling real-time monitoring and analysis of gas levels.
This project is designed to provide an easy and efficient way to monitor gas levels in various environments. By using the MQ2 gas sensor, we can detect the presence of gases such as LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide. The ESP8266 Wi-Fi module connects the sensor to the internet, allowing the data to be sent to the ThingSpeak cloud platform where it can be observed and analyzed.
- Real-Time Monitoring: Continuously monitors gas levels and provides real-time data.
- Wireless Data Transmission: Sends sensor data to the ThingSpeak cloud platform via Wi-Fi.
- Cloud Visualization: Visualize and analyze gas sensor data on ThingSpeak.
- MQ2 Gas Sensor: Detects various gases and provides an analog signal output.
- ESP8266 Wi-Fi Module: Connects to Wi-Fi and sends data to the cloud.
- ThingSpeak Cloud Platform: Receives and visualizes sensor data.
To get started with this project, follow the instructions below:
https://www.arduino.cc/en/software
After installing arduino IDE
- Open Arduino IDE
- Go to File > Preferences.
- In the Additional Board Manager URLs field, add the following URL:
- Go to Tools > Board > Boards Manager.
- Search for esp8266 and install the ESP8266 package.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
1.Create a ThingSpeak account at
https://thingspeak.com
- Create a new channel and add a field for the gas sensor data.
#include <ESP8266WiFi.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* thingspeakServer = "api.thingspeak.com";
const int thingspeakAPIKey = YOUR_THINGSPEAK_API_KEY;
const int thingspeakChannelID = YOUR_THINGSPEAK_CHANNEL_ID;
const int gasSensorPin = A0; // Adjust based on your sensor's analog pin connection
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Read analog value from gas sensor
int sensorValue = analogRead(gasSensorPin);
// Convert sensor value to a meaningful unit (adjust based on sensor datasheet)
// This example assumes a linear relationship between sensor value and gas concentration (replace with your sensor's conversion method)
float gasConcentration = sensorValue * 5.0 / 1023.0; // Assuming 0-5V sensor output
// Prepare HTTP request to Thingspeak
String dataString = "api_key=" + String(thingspeakAPIKey) + "&field1=" + String(gasConcentration);
Serial.print("Connecting to Thingspeak...");
if (connectToThingspeak()) {
Serial.println("Connected!");
client.print("POST /update HTTP/1.1\n");
client.print("Host: " thingspeakServer "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Connection: close\n");
client.print("Content-Length: ");
client.print(dataString.length());
client.println("\n");
client.println(dataString);
delay(1000); // Wait for Thingspeak to process data
} else {
Serial.println("Connection failed!");
}
client.stop();
delay(10000); // Adjust delay between readings as needed
}
boolean connectToThingspeak() {
if (!client.connected()) {
Serial.print("Connecting to server: ");
Serial.println(thingspeakServer);
if (client.connect(thingspeakServer, 80)) {
return true;
} else {
return false;
}
}
return true;
}
1.Select Tools > Board > NodeMCU 1.0 (ESP-12E Module).
3.Click the Upload button.
Once the setup is complete, the ESP8266 will connect to your Wi-Fi network and start sending gas sensor data to ThingSpeak. You can visualize the data on your ThingSpeak channel.
Contributions are welcome! If you have any ideas for improvements or encounter any issues, feel free to open an issue or submit a pull request.