For a long time, I wanted to monitor every component in the air only using low-cost MQ sensors. So I ordered a set of 9 MQ sensors and made this project, in which I can measure the concentration of many kinds of gas in the air only using some MQ sensors. This kind of sensor is not so accurate and needs lots of calibration, but they are the best cheap gas sensors out there. You can find a set of nine gas sensors for only $6 to $7. in my project, I use 6 of them and measure the gas concentration of 12 gases.
Wait!!! Before starting any work, you should power your sensor and let it burn for at least 24 hours. This step is very important because MQ sensors come polluted, and burning helps them to clean themselves. You have to power the sensors with 5V and put them In a clean place.
MQ sensors output an analog voltage that varies with the concentration of some selected gases. So, we can read the analog value via Arduino ADC and find the gas concentration in the air.
I use 6 MQ sensor (MQ3, MQ4, MQ7, MQ8, MQ9 and MQ135).
Uses of the sensorsMQ3 for measuring Alcohol, Benzene, and Hexane
MQ4 for measuring Methane and smoke
MQ135 for measuring CO2, NH4, Toluene, and Acetone
MQ7 for measuring CO
MQ8 for measuring H2
MQ9 for measuring flammable gasConnections
I connect them to Arduino nano because it has 8 ADC, which I need. Six ADC for the sensors and two for the I2C communication with the LCD.
Connect the Arduino with sensors as follow-
- MQ3 Ao - Arduino A0
- MQ4 Ao - Arduino A1
- MQ135 Ao - Arduino A2
- MQ7 Ao - Arduino A3
- MQ8 Ao - Arduino A6
- MQ9 Ao - Arduino A7
Connect the Arduino and the LCD as follow-
- Arduino A4 - LCD SDA
- Arduino A5 - LCD SCL
Connecting the hardware and Reading the analog value is easy, but the most difficult thing is to calibrate the sensors and calculating the ppm(parts per million) value for a specific gas. After searching for a long time on the internet, I find a library for those sensors. And comparing the calculation with the datasheet of the sensors, it seems promising.
Here I found an article that explains the working and the calculation for an MQ sensor- UNDERSTANDING A GAS SENSOR.
I use the library and write a code to use six of those sensors with an Arduino nano and show different gas concentrations on air.
You can find the library here - MQUnifiedsensor library
For coding, first of all, I include the LiquidCrystal_I2C and MQUnifiedsensor library and then define the display parameter and the Input PIN for the sensors. Then in the setup section, I initialize the display and the sensors and set the R0 value for every sensor. You have to calibrate your sensors to find this R0 value. For that, uncomment a section in the setup function and upload the code to your Arduino with the pre-burned sensor connected. Then you will find the R0 value for every sensor in the serial monitor. Note the values and change them in the setup function. It is recommended that calibrate the sensors once in a clean environment and set the R0 value. The part to uncomment is indicated in the code.
And in the loop function, I set the A and B values for the exponential equation for different gases. Here A and B value is for PPM = A*ratio^B. Those values are different for different gas in different sensors.
After that, I display the gas concentration on the LCD by two values on a page. There is a 3-second delay between every page.
The Video Clip For The Project
Comments