Gas Level Monitoring Over Internet Using ESP8266 & Gas Sensor
In this project, we will learn about Gas Level Monitor On Internet Using ESP8266 & Gas Sensor Module, i.e MQ135. We will measure the quantity of gas in percentage and send it over the internet using the thingspeak server. With this system, the data can be monitored remotely staying at any part of the world. We just need gas/smoke/LPG sensor like MQ2/MQ3/MQ5/MQ7/MQ135 that is directly connected to Nodemcu ESP8266-12E Module.
ThingSpeak is an open-source Internet of Things (IoT) application and API to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network.
You can check our earlier projects while are similar to the current project:
- Alcohol Level Meter using Arduino & MQ-135 Alcohol/Gas Sensor
- Arduino Smoke Level Detector using MQ-135 Sensor with Alert Alarm
- Gas Leak Alarm System using MQ2 & Arduino
- Gas Leakage Detector with SMS Alert using GSM Module & Arduino
Bill of Materials
The following are the components required for the project. All the components can be purchased from Amazon.
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | NodeMCU ESP8266 | 1 | Amazon | AliExpress |
2 | MQ-135 Air Quality Sensor | 1 | Amazon | AliExpress |
3 | Connecting Wires | 10 | Amazon | AliExpress |
4 | Breadboard | 1 | Amazon | AliExpress |
MQ135 Gas/Smoke Sensor
Description
The MQ-135 gas sensor senses gases like ammonia nitrogen, oxygen, alcohols, aromatic compounds, sulfide, and smoke. The MQ-3 gas sensor has a lower conductivity to clean the air as a gas sensing material. In the atmosphere, we can find polluting gases, but the conductivity of the gas sensor increases as the concentration of polluting gas increases. MQ-135 gas sensor can be implemented to detect the smoke, benzene, steam, and other harmful gases. It has the potential to detect different harmful gases. It is with low cost and is particularly suitable for Air quality monitoring applications.
The MQ135 sensor is a signal output indicator instruction. It has two outputs: analog output and TTL output. The TTL output is a low signal light that can be accessed through the IO ports on the Microcontroller. The analog output is a concentration, i.e. increasing voltage is directly proportional to increasing concentration. This sensor has a long life and reliable stability as well.
Features
• High Sensitivity
• High sensitivity to Ammonia, Sulfide, and Benze
• Stable and Long Life
• Detection Range: 10 – 300 ppm NH3, 10 – 1000 ppm Benzene, 10 – 300 Alcohol
• Heater Voltage: 5.0V
• Dimensions: 18mm Diameter, 17mm High excluding pins, Pins – 6mm High
• Long life and low cost
Circuit Diagram & Connections
Make a connection as per the circuit diagram below. Connect the VCC pin of MQ135 to Vin of NodeMCU and GND to GND. Connect analog pin A0 of MQ135 to Analog pin A0 of NodeMCU.
Setting Thingspeak & Getting API Key:
- Go to https://thingspeak.com/ and create an account if you do not have one. Login to your account.
- Create a new channel by clicking on the button. Enter the basic details of the channel. Then Scroll down and save the channel. You can follow the video guide below.
- Then go to API keys copy and paste this key to a separate notepad file. You will need it later while programming.
Source Code
Here is a program for Gas Level Monitor On Internet Using ESP8266 & Gas Sensor MQ135. Copy this code and upload it to Nodemcu.
Change the wifi SSID, password, and thingspeak API key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#include <ESP8266WiFi.h> String apiKey = "SKP9YQY2CFVNK919"; // Enter your Write API key from ThingSpeak const char *ssid = "Alexahome"; // replace with your wifi ssid and wpa2 key const char *pass = "hngzhowxiantan"; const char* server = "api.thingspeak.com"; WiFiClient client; void setup() { Serial.begin(115200); delay(10); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); } void loop() { float h = analogRead(A0); if (isnan(h)) { Serial.println("Failed to read from MQ-5 sensor!"); return; } if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com { String postStr = apiKey; postStr += "&field1="; postStr += String(h/1023*100); postStr += "r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.print("Gas Level: "); Serial.println(h/1023*100); Serial.println("Data Send to Thingspeak"); } delay(500); client.stop(); Serial.println("Waiting..."); // thingspeak needs minimum 15 sec delay between updates. delay(1500); } |
Gas Level Monitor On Internet Using ESP8266 & Gas Sensor
After the circuit is assembled on a breadboard, code should be uploaded.
Once code uploading is done open the serial monitor to see whether the wifi is connected or not. Make sure the baud rate should be 115200. If wifi is connected then you can see the gas level displayed in percentage and data will be sent to thingspeak.
You can now introduce gas or smoke or perfume at the MQ135 and see the changes in a rise in the percentage value of gas level.
Open the thingspeak channel and select pubic/private view. Here you can see the data uploaded after the interval of 15 seconds.
15 Comments
i uoloaded this code but nothing comes in serial monitor.please help me.
Didn’t show the graph in thingspeak
I have the same issue. In monitor it works but not in Thingspeak
How can we calibrate MQ135
not a good lab to do – author has not updated code to work correctly with Thinkspeak
same problem
Senosr data is displayed in serial monitor ,but the data is not same in JSON format in thingspeak?? it is showing null why
please me the solution
Anyone solved the issue with thingspeak not showing the values? I can see my entries, but nothing on the graph.
UPDATE:
I solved the issue and here is the link for the code :
https://docs.google.com/document/d/1Xt4i5q6X_nxIBbx6qLLffofYwJqJ592F4WzdNPaJl8o/edit?usp=sharing
where is the scheme?
The first line of the sketch should be the library of mq-135 :
#include <MQ135.h>
Really good post. I’m a 14 yrs old girl coder and I had to make a circuit for a competition and found so many sites but they never contained correct info. I found this so useful with making mine, and I hope I’d win a prize! thank you so much whoever you are or whereeve you are! Love u so much!
Nexa Osbourne
That is extraordinary as everyone else here seems to stumble upon the code not being correct, whereas contrary to your statement, many other sites do contain correct code
hi!
Author never included the MQUnified sensors library? awesome….