Have you ever wondered about the quality of the air you are breathing, or maybe, why you sometimes feel sleepy in the office or tired in the morning even after sleeping all night? Poor air quality can lead to many negative health effects as well as can cause tiredness, headaches, loss of concentration, increased heart rate and so on. Monitoring the quality of the air may actually be more important than you realize. So, in this tutorial we will learn how to build our own Air Quality Monitor which is capable of measuring PM2.5, CO2, VOC, Ozone, as well as temperature and humidity.
I will explain how each of air quality parameters affect us and how the sensors work. The brain of this project is an Arduino Pro Mini board which in combination with a 2.8” Nextion touch display provides a decent user interface.
We can see the measurements from all the sensors in real time, and if we click on a particular sensor, we will get values from the last 24 hours from that sensor. There’s also a dimming function through which we can lower the brightness of the display or even turn it off completely. This is convenient, for example, if we want to track the air quality in our bedroom during the night.
We can turn off the screen for the night, and the next day we can check the values from each sensor individually.
Nevertheless, now I will walk you through the entire process of building it and explain how everything works. At the end of this video, you will be able to build one on your own. So, let’s get started.
The PM2.5 Sensor – PMS5003
This device has four main components or air quality sensors. We are using the PMS5003 sensor for measuring PM2.5 or particulate matter in the air with diameter of around 2.5 microns. Particulates are the most harmful form of air pollution because they can penetrate deep into the lungs, blood streams and brain, causing many health problems.
This sensor works on the principle of laser scattering. The sensor has a fan which creates a controlled airflow so the environmental particulates pass through a focused laser beam.
The particulates cause light scattering which is detected by a photodiode and then converted into PM concentration with the help of its microprocessor. I found the results of this sensor to be quite reliable and along PM2.5 it can also output PM1 and PM10 values.
The CO2 Sensor – MH-Z19
Next, we are using the MH-Z19 sensor for measuring CO2 or carbon dioxide. As people emit carbon dioxide while respiration, the indoor concentration of CO2 can easily get very high. CO2 is not only dangerous in high concentrations, but it can also cause drowsiness, tiredness, decrease our productivity level and so on.
The sensor is using non-dispersive infrared principle for measuring CO2 in the air. An infrared source directs light through a tube which is filled with the air that we are measuring. On the other side of the infrared source, there is an optical filter and an IR detector which measures the amount of IR light that passes through.
The CO2 gas molecules which are present in the air that we are measuring absorb a specific band of IR light while letting some wavelengths to pass through. So, the CO2 level is calculated according difference between the amount of light emitted and the amount of IR light received by the detector. The results from this sensor are also quite accurate.
The VOC and Ozone Sensors – MP503 and MQ-131
For measuring VOC and Ozone we are using the MP503 and the MQ131 gas sensors. These are heated metal oxide sensors and their principle of work is based on detecting change in resistance at the presence of targeted gases.
A specific electrical current pass through a metal substrate and the resistance changes according to the amount of gas present.
The target gas of the MQ131 sensor is just Ozone, which in a normal household can be generated by products like certain air purifiers, facial steamers, germicidal lamps that produce ultraviolet light and so on.
On the other hand, the MP503 sensor has multiple target gases, including alcohol, smoke, iso-butane, methanal and others. VOC stands for Volatile Organic Compounds and these are organic emission from products that we use on a daily basis like laundry detergents, cleaners, air fresheners, paint, makeup, and so on. VOCs can cause many negative health effects including headaches, irritation to eyes, skin reactions, dizziness and so on.
DIY Arduino Air Quality Monitor – Circuit Diagram
Nevertheless, so let’s take a look at the circuit diagram now and explain how everything needs to be connected.
You can get the components needed for this Arduino air quality monitor from the links below:
- PMS5003 PM Sensor ……………………. Amazon / Banggood / AliExpress
- MH-Z19 CO2 Sensor …………………….. Amazon / Banggood / AliExpress
- MQ-131 Ozone Sensor ………………….. Amazon / Banggood / AliExpress
- MP503 VOC Sensor ………………………. Amazon / Banggood / AliExpress
- DHT22 Temp & Hum Sensor…………. Amazon / Banggood / AliExpress
- Nextion 2.8″ Display …………………….. Amazon / Banggood / AliExpress
- DS3231 RTC …………………………………. Amazon / Banggood / AliExpress
- Arduino Pro Mini………………..…….….. Amazon / Banggood / AliExpress
- Distance / Spacer Nuts M3 …………… Amazon / Banggood / AliExpress
- Mini USB Connector ……………………. Amazon / Banggood / AliExpress
- Pin headers …………………………………. Amazon / Banggood / AliExpress
- 2 Positions switch ………………………… Amazon / Banggood / AliExpress
- Capacitors values: 0.1uF ceramic and 10uF electrolytic
- Transistors – 2N3904
Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
Correct resistors values: R1 = 1K, R2 = 2K, R6=100K or 1M, R7=1K
The PM2.5 sensor communicates with the Arduino through a serial interface. It works at 5V, but the receive RX logic level works at 3.3v, so therefore we need a voltage divider for it. The CO2 sensor and the Nextion display also use serial communication. For reading the VOC and the Ozone sensors we use analog inputs of the Arduino, while the DHT22 temperature and humidity sensor uses a digital pin for that purpose.
The two transistors are used for activating the sensors heaters. We are also using a Real Time Clock module for keeping track of the time when storing the sensors values, and it uses the I2C communication. The whole device is powered with 5V through a Mini USB connector.
Now if we try to connect everything together, we will get quite a mess because of the many connections.
So, we definitely need a PCB for this project.
Making a PCB for the Arduino Air Quality Monitor
For making a PCB for this project, I’m going to use Altium Designer which are actually the sponsor of this video.
Altium Designer represents decades of innovation and development dedicated to creating a truly unified design environment. Striking the perfect balance between power and ease of use, Altium Designer has secured its position as the most widely-used PCB design solution on the market.
Now I will show you how I designed the PCB for this project using Altium Designer. I started with making the schematic for the project. Altium Designer has built-in libraries with basic electronic components, but even better you can search for components directly from manufacturers which makes sourcing components for your project very convenient.
As an example, I found the Mini USB connector using this Manufacturer Part Search feature. From here you can also easily get access to data related to the components, like 3D models, footprints, dimensions etc.
You can also create your own components libraries. I created most of the components for this project on my own, as I wanted to create my own 3D footprints for each part so that at the end, I would get the whole PCB in 3D. For creating 3D models for the PCB footprints, you can use any CAD software, save the files as .STEP files and import them in Altium Designer.
Once I finished the schematic, I generated the PCB. I arranged the components as I wanted, and with just a simple click using the Auto Route feature, the software generated all traces automatically.
If needed, we can manually create or adjust them. Also, we can set design rules how the auto routing will make the traces, set different widths for each net and so on. At this point we also see the PCB in 3D and export a 3D file of the entire PCB assembly which will be used for designing a case for it later on.
Nevertheless, I would like to thanks Altium for sponsoring educational content like this. If you would like to find out more about this software and also try it out, you can check out the links below. You can also try the web based Altium 365 viewer for project previews and file.
Here are the Altium Designer project files:
Altium Designer files including the project file, libraries and .STEP files of the 3D models of the electronics components:
PCB Gerber file:
Ok, so once I finished the PCB, I generated the Gerber and the NC Drill files, put them into a single zip file, and so I was ready to order the PCB to be manufactured.
I ordered the PCB from JCLPCB. Here we can simply drag and drop the zip file and once uploaded we will get all visual information about our PCB.
Then we can select the properties that we want and order our PCB at a reasonable price.
Assembling the PCB
After several days the PCBs have arrived. The quality of the PCB is great and everything is exactly the same as in the design.
So, now we are ready to start assembling the PCB. I started by inserting and soldering the smaller components first, the resistors and the two transistors.
Then we can solder the Arduino Pro Mini board in place. However, first we need to solder the pin headers to it. Please note that we don’t need all its pins, but make sure you don’t miss the one we need like the A4, A5 and the DTR pin. Also make sure you have this exact same Arduino Pro Mini board with this layout of pins, because they can sometimes be different.
Next, we can insert the DHT22 sensor in place. For that purpose, first we need to bend its pins 90 degrees. Sometimes I also use Blu-tack adhesive for keeping the components in place when soldering.
The two capacitors used in this project are for stabilizing the power supply. The power to the board will come from a mini-USB connector to which we can connect 5V.
Right above the power supply connector we need to solder the two switches. One is for turning on and off the device, and the other is used when we want to upload a sketch to the Arduino board. Then we can insert the pin headers for the USB to UART interface, the display and the PM2.5 sensor, as well as the VOC, the Ozone and the CO2 sensors in place.
Next, for soldering the DS3231 Real Time Clock module again, first we need to bend the pins 90 degrees. Once soldered we can insert the battery which keeps track of the time even when main PCB loses power. With this the PCB is actually done, and what’s left to do now is to prepare the cables that we will use for connecting the PM2.5 sensor and the display to the PCB. I soldered male pin headers to the cable that comes with the sensor, and so I was able to easily connect it to the PCB. For connecting the display to the PCB, I soldered four wires to the back side of the display connector and then connected them to the PCB.
And that’s it, our Air Quality Monitor is actually done. Of course, what we need to do now is to make some kind of box or case for it. As we have the 3D model of the entire PCB assembly from Altium Designer, we can import it in a CAD software and design a case for it.
I used SOLIDWORKS for that purpose, and made the simplest case possible consisting of just two parts and few bolts and nuts. I decided to make the case using transparent acrylic because I like how the PCB and the components look exposed and it’s also a great way to show off your DIY project.
Here you can download the 3D model of the DYI Air Quality Monitor:
Making the Case for the Air Quality Monitor
The acrylic that I will use is 4mm tick which perfectly fit with the display. As I currently don’t have a CNC machine, I cut the shapes manually using a simple metal hacksaw.
For making the opening for display, first I made two holes with a drill. Then I passed through a blade from a mini hacksaw and carefully cut the shape. Using a simple rasp, I smoothed out shape. Then using a 3mm drill I made all the holes for attaching the PCBs and connecting the two acrylic plates together.
At this point, I removed the protective foil from the acrylic which, and to be honest, that’s quite satisfying process. For attaching the PCB to the base plate, I used some M3 bolts and nuts. For attaching the PM2.5 sensor to the plate we need M2 bolts.
Next, using some distance nuts we can join the two plates together. By using one female and one male distance nut I was able to easily get the desired distance between the two plates.
I personally really like how this case turned out, plus, it’s functional as air can easily circulate around the sensors.
All right, so now we can power up the device and upload the program. We can power the air quality monitor through the Mini USB connector and we can get the 5 volts from a 5V USB adapter, a 5V phone charger or a power bank.
For uploading the program to the Arduino Pro Mini board, we need an USB to serial UART interface which can be connected to the programming header. Before connecting it to the computer USB, first we must turn on main power of the device, because otherwise the power coming from the computer USB which is only 500mA might not be enough to work properly. When uploading the Arduino sketch, we also need to switch the upload switch on the PCB.
Here you can download the Arduino Code and the Nextion Display Program:
For uploading a sketch to an Arduino Pro Mini board, in the Arduino IDE first we need to select this board, select the proper version of the processor, select the port and select the programming method to “USBasp”.
Once we upload the code to the Arduino, we also need to upload a code to the Nextion display. Nextion displays have built-in ARM controller which actually controls the display on its own.
All graphics like buttons, text, images, variables and so on, are generated and controlled by the display itself. The Nextion display has a dedicated Nextion editor where we can create all these stuffs. The display and the Arduino communication with just two wires using the serial communication. The Arduino simply just sends the values from the sensor to the display and vice versa, the display sends data to the Arduino when needed.
For uploading the display program, we need a microSD card where we can save the output .TFT file from the Nextion editor.
The display has a card reader where we can insert the microSD card while the power is off. Then we can power up the device and the program will be uploaded to the display. Now we just have to remove the card, switch on the power again, and our air quality monitor will start working.
So, we are using libraries for each sensor and which can be found on the following links, MHZ19, PMS, MQ131, DHT, DS3231. In order to better understand how we read the data from each sensor I recommend reading the libraries documentations and try out their examples.
We are also using the SoftwareSerial library because both the MH-Z19 and the PMS5003 sensors use the serial communication. The Arduino and the Nextion display also use the serial port for communication and in this case we are using the default, hardware serial.
So, the Arduino reads the sensors and sends that data to the Nextion display. Here’s an example.
Serial.print("tempV.val="); Serial.print(temp); Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
So we have a variable at the nextion display called “tempV” and in order to update it’s value we need to send a command to the nextion as following “tempV.val=22”. So the variable name, then “.val”, then the value, let’s say 22. The first two lines of the code do that, and in order the Nextion display to accept this command or actually any command we need to send the three unique “write” commands.
In the Nextion display program, we have a timer which runs in a loop, just like the Arduino code loop, and it constantly updates the numbers on the display.
In this timer event we also have a code for changing the background color for each sensor depending on its value.
On the second page we have waveform, which gets the values from the stored values from the Arduino. Please note that you can find more info on the Arduino code itself as there is explanation in the comments of the code.
The hours and the Y-axis values also get their values from the Arduino.
On top of the waveform, as well as the numbers on the main screen, you can notice we have like transparent objects, called “Hotstops” in the Nextion editor, and they are act as buttons. If we press the hotstop on the waveform we can see in the Event section that it sends us back to “page 0”.
Overall, that’s how the program of this Arduino air quality monitor works. Of course, in order to fully understand how it works you need to learn and know how each sensor works with their libraries, as well as how the Nextion display works.
Please note that for the VOC sensor we are only reading raw data from this sensor, not ppm or ppb values. Just analog values from 0 to 1024. Higher values means there is a presence of VOC.
As for the Ozone sensor, in order to get more accurate outputs we must set the setTimeToRead() and setR0() values correctly according to the calibration example of the library. However, longer setTimeToRead means the program will be blocked while sampling and everything else will be freezed. Of course, there are ways to work this around. I would even suggest not using the ozone sensor at all unless you really need it.
I hope you enjoyed this video and learned something new. If you did please consider supporting me on Patreon. Feel free to ask any question in the comments section below and check my Arduino Projects Collection.