Track air quality anywhere with Raspberry Pi

When you venture outside and take a deep breath, you expect to be inhaling a heap of fresh air, particularly if you’re in the countryside. But in truth, you’re just as likely to be filling your lungs with pollutants from dirt, dust, pollen spores, gases, and even lead. There’s just no getting away from the fact that a good percentage of air can be deemed unhealthy, so being able to monitor it on the go with a flick of a switch could be welcome news.

The screen displays the current air quality as a number and explains what that number means

Arnov Sharma has created a handheld air quality meter which can use a Raspberry Pi Pico 2 connected to a gas sensor to display the current levels of a host of hazards. “My Air Quality Meter was created with the intention of measuring the degree of air pollution in my city,” he explains. “Since we’d just had an air quality issue in New Delhi, where I live, I thought it would be a good idea to try to develop a project to measure the pollution level.”

Delhi has suffered record pollution levels of late, with the Air Quality Index (AQI) measuring as high as 1500 in November 2024. Toxic air of this magnitude, which led to smog descending over the area, is 15 times the level considered satisfactory for breathing by the World Health Organisation. It was so bad that schools were temporarily closed, construction was halted, and flights were disrupted.

What’s more, it hasn’t become infinitely better since, with an AQI reading in January 2025 showing the air has remained poor, albeit at a level of 262.

Turning detective

With his project, Arnov has sought to detect carbon dioxide, smoke, benzene, alcohol, nitrogen oxide, and ammonia in the air. In doing so, his resulting device is able to display the levels of gases produced by the incomplete combustion of fossil fuels, wood, and coal, as well as some of those pumped out by vehicles and emitted from hazardous waste sites. The detection of ammonia is indicative of the amount of livestock waste, decaying organic matter, and fertiliser production. It helps to build a general understanding of the air quality in any given location, Arnov says.

So while Arnov’s meter doesn’t quite go as far as matching an AQI evaluation — which also includes assessing the PM2.5 and PM10 types of particulate matter, along with oxygen, nitrogen dioxide, sulphur dioxide, and carbon monoxide — it’s still ultra-useful. What’s more, he designed his meter so that it would also be inexpensive, meaning this open-source project should be within the reach of wide numbers of people. This influenced his choice of components.

To test the build, Arnov used a breadboard and simply connected the sensor and a Raspberry Pi Pico 2

“I used the MQ135 sensor and found it to be incredibly versatile for pollution control, environmental monitoring, and checking air quality,” Arnov says, of a module that can be picked up for less than £10/$10. “It was handy for various projects where I needed to monitor the air around me, particularly in spotting harmful gases. The best part is that it’s super easy to get hold of. It doesn’t burn a hole in your pocket, making it an all-around great pick.”

Displaying values

Arnov says planning the project was simple. “I already had an idea of the components I wanted to use, which was the PCBWay MQ135 sensor with Raspberry Pi Pico 2 — Pico is my preferred microcontroller for projects unrelated to wireless LAN. I first created a basic breadboard setup consisting of the Pico and MQ135 sensor.” This allowed him to make use of the sensor’s outputs: one that generates an analogue voltage signal based on the gas concentration and a digital signal based on the gas concentration beyond a threshold.

Having written a short program to test the sensor’s readings, ensuring it returned both analogue and digital values, Arnov then looked to refine the project further. To be effective, he needed the readings to be displayed on a screen — it shows the specific particle levels in real time — so he chose a tiny, 0.96-inch SSD1306 OLED display, again available for an extremely low price. “I then constructed a body to house all of the components inside a nice enclosure,” he continues, explaining that he used the CAD facilities of Autodesk Fusion to complete the task. “This wasn’t challenging: I have experience with industrial design, so creating a case was easy enough.”

The casing was designed to be 3D-printed and, as well as being functional, Arnov added some aesthetic flourishes

Gas panic

At this stage, Arnov made a big decision. He swapped out the Raspberry Pi Pico 2 microcontroller for a Firebeetle 2 ESP32-E, which may sound like sacrilege, but he had his reasons. Chief among them was a lack of space in the enclosure that led to a power-related issue. “I was using a lithium cell as a power supply and, in order to charge the lithium cell, Pico would require the use of an additional board,” he explains. “Firebeetle has an on-board TP4056 lithium cell charging circuit.”

Yet, as he says, “Pico would be just as effective” and he has plans to return to Raspberry Pi. “I will use the RP2040 chip directly on a custom PCB that will also include a lithium cell charging circuit,” he explains. As with the Firebeetle, this would resolve the problem of space.

Regardless, the device works well. Arnov used Arduino IDE to write the code and upload it to the board. The program takes the raw analogue value — of between zero and 4095 — and reduces it to a range between zero and 1023, which is needed for an air quality measurement. It then helpfully describes the value as either very poor, poor, moderate, good, or excellent, so the user can immediately assess the current state of hazardous gases in the environment. 

To make it easier to carry and operate, Arnov made it possible to attach a keychain or ID card strap to the device

So how has it fared? In tests, Arnov found that city readings ranged between 550 and 620 regardless of whether he was close to a major road, industrial region, or green space. It’s proof, if any were needed, that such gadgets could be useful in helping people prepare for unsafe environments — and that urgent work is needed to improve matters in some parts of the world.

Raspberry Pi Official Magazine #151 out NOW!

You can grab the latest issue right now from Tesco, Sainsbury’s, Asda, WHSmith, and other newsagents, including the Raspberry Pi Store in Cambridge. It’s also available from our online store, which ships around the world. And you can get a digital version via our app on Android or iOS.

You can also subscribe to the print version of our magazine. Not only do we deliver worldwide, but people who sign up to the six- or twelve-month print subscription get a FREE Raspberry Pi Pico W!

The post Track air quality anywhere with Raspberry Pi appeared first on Raspberry Pi.



from News - Raspberry Pi https://ift.tt/ukcRhZm

Comments

Popular Posts