Introduction: IoT Air Quality Sensor
In this Instructable, I will walk you through the steps to build an IoT Air Quality Sensor. This is an inexpensive air quality sensor with reasonable accuracy and is accessible to internet through WiFi. This project is to integrate 3 sensors that detect different kinds of gases and particles with Nodemcu and then, send the data detected to the internet. The 3 sensors are MQ2 sensor for smoke, MQ9 sensor for carbon monoxide and PMS3003 G3 particle sensor for PM1.0, PM2.5 and PM10. Nodemcu 1.0 ESP8266 is a very good micocontroller for developing IoT project because it has an inbuilt WiFi function by ESP8266 chip. It provides easy and very stable connection to the internet.
Step 1: Bill of Materials
Things you would need:
- Nodemcu 1.0 ESP8266
- MQ2 gas sensor
- MQ9 gas sensor
- PMS3003 G3 particle sensor
- 3.3V to 5V boost converter
- 180ohm resistor x2 and 330 ohm resistor x2
- Analog Multiplexer 4051 (CD4051BE)
- 1.3 inches OLED monitor SSD1306
- 7.4V Li-ion battery
- Li-ion battery Charger Board
- Breadboard
Step 2: Nodemcu 1.0 ESP8266
Nodemcu 1.0 ESP8266 is a very good micocontroller for developing IoT project because it has an inbuilt WiFi function by ESP8266 chip. It provides easy and very stable connection to the internet.
One drawback of Nodemcu is that it has only one analog I/O pin. For this project, there are 2 sensor, MQ2 and MQ9 gas sensor using analog output. In this case, a technique, called multiplexing, can be used. Instead of reading output from 2 sensor at the same time, reading data one by one. In this project, an analog multiplexer CD4051BE is used. It is a 8-channel multiplexer which means it can operate with 8 outputs. If you do not like to use multiplexer, simple circuit using diodes can also be achievable. You can take a look at Multiple Analog Inputs Using One Analoge Pin by Ingenerare or ESP8266 ADC - Multiple Analog Sensors by breagan22.
Another drawback is that Nodemcu only supplies 3.3V output. For many devices and the three sensors using in this project, they need 5V power supply to operate. Therefore, a 3.3V to 5V boost converter is needed to step up the voltage or simply supply the devices by other 5V supply.
There are many firmware for nodemcu. Nodemcu 1.0 is programmable by Arduino IDE, but few steps is needed before you can use it. You can look at Quick Start to Nodemcu (ESP8266) on Arduino IDE by Magesh Jayakumar.
Step 3: Connection
The above is the connection of all different components.
3.3V to 5V boost converter is connected to the 3.3V output of nodemcu.
I will explain how to connect other components below.
Step 4: Step 3: Connecting MQ2 and MQ9 Gas Sensor
MQ2 and MQ9 gas sensor both have four pins:
- VCC
- GND
- DO (Digital Control)
- AO (Analog Output)
The analog output of MQ2 and MQ9 is between 0V to 5V whereas the analog pin of nodemcu can only read between 0V to 3.3V. That means nodemcu cannot read the data if MQ2 or MQ9 sensor output is above 3.3V. The data read is not accurate. Therefore, voltage is needed step down.
In this project, voltage divider by two resistors is used. The voltage output is determined by the ratio of the value of two resistors. I use 180ohm as R1 and 330ohm as R2 so that Vout is 3.3V.
So, Vin is connected to AO pin of MQ gas sensors. Vout is connected to channels of the multiplexer.
Only three pins of each sensor are used:
- Vcc to 5V supply
- GND to nodemcu GND pin
- Vout of voltage divider to CD4051BE channel 1 and channel 2(pin14 and 15)
Multiplexer connection:
- Vdd (pin 16) to 5V supply
- INH, Vee, Vss (pin 6, 7, 8) to nodemcu GND pin
- common out/in (pin 3) to nodemcu A0 pin
- A, B, C (pin 11, 10, 9) to nodemcu D0, D1, D2
A, B, C (pin11, 10, 9) are used to select channel for output.
A, B, C are digital input which means only read 0 and 1.
3-digit binary number is formed in the order of CBA.
As we use channel 1 and 2, denary number of 1 and 2 in 3-digit binary number are 001 and 010 respectively.
Therefore, when we want output of channel 1, D0 output 1, D1 and D2 output 0.
When we want output of channel 2, D0 output 0, D1 output 1 and D2 output 0.
Step 5: Connecting PMS3003 Sensor
PMS3003 has 8 pins for different purposes. In fact, only 4 pins is used in this project:
- VCC (pin 1) to 5V supply
- GND (pin 2) to nodemcu GND pin
- RXD (pin 4) to nodemcu tx pin
- TXD (pin 5) to nodemcu rx pin
Step 6: Connecting 1.3 Inches OLED Display SSD1306
It has 4 four pins. Connection:
- VCC to 3.3V pin of nodemcu
- GND to GND pin of nodemcu
- SCL to D3 pin of nodemcu
- SCA to D4 pin of nodemcu
Step 7: Programming
I use Arduino IDE to program.
I use thingspeak as IoT platform.
Change to your API key in the program.
Change to your own SSID and password.
15 Comments
Question 5 months ago on Introduction
where can I get the libraries?
SH1106ui and images.h
Question 3 years ago
Do I need a soldering iron?
Question 3 years ago on Step 7
What do we do on the thingspeak channel, like what labels...
4 years ago
Also interested with the casing you have enclosed the sensor in. do you have document with that?
Question 4 years ago on Introduction
WHAT FILE TYPES ARE THE IMAGE DOWNLOADS
4 years ago
Hi, am I using the GP2Y1010AU0F sensor instead of the sensor you used?
4 years ago
Thank you! Great instruction - I implemented it using Heltec LoRa32 and https://github.com/i4things / www.i4things.com but a littel concerned about the quality of the gas sensors to be honest...
4 years ago on Step 6
nice one.
Question 4 years ago on Introduction
nice instructions. Do you know how long is the heater life? Should the sensor stay all the time on, or I should switch off heater and only when measurements are done I should switch it on? This module doesn't allow to separately control the power of the heater, so it's always on as long as you power supply the board. And it consumes like ~200mA, which is not small amount long run.
And if I switch it on/of I need to preheat it... I saw that it needs like 20sec to be heated to have correct measurements.
Any hints, advises are welcomed
5 years ago
Hi Lam, little reminder, you might have missed my previous message.
Thanks ! :)
5 years ago
Would you be kind to mention? ...
- Makerbay with a link to [Makerbay.org] where the project was built at and SUPPORTED BY
- and mention that was BUILT FOR the Hong Kong Citizen Science Faire [Citizensciencefaire.com]
- Also, you worked in a team with several team mates and Eddie's mentorship. It seems it would be appropriate to GIVE CREDITS TO YOUR TEAMMATES.
- If you have learnt from other projects online, please LINK TO REFERENCES.
I can imagine you feel this is YOUR PROJECT, but remember, you're standing on many giants shoulders :) Gratitude goes both ways and goes a long way.
https://makezine.com/2012/02/14/soapbox-the-unspok...
5 years ago
Hi. Awesome work! I would like to display the data on a computer screen / video screen. via VGA, HDMI or s large LED display. How would you do that?
5 years ago
I have been wanting to make an air quality sensor for a while, but i remember reading somewhere that calibrating the sensors is the biggest issue to getting accurate particle measurments. Have you had any trouble with this?
Reply 5 years ago
I use the initial environment for the reference level, which means any reading higher than the initial environment will be reflected. If you want to have a more accurate reading to calibrate, you can simply go to the nearest government air quality monitoring station and compare your reading with it
5 years ago
Awesome. Every city should have a network of these monitoring air quality.