Arduino projectsElectronic projects

Air Quality Monitor Arduino Meter

Air Quality Monitor Arduino Meter

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

Have you ever wondered about the quality of the air you breathe, or why you wake up tired after a full night’s sleep or sometimes feel sleepy at the office? Not only can bad air quality have negative health effects, it can also cause fatigue, headaches, loss of concentration, increased heart rate, and more. Monitoring the quality of your air may actually be more important than you think. So in this tutorial, you’ll learn how to build your own air quality monitor that can measure PM2.5, CO2, VOCs, ozone, as well as temperature and humidity.

outline

We will explain how each air quality parameter affects us and how the sensor works. The heart of this project is the Arduino Pro Mini board, which is combined with a 2.8 inch Nextion touch display to provide a proper user interface.

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

You can view measurements from all sensors in real time, and clicking on a specific sensor will bring up the values ​​for that sensor for the last 24 hours. There is also a dimming function that allows you to lower the brightness of the display or turn it off completely. This is handy if you want to track the air quality in your bedroom at night, for example.

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

You can turn off the screen at night and check the values ​​of each sensor individually the next day.

Nonetheless, now I’m going to walk you through the entire process of building it and explain how everything works. After this video, you can build it yourself. So, let’s get started.

PM2.5 Sensor – PMS5003

There are four main components or air quality sensors in this device. We are using the PMS5003 sensor to measure PM2.5 or particulate matter in the air, which is about 2.5 microns in diameter. Particulate matter is the most harmful form of air pollution because it can penetrate deep into the lungs, bloodstream and brain, causing many health problems.

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

This sensor works on the principle of laser scattering. The sensor has a fan that creates a controlled airflow, which forces environmental particles through a focused laser beam.

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

The particles cause light scattering, which is detected by a photodiode and converted into PM concentration with the help of a microprocessor. The results of this sensor are very reliable and can output PM1 and PM10 values ​​along with PM2.5.

CO2 Sensor – MH-Z19

Next, we are using the MH-Z19 sensor for CO2 or carbon dioxide measurement. Since people exhale carbon dioxide while breathing, indoor CO2 concentrations can easily become very high. CO2 is not only dangerous at high concentrations, but can also cause drowsiness, fatigue, and decreased productivity.

DIY Air Quality Monitor – PM2.5, CO2, VOC, Ozone, Temperature and Humidity Arduino Meter

The sensor uses the principle of non-dispersive infrared to measure CO2 in the air. The infrared source transmits light through a tube filled with the air we are measuring. On the opposite side of the infrared source is an optical filter and an IR detector that measures the amount of IR light passing through.

The CO2 gas molecules present in the air we are measuring absorb a certain range of infrared light while allowing some wavelengths to pass through. Therefore, the CO2 level is calculated based on the difference between the amount of light emitted and the amount of IR light received by the detector. The results from this sensor are also very accurate.

VOC and Ozone Sensors – MP503 and MQ-131

For VOC and ozone measurements we use MP503 and MQ131 gas sensors. These are heated metal oxide sensors and their working principle is based on detecting a change in resistance in the presence of the target gas.

A specific current flows through the metal substrate and its resistance changes depending on the amount of gas present.

The target gas for the MQ131 sensor is ozone, which can be produced in typical household environments by products such as certain air purifiers, facial steamers, and germicidal lamps that generate ultraviolet light.

On the other hand, the MP503 sensor has several target gases, including alcohol, smoke, isobutane, and methanol. VOC stands for Volatile Organic Compounds, and is an organic compound that comes from products we use every day, such as laundry detergents, detergents, air fresheners, paints, and makeup. VOCs can cause many negative health effects, including headaches, eye irritation, skin reactions, and dizziness.

DIY Arduino Air Quality Monitor – Schematic

Nonetheless, let’s now look at the schematic and explain how everything should be connected.

You can get the components needed for this Arduino air quality monitor from the link below.

  • PMS5003 PM Sensor ………………………
  • MH-Z19 CO2 sensor …………………………………….
  • MQ-131 Ozone Sensor ………………………………………………….
  • MP503 VOC Sensor ……………………………………
  • DHT22 Temperature and Humidity Sensor …………………..
  • Next 2.8″ display …………………………………….
  • DS3231 RTC ………………………………………… …….
  • Arduino Pro Mini…………………………………………………………………
  • Distance/Spacer Nut M3 ……………………………….
  • Mini USB connector ………………………
  • Pin header ……………………………………………………………………………….
  • 2 position switch ……………………………………
  • Capacitor values: 0.1uF ceramic and 10uF electrolytic
  • Transistor – 2N3904
  • conversion

Disclosure: This is an affiliate link. As an Amazon Associate, I earn from qualifying purchases.

Correct resistor values: R1 = 1K, R2 = 2K, R6 = 100K or 1M, R7 = 1K

The PM2.5 sensor communicates with the Arduino via a serial interface. It operates at 5V, but the incoming RX logic level operates at 3.3V, so a voltage divider is needed for this. The CO2 sensor and the Nextion display also use serial communication. While the VOC and ozone sensors use the analog inputs on the Arduino to read them, the DHT22 temperature and humidity sensor uses the digital pins for that purpose.

Two transistors are used to activate the sensor heater. Also, a Real Time Clock module is used to keep track of the time when storing sensor values, and it uses I2C communication. The entire device is powered by 5V via a Mini USB connector.

Reference: 8 Best Arduino Starter Kits [2021 Update]

Now if we try to connect everything together it will become quite a mess due to the many connections.

So, this project definitely requires a PCB.

Building a PCB for an Arduino Air Quality Monitor

To create the PCB for this project we will actually be using Altium Designer, the sponsor of this video.

Altium Designer represents decades of innovation and development dedicated to creating a truly integrated design environment. Striking the perfect balance between performance and ease of use, Altium Designer has established itself as the most widely used PCB design solution on the market.

Now I’m going to show you how I designed the PCB for this project using Altium Designer. I started by creating a schematic for the project. Altium Designer has a built-in library of basic electronic components, but you can also search for components directly from manufacturers, which makes it very convenient to find the parts you need for your project.

For example, I used this manufacturer parts search feature to find a Mini USB connector. Here, you can also easily access data related to the component, such as 3D models, footprints, dimensions, etc.

You can also create your own component library. I created most of the components for this project myself, because I wanted to create a unique 3D footprint for each part, and eventually create the entire PCB in 3D. You can use any CAD software to create a 3D model of the PCB footprint, save the file as a .STEP file, and import it into Altium Designer.

Once the schematic was finished, I created the PCB. I arranged the components the way I wanted them and used the Auto Route feature to have the software automatically create all the traces with a few clicks.

If necessary, you can create or adjust them manually. You can also set design rules for how the auto-router creates traces, set different widths for each net, etc. At this point, we also export a 3D file of the entire PCB assembly to view the PCB in 3D and use it to design the case later.

Nonetheless, thanks to Altium for sponsoring this educational content. To learn more about this software and get started using it, check out the links below. You can also try the web-based Altium 365 Viewer for project previews and files.

Altium Designer Free Trial – https://www.altium.com/yt/howtomechatronics
Altium 365 Viewer: https://www.altium.com/viewer

The Altium Designer project file is:

Altium Designer files including project files, libraries, and .STEP files for 3D models of electronic components:

PCB Gerber Files:

Okay, once I’ve finished the PCB, I’ve generated the Gerber and NC Drill files and put them into a single zip file so I’m ready to order the PCB for fabrication.

I ordered the PCB from JCLPCB. You can just drag and drop the zip file here. Once uploaded, you will get all the visual information about the PCB.

Then you can select the properties you want and order the PCB at a reasonable price.

PCB Assembly

A few days later the PCB arrived. The quality of the PCB is excellent, everything is as per the design.

Now we are ready to start assembling the PCB. I started by inserting and soldering the smaller components: the resistors and the two transistors.

Then you can solder the Arduino Pro Mini board in place. However, you will need to solder the pin headers first. You may not need all the pins, but make sure you don’t miss any of the ones you need, like the A4, A5, and DTR pins. Also, make sure you have the exact same Arduino Pro Mini board, as the pin layout may be different.

Next, you can insert the DHT22 sensor into place. To do this, you first need to bend the pin 90 degrees. Sometimes, you can also use Blu-tack adhesive to keep the part in place while soldering.

The two capacitors used in this project are to stabilize the power supply. The board’s power comes from a mini USB connector that can be connected to 5V.

You will need to solder two switches just above the power supply connector, one to turn the device on and off and one to upload the sketch to the Arduino board. Then you can plug in the pin headers for the USB-UART interface, the display, and the PM2.5 sensor, as well as the VOC, ozone, and CO2 sensors.

Next, to re-solder the DS3231 real time clock module, you will first need to bend the pins 90 degrees. Once that is soldered, you can insert a battery that will keep track of the time even when the main PCB is powered off. This practically completes the PCB, and all that is left is to prepare the cables that will be used to connect the PM2.5 sensor and the display to the PCB. I soldered a male pin header to the cable that came with the sensor, making it easy to connect to the PCB. To connect the display to the PCB, I soldered 4 wires to the back of the display connector, which I then connected to the PCB.

That’s it, the Air Quality Monitor is actually done. Of course, what we need to do now is to create some kind of box or case for it. Since we have a 3D model of the entire PCB assembly in Altium Designer, we can import it into CAD software and design the case.

I used SOLIDWORKS for this purpose and made the simplest case with two parts and a few nuts and bolts. I decided to make the case using clear acrylic because I like the way the PCB and components are exposed and it’s also a great way to show off your DIY project.

You can download this DYI Air Quality Monitor 3D model as well as explore it in your browser on Thangs.

Download 3D models from Thangs.

Making a Case for Air Quality Monitors

The acrylic I will be using is a 4mm square which fits the display perfectly. As I do not currently have a CNC machine, I cut the shapes manually using a simple metal hacksaw.

To make the display holes, I first drilled two holes with a drill. Then I carefully cut the shape through the blade of a mini hacksaw. I used a simple file to trim the shape. Then I used a 3mm drill to make all the holes for attaching the PCB and connecting the two acrylic plates together.

At this point I removed the protective foil from the acrylic. It was a pretty satisfying process to be honest. I used M3 bolts and nuts to attach the PCB to the base plate. You will need M2 bolts to attach the PM2.5 sensor to the plate.

Next, you can use distance nuts to join the two plates together. Using one female threaded nut and one male threaded nut, you can easily get the desired distance between the two plates.

I personally really like how this case came out. Plus, it’s very functional, allowing air to circulate easily around the sensor.

Programming

Okay, now you can power up the device and upload the program. You can power the air quality monitor via the mini USB connector, you can get 5V from a 5V USB adapter, 5V phone charger or a power bank.

To upload a program to the Arduino Pro Mini board, you will need a USB-to-serial UART interface that can be connected to the programming header. Before connecting the device to the computer USB, you must first power up the device, otherwise the power from the computer USB, which is only 500mA, may not work properly. You will also need to toggle the upload switch on the PCB when uploading the Arduino sketch.

You can download the Arduino code and Nextion display program here.

To upload a sketch to your Arduino Pro Mini board, you must first select the board in the Arduino IDE, select the appropriate processor version, select the port, and select “USBasp” as the programming method.

Once you have uploaded the code to your Arduino, you will also need to upload the code to your Nextion display. The Nextion display actually has an ARM controller built into it that controls the display itself.

All graphics such as buttons, text, images, variables etc. are created and controlled by the display itself. Nextion displays have a dedicated Nextion editor to create all of these. Communicate with the display and Arduino using only 2 wires using serial communication. The Arduino simply sends values ​​from the sensor to the display and vice versa, sending data from the display to the Arduino when needed.

To upload the display program, you will need a microSD card where you can save the output .TFT files from the Nextion editor.

The display has a card reader that allows you to insert a microSD card while the device is powered off. Then, when you power up the device, the program will be uploaded to the display. Now, when you remove the card and power it back up, the air quality monitor will start working.

Code Description

So we are using libraries for each sensor and you can find them in the links MHZ19, PMS, MQ131, DHT, DS3231. I would recommend reading the library documentation and trying the examples to better understand how to read data from each sensor.

Since both the MH-Z19 and the PMS5003 sensors use serial communication, we are also using the SoftwareSerial library. The Arduino and the Nextion display also use the serial port for communication, in this case we are using the default hardware serial.

So the Arduino reads the sensor and sends that data to the Nextion display. Here is an example:

Serial.print("tempV.val=");
Serial.print(temp);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);Code language: Arduino (arduino)

So if you have a variable called “tempV” on your nextion display and you want to update its value, you need to send a command to the nextion like “tempV.val=22”. So let’s say the variable name, “.val”, and the value is 22. The first two lines of code do that, and to make the Nextion display accept this command, or indeed any command, you need to send three unique commands. The “write” command.

The Nextion display program has a timer that runs in a loop, just like the Arduino code loop, and continuously updates the numbers on the display.

This timer event also has code to change the background color of each sensor based on its value.

The second page has a waveform that gets values ​​from the Arduino’s stored values. There are explanations in the code comments, so you can find more information about the Arduino code itself.

The time and Y-axis values ​​are also taken from the Arduino.

In addition to the numbers on the main screen, you will notice that there is a transparent object on top of the waveform called “Hotstop” in the Nextion editor, which acts as a button. When you press the hotstop on the waveform, you will see that it will send you back to “Page 0” in the Events section.

Overall, this is how the program for this Arduino air quality monitor works. Of course, to fully understand how it works, you need to learn and understand how each sensor works in the library and how the Nextion display works.

For VOC sensors, we only read raw data from this sensor, not ppm or ppb values. It is an analog value from 0 to 1024. Higher values ​​indicate the presence of VOC.

For ozone sensor, you need to set setTimeToRead() and setR0() values ​​correctly according to the calibration example in the library to get more accurate output. However, the longer setTimeToRead, the more the program will block while sampling and everything else will freeze. Of course, there are ways to work around this. It is better not to use ozone sensor at all unless absolutely necessary.

I hope you learned something new from watching this video. If so, please support me on Patreon. Feel free to ask questions in the comments section below and check out my collection of Arduino projects.

Source

Back to top button