In today’s world, we encounter different scenario where we see different gasses being emitted in atmosphere such as home appliances like air conditioner and industrial chimneys. Monitoring of these gasses is very important with safety point of view. Gas Sensors are very helpful in accomplishing this task. Small nose like sensor spontaneously respond to the alteration of gas concentration and keep our systems updated for special tasks.
In this tutorial, we will create a standalone web server with Surilli WiFi ESP8266 that displays the Air Quality using the Arduino IDE. The web server that we will build can be accessed by any device that has a browser on your local network.
MQ135 SensorThe MQ135 Sensor Module consists of a steel exoskeleton under which a sensing element is housed. This sensing element is subjected to current through connecting leads. This current is known as heating current through it, the gases coming close to the sensing element get ionized and are absorbed by the sensing element. This changes the resistance of the sensing element which alters the value of the current going out of it.
The MQ-135 gas sensor senses the gases like ammonia nitrogen, oxygen, alcohols, aromatic compounds, sulfide and smoke. The operating voltage of this gas sensor is from 2.5V to 5.0V. MQ-135 gas sensor can be implementation to detect the smoke, benzene, steam and other harmful gases.
Working PrincipleThe MQ-135 alcohol sensor consists of a tin dioxide (SnO2), a perspective layer inside Aluminium Oxide micro tubes (measuring electrodes) and a heating element inside a tubular casing. The end face of the sensor is enclosed by a stainless steel net and the back side holds the connection terminals. Ethyl alcohol present in the breath is oxidized into acetic acid passing through the heat element. With the ethyl alcohol cascade on the tin dioxide sensing layer, the resistance decreases. By using the external load resistance the resistance variation is converted into a suitable voltage variation.
It has lower conductivity compare to clean air and due to air pollution the conductivity is increases. The air quality sensor detects ammonia, nitrogen oxide, smoke, CO2 and other harmful gases. The air quality sensor has a small potentiometer that permits the adjustment of the load resistance of the sensor circuit.
The air quality sensor is a signal output indicator instruction. It has two outputs: analog output and TTL output. The TTL output is low signal light which can be accessed through the IO ports on the microcontroller. The analog output is an concentration, i.e. increasing voltage is directly proportional to increasing concentration. The resistance of the sensor decreases as the concentration of the target gas is increased in PPM while for clean air its resistance remains constant.
The analog output voltage from the sensor can be assumed directly proportional to the concentration of CO2 gas in PPM under standard conditions. The analog voltage is sensed from the sensor and converted to a digital value in range from 0 to 1023 by the inbuilt ADC channel of the controller. The digitized value is hence equal to the gas concentration in PPM.
When no gas digital output is 1 and analog output gives 1023 max value. When gas is present digital output is 0 and analogue output is much less than 1023. Using potentiometer on chip we can control the turning OFF point of digital pin at some value of analog pin. The sensor needs a load-resistor at the output to ground. Its value could be from 2k Ohm to 47k Ohm.
The lower the value, the less sensitive is the sensor. The higher the value, the less accurate is sensor for higher concentrations of gas. If only one specific gas is measured, the load-resistor can be calibrated by applying a known concentration of that gas. If the sensor is used to measure any gas (like in a air quality detector) the load-resistor could be set for a value of about 1V output with clean air. Choosing a good value for the load-resistor is only valid after the burn-in time.
NOTE: Don’t touch the sensor, it will be very hot.
Features1. High sensitivity to sulfide, benzene Department of steam, smoke and other harmful gases
2. Long life and low cost
3. Simple drive circuit
Pin Configuration:
From left to right first pins are as follows:
A0 Analog output
D0 Digital output
GND Ground
Vcc Supply (5V)
Specifications of MQ-135 Gas Sensor:
- Wide detecting scope.
- Fast response and High sensitivity.
- Stable and long life Simple drive circuit.
- Used in air quality control equipment for buildings/offices, is suitable for detecting of NH3, NOx, alcohol, Benzene, smoke, CO2, etc.
- Size: 35mm x 22mm x 23mm (length x width x height).
- Working voltage: DC 5 V.
- Signal output instruction.
- Dual signal output (analog output, and high/low digital output).
- 0 ~ 4.2V analog output voltage, the higher the concentration the higher the voltage.
Parts per million (PPM) is a unit of measurement used for expressing a very dilute concentration level of pollutants in the air, water and other fluids or one item in a million of anything of the same size. PPM is a volume-to-volume ratio.
Changes in temperature and pressure do not change the ratio of the volume of pollutant gas to the volume of air that contains it.
Required Hardware1. Surilli WiFi
2. MQ135 gas sensor module
3. Connecting wires
4. Arduino IDE software
ConnectionsMQ135 Sensor Module with Surilli WiFi:
- -> PIN A0 (MQ135) to PIN ADC (Surilli WiFi).
- -> GND PIN (MQ135) to GND PIN (Surilli WiFi).
- -> VCC PIN (MQ135) to USB PIN (5V) (Surilli WiFi).
Make sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if every thing is working fine).
STEP 2: The CircuitryThe circuitry is very simple. It's mostly the programming. Follow the figure below to set up your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE. Replace the "SSID" and "Password" with your own credentials and hit upload. The results can be viewed on the Serial Monitor.
Arduino Code:// Including the ESP8266 WiFi library
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
// Replace with your network details
const char* ssid = "YOUR_NETWORK_NAME";
const char* password = "YOUR_NETWORK_PASSWORD";
// Web Server on port 80
WiFiServer server(80);
int sensorValue;
int sensor_pin = A0;
void setup()
{
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);
sensorValue = analogRead(sensor_pin);
// Connecting to WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Starting the web server
server.begin();
Serial.println("Web server running. Waiting for the ESP IP...");
delay(10000);
// Printing the ESP IP address
Serial.println(WiFi.localIP());
}
// Runs over and over again
void loop()
{
// Listening for new clients
WiFiClient client = server.available();
if (client)
{
Serial.println("New client");
// Boolean to locate when the http request ends
boolean blank_line = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.print(" AirQuality = ");
Serial.print(sensorValue, DEC);
Serial.println(" PPM");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// Your actual web page that displays Air Quality
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head></head><body><h1>ESP8266 - Air Quality</h1><h3>Air Quality in PPM: ");
client.println(sensorValue);
client.println("</h3><h3>");
client.println("</body></html>");
break;
if (c == '\n')
{
// When starts reading a new line
blank_line = true;
}
else if (c != '\r')
{
// When finds a character on the current line
blank_line = false;
}
}
}
// Closing the client connection
delay(1);
client.stop();
Serial.println("Client disconnected.");
}
}
Open the Arduino IDE Serial Monitor at a baud rate of 115200. After a few seconds your IP address should appear. In my case, the IP Address was displayed as follows:
Now, simply copy the IP Address from the Serial Monitor of Arduino IDE and paste it in a web browser to see the Air Quality values. If you refresh the webpage then the value of Air Quality changes accordingly. In my case, the Air Quality value was displayed as follows:
Play with the program to see how it reacts to different values and logic.
If you make something fun and interesting, do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with the Surilli family for more amazing stuff. :-)
Comments
Please log in or sign up to comment.