Hacker News new | past | comments | ask | show | jobs | submit login
How to Measure Indoor Air Quality with a Raspberry Pi, RuuviTags and PMS7003 (joshefin.xyz)
292 points by joshefin on Aug 7, 2019 | hide | past | favorite | 97 comments

I think this is the main way to go if you care about air quality because unfortunately most consumer air quality monitors can be wildly inaccurate (i.e. detect nothing at all) even in day-to-day scenarios like making toast [0].

It's not limited to particulate matter either. You can get devices with reasonably accurate basics like temperature and humidity but as soon as you get into the actual air quality stuff like CO2, things start to fall apart. There are tons of devices that use wildly inaccurate TVOC sensors or fake their CO2 measurements (they estimate it based on H2 instead).

If you want anything remotely close to accuracy, I strongly recommend buying something that actually tells you which sensors it has inside it. Get datasheets for the sensors and check that their specs are reasonable for what you want. For example make sure that if you want to actually measure CO2 to buy something with an NDIR sensor like the Senseair S8 inside.

I wanted something I could plug into my home Prometheus/InfluxDB/Grafana setup so I bought [1] from Taobao. It lists all the sensors it uses, which are fairly good for the price. The device has a pretty simple TCP API that gives you JSON. Everything is Chinese but the measurements themselves are labelled in English and Google Translate works pretty well on the documentation.

0: https://www.sciencedaily.com/releases/2018/08/180822091022.h...

1: https://item.taobao.com/item.htm?id=550317428831

Thanks for posting this! From the millions of air purifiers and filters that are sold, it is clear that people care about air quality in their homes. But there doesn't seem to be a good option for accurately measuring air quality.

I appreciate the option you linked and wish there was an English version of it. If you were to build a consumer product, which air quality sensors would you want in it?

For CO2, which I've researched the most out of the various things that interest me, I'd want a Senseair K30 or S8 Commercial, an Amphenol Telaire T6613 or T6713, or a CozIR-A or CozIR-LP sensor.

For low cost, I'd go with the Senseair S8 Residential. It's not fantastically accurate but it's still a "real" sensor and you can get it for $20 from China.

For other aspects of air quality, I haven't finished researching the options yet.

Thanks for sharing. I wanted to get Winsen MH-Z19B, but Senseair S8 (residential) looks like a better, more reliable option, for a DIY project. One comparison: https://www.letscontrolit.com/forum/viewtopic.php?t=3736&sta...

If you'd asked me a few days ago I'd have said that the MH-Z19B is okay on a budget but now that I know you can get an S8-0053 for $20, I don't think I can recommend it.

If it's difficult for you to get the cheap S8s for some reason though, per that thread it looks like an MH-Z19B with calibration off is a decent choice.

[1] on Aliexpress, in English, $150 : https://www.aliexpress.com/item/32759169154.html

It does have English but it's not the same thing at all: It doesn't tell you which sensors are inside it (only the CO2 sensor) and it doesn't have any kind of machine-readable interface.

"S8 is short for S8-0053 model" from description. It seems like its using sensor you mentioned.

Yes, that's why I said "only the CO2 sensor". It has other sensors but doesn't tell you what those are.

And the CO2 sensor isn't much use to me without a way to read the sensor with a computer though and the device you linked doesn't have any kind of machine-readable interface.

For this task I absolutely love my Xiaomi Mijia indoor air quality sensor[1].

Under $50, nice touch screen, WiFi, TVOC, PM2.5, CO2, temp, humidity. Have one by a laser cutter (particulate), one in a paint booth(TVOC), and one in the office conference room (when the CO2 is higher than 1200 its time for a fresh air). A+ product and so much better than what I could build myself at that price point. If you find yourself in mainland China do yourself a favor and drop into a Xiaomi store.


I'm not sure about this particular sensor but Xiaomi doesn't have a good track record when it comes to accuracy when it comes to air particulates [0]. Also they claim to use a combined Sensirion TVOC + CO2 sensor, however the only TVOC + CO2 sensors Sensirion offers (SVM30, SGP30) [1] merely estimate CO2 concentration based on H2 levels, they don't actually measure it directly. These sensors tend to be wildly inaccurate. The spec sheet even says typical accuracy is 15%, which is pretty bad.

0: https://smartairfilters.com/en/blog/xiaomi-particle-counter-...

1: https://www.sensirion.com/en/environmental-sensors/gas-senso...

I plan on building something with the CCS811 and SGP30 just for comparison sake. This article was interesting [0].

[0] https://www.jaredwolff.com/finding-the-best-tvoc-sensor-ccs8...

I found this[1] article rather interesting, comparing the tVOC and CO2 measured by a consumer device with professional grade equipment. It seems the MOX sensor used in the consumer device (AMS iAQ-CORE-C) did rather well on tVOC, but poorly on CO2 as you mentioned.

[1]: https://www.j-sens-sens-syst.net/7/373/2018/ (pdf on the right)

The study is interesting but I wouldn't say it "did rather well", as they applied a calibration to it first:

"A regression analysis was performed to improve the accuracy of the Foobot FBT0002100 data relative to the GrayWolf data. Field calibration equations were then produced from the calibration dataset using the results from the GrayWolf instruments as dependent variables and the Foobot FBT0002100 as independent variables and tested on the validation dataset. An analysis in SPSS of the linear, quadratic, and cubic models was performed individually for each parameter to find the most accurate equation."

You can't do that unless you happen to have access to a different research quality sensor. If the Foobot had that out of the factory it'd be nice though.

That's not how I read it.

"Field calibration equations were then produced from the calibration dataset [...]" (emphasis mine).

Table 3 shows the calibration dataset for tVOC, which at least to me looks rather ok except for the outlier E.


Hmmm, does this by chance require an internet connection to operate?

I think that I could get by even with the Chinese menus, but the real problem for me is the mobile app. Is the mobile app strictly _required_ or is it an optional feature? I won't use a device that requires an app on my phone to function.

I have never touched their air purifier, but I did three other gadgets (TV box, some indoor camera, some light bulbs).

If privacy is your concern, I wouldn't recommend them. If stability is your concern, I wouldn't recommend them.

The light bulb works with an app only (probably to remove the need for a separate hub), the camera could be rooted to work offline-only (which is why I bought it, but I gave up after a couple of shots and it's currently sitting in my drawer), and the TV box is by far the noisiest device in my local network. It's like 60% of all DNS requests blocked by my Pi-hole.

Their devices are also the most unstable devices I own, to the point where I'm considering just throwing them in the trash and re-investing in another camera and a TV box. I've already replaced the bulb I've purchased with a Philips Hue system. Quite more expensive, but truly works locally.

I have the same experience - Xiaomi makes good and cheap hardware, but the software and reliability are bad. And if you want to keep your data private, skip them.

Is it linux or freebsd based? Can the firmware be reflashed?

Couldn't tell from the link, is there an English language option on the device?

Yes as well as Fahrenheit temperature if you prefer. Importing outside of China is a fairly highly mark up - $80 on BangGood: https://www.banggood.com/Xiaomi-Mijia-Air-Quality-Tester-Hig...

Although on the link you supplied, it does state "Note: Currently only supports Chinese interface display"

You can skip Banggood and save a bit. It's $52 from Xiaomi's official store [0] and $8 shipping from a forwarder [1], so $60 total.

[0]: https://detail.tmall.com/item.htm?id=582112668204

[1]: https://www.superbuy.com/en/page/query/freight/#areaId%3D3%2...

$64 on AliExpress. Pandacheck is a good tool for price comparison although it doesn't help deal with listings with multiple prices https://www.aliexpress.com/item/32970668564.html https://en.pandacheck.com

>when the CO2 is higher than 1200 its time for a fresh air

That's hilarious. Where I am from, in winter it's always at least 1500 ppm outside, and more than 2000 ppm after ~19:00.

Tangentially, for nearly a decade I've been looking for consumer-oriented wireless thermometers.

Something that I can either query over the network (any protocol), or that uploads to some cloud service that I can inspect. This was the original selling point of ZigBee, but it sounds like it only exists for industrial applications. Does anyone know of a $10-$30 network-capable thermometer?

I know they're relatively easy to hack together, as the OP project (and so many others like it) shows, but I'm specifically looking for a turnkey consumer solution, not something I'll have to spend a couple hours and multi-sourced parts to put together.

Xiaomi might have what you are looking for: https://www.aliexpress.com/item/32966216308.html. It's zigbee, multi-year battery powered, costs $10-15, does temperature and humility. No soldering, programming or any other diy.

You can get a zigbee radio that can serve as a hub for a few bucks, but if you want the turnkey consumer experience, you also need Xiaomi's zigbee hub which runs around 50 bucks. With that you also get an iOS app that integrates with homekit. Xiaomi makes a lot of other zigbee products at a similar price range that work with it.

You're not going to find any acceptable wifi solutions in the battery powered sensor category (there are a lot of other reasons that make wifi non-ideal for this), so unfortunately a hub is probably in your future for any option.

EDIT: BTLE devices may also be an option, but IoT applications my tldr option is that BT is too complicated to be worth it unless you need something you can't get elsewhere.

I have a bunch of Xiaomi zigbee sensors (door/window, temperature, and water leak) connected to my SmartThings hub -- You just need to install a device handler and they will work fine (though from what I've heard Xiaomi devices don't work well with most repeaters -- these are pretty much my only Zigbee devices so they are connected directly to my hub and work great).

I don't trust Xiaomi for anything connected directly to my network, but zigbee devices connected through something that I (kind of) trust works for me.

I run a company (https://flair.co) that builds a device you could use but is admittedly out of your proposed price range. That said, it's consumer/prosumer grade and you can network as many as you want together. You need at least one to be wired so it has enough power to fire up wifi and the rest can be run wired or on batteries. They mesh over a 915MHz radio and temp/humidity/light/pressure. We have been contemplating building a cheaper headless unit (these have a fancy little E-ink display) but haven't done it yet.

The actual device is here: https://flair.co/products/puck

There is a full fledged API (api.flair.co), desktop (my.flair.co) and apps of course. For what you are looking for, there is plenty of plotting built in but you can also export the data from the app as a csv/spreadsheet or grab it from the api.

Anyhow, it's definitely over your targeted price point but functionality wise, I think it does everything you might want.

As a consumer wanting a better HVAC solution, I've been following this space for years and am glad to see your company still here and offering products for sale.

I think there is an opportunity to grow your market if your Puck (or a new kind of Puck) can incorporate air quality sensors and make the data available. If you go this route, please see the recommendations in this comment as accuracy is key (https://news.ycombinator.com/item?id=20642939). I would certainly purchase multiple Pucks if they provided accurate data in a format that I could query myself if I wanted (no subscription BS please). People are concerned about air quality yet have no easy way to accurately measure it in their homes.

The bonus is that if I've got Pucks already, I would be more likely to purchase your Smart Vent products.

I also haven't found anything commercial in this space. Luckily it is a pretty easy and cheap (<$10 in parts) hack project.

I made a thermometer/barometer/hydrometer using an ESP-8266 wifi microcontroller ($5 on ebay) and a single BME280 sensor ($1 on ebay). Plugged into one of my left-over old 500mA phone chargers, it makes a wireless indoor weather station that speaks HTTP.

I bought the sensor on a breakout board, soldered a couple of wires, flashed micropython to the ESP-8266 (NodeMCU), and wrote wrote Python to POST my server with the temperature data, schedule a wakeup, then go to sleep.

But as you say, it took me a weekend of hacking around to build. This seems like exactly the kind of thing that should be available for $10 on eBay yet I can't find anything at all open.

I bought a bunch of wireless temperature/humidity sensors from AliExpress - they broadcast their readings once a minute via a small 433Mhz radio-transmitter.

Completely standalone, no WiFi, or other concerns. And because they're battery powered I think they're safe enough in the sauna!

From there I can get the readings via a USB-attached SDR dongle, and also sniff the radio-transmissions via a WiFi connected ESP8266 device with a radio-receiver.

Xiaomi Aqara temperature and humidity sensor.

* Under $10.

* Works with zigbee.

* Works out of the box with open source zigbee hubs. I personally have conbee II/deconz.

And the whole setup of these open source zigbee solutions usually just consists of plugging in the USB device and starting a docker container. It's not not the tedious open source setup as it often is with open source projects.

As a bonus you can use different zigbee devices from different manufacturers all together.

Thanks, sounds perfect, I'll try that.

I used RuuviTags (https://ruuvi.com/). They use a battery and send data over Bluetooth to your mobile phone.

You only get data from those when the phone is in bluetooth range. That's not very useful for long-term measurements. Unless you buy cheap android phone as a basestation I guess.

I have a bunch of SensorPushes at home which do the same, but they store the data for up to 20 days iirc, so it's effectively continuous data unless both my wife and I go away for a month or so.

It's popular to set up a Raspberry Pi or similar to act as a bridge between Bluetooth and wifi.

Agreed. Having to set up a raspberry pi or some other microcontroller is time consuming and the end product is ugly. I would like something small that connects to WiFi that operates off battery or could be plugged in permanently.

I recently purchased Wyze's sensor starter kit and have been quite impressed. The contactless sensors are tiny and have decent range to the corresponding bridge. Now Wyze just needs a documented, public API.

Pimoroni made this quite easy though if you know a bit of python https://shop.pimoroni.com/products/enviro-plus

Small and WiFi sound like an ESP8266 could be right for you. Or a Wemos D1 Mini, which uses an ESP but comes with a USB port.

Have you seen these remote temperature monitors from sensorpush? They seem to do a decent job and there is an internet gateway device to manage them if you want.


I use xiaomi to measure temperature, and send it to homeassistant.

There was a similar post on HN about four months ago describing an air quality monitor with a slightly different stack:

Build an Air Quality Monitor with InfluxDB, Grafana and Docker on a Raspberry Pi https://news.ycombinator.com/item?id=19506983

Thank you for sharing that.

This particular article & comments read like a collection of referral links to Taobao and Ali-Express.

I love the idea, but why in the name of the Flying Spaghetti Monster, would you use Java on an RPi? There are at least half a dozen python libs for the PMS7003.

Java is great on a RPi.

Many people don't realize but for a garbage collected language it can be quite efficient in terms of memory used. I have a long running web server that's forced to not exceed 50 MB of heap, having an up time of one year, which means no leaks.

And the great part of Java processes is that they can be fat and handle multiple things at the same time, so you only need one Java process for anything you'd like to do.

It's actually hard to achieve such stats with other garbage collected languages, including Python which in my experience is a memory hog and does reference counting AFAIK, along with relying on shitty C libraries, Python processes being leaky.

The other advantage that Java has, over compiled languages like Rust or Haskell is that you can compile your JAR on your workstation and then distribute just that.

This is less of a concern with interpreters like Python, however anybody that tried compiling stuff with something like Haskell for RPi knows how challenging that can be. And even for Python you often end up depending on native libraries that need to be compiled from source.

I mean, every Python beginner hates PostgreSQL just because of how hard it can be to install psycopg2 via pip/easy_install.

In my experience Java's ease of deployment is better than anything else. You just copy a JAR and that's it.

Python is great for prototyping, but my grand plan with this project is to add more sensors, integrate with some "smart home" devices and create a web UI - and I'm more comfortable coding all that in Java.

just be sure to allocate enough swap space for the gigabytes of bloat.

Should be possible to compile Java such that it runs very efficiently. Java is commonly used for Android after all.

My Android device that runs slower after each "update"?

> My Android device that runs slower after each "update"?

This is not only an Android problem, Apple is equally guilty of this. Arguably, more so.

Nor is it a Java problem. Some extremely speed-sensitive high perfomance code used by high speed trading algorithms use Java. This is in an environment where micro-seconds count.

When microseconds/frame rates/audio buffers count, you're only one garbage collection away from a complete thread lockup. Those gigabytes of heap aren't going to clean up themselves!

Python is also great for production, especially for tasks like this ;)

Java is generally faster than Python and I assume the OP is more familiar with it. I am not quite sure why you are asking that question?

there’s no reason not to use java. the pi is powerful and runs a full linux os. generally in device programming the language breakdown is C or Everything Else

I can just confirm what others are saying here - Java is great for the development of robust and reliable software. If you need even lower memory usage, you can compile the Java app with a GraalVM to a native image.

yeah the Java thing stopped me cold. That's bizarre on a Pi.

Currently running 4 JVM based solutions on 2 RPi's in our home. One is a fairly heavy one (OpenHAB 2), consuming 700 MB of memory. The others are simple importers (written in Scala), using around 50 MB each. It runs fast, is extremely stable (> 200 days uptime), very fast response times (< 100 ms), has a built-in dependency manager and is type-safe.

With this setup, I have aggregated more than 4 years of in-home data, ranging from radio-thermostats, 15 thermometers, continuous electricity usage, around 10 z-wave devices, 15 zigbee sensors, Philips Hue Lighting (8 bulbs, 8 switches), local weather updates, InfluxDB storage and a fairly complicated setup for climate control (including presence detection using OwnTracks / WiFi and operation of roller-shutters and sunscreens).

How is it bizarre? Java and Python are both pretty standard for devices like this since they don't require recompilation for ARM. And Java is more performant than Python in general.

In the end, you'll still need an air purifier unit to clean a room(s), or the entire house. Indoor air quality is a much bigger issue than most realize.

That depends on your location. I've built something similar to this tool that is discussed here and I've tested in multiple locations.

For example, Vienna air was so clean (<= 10 pm10 ug/m^3), that you don't need any purifiers or anything like that.

If you think Vienna's air is clean, you didn't measure during winter and/or during an inversion. You absolutely need air purifiers.

Are there stand-alone air purifier units that are worth the hassle?

Yes look at the Coway AP-1512HH. I have one in each bedroom. It also has a good air quality sensor and “auto” mode that’s driven by it. Among the competition, it cleans better than most and has a low TCO. Very quiet on “low”

I have one too. I got it based off of the recommendation from the Wirecutter: https://thewirecutter.com/reviews/best-air-purifier/ .

Alot of junk out there so thinking your cleaning the air effectively with a $100 unit is hilarious. You might filter more dust but not the particles you may really need. Products like Amaircare can be attached to your entire hvac and clean all the air multiple times an hour depending up on the size. Other room purifiers can target specific things like chemicals, dander, and dust but these units cost more because you get what you pay for. If you worked in a salon or paint store all day long, there is a lot of stuff floating around. Better units have very good filter(s) which is the difference.

The Winix C535 from Costco for $100 is a great deal: https://www.costco.com/Winix-C535-Air-Cleaner-with-PlasmaWav...


I’ve looked at building one of these, but what new actionable information do you get? I’ve been wondering if it might say the room is dusty and then I could run the HEPA vacuum cleaner to bring it down. Or is this just for measurement geeks?

You can use the PM measurement that the sensor outputs to calculate the Air Quality Index (for Europe: http://airindex.eea.europa.eu/) and for example, make it send you a notification when the pollution level goes up, so you can turn on the air purifier or vacuum or open the windows.

Just yesterday I thought of building something similar. I often get tired from being in my small flat and I'm curious if CO2 could have anything to do with it.

Is there a spec sheet on how accurate/precise the specific recommended sensor is? I'm not even sure exactly how to describe a particle sensor but the aliexpress page is full of typos and I'm just wondering if it'll at least be able to measure the effectiveness of my indoor air purifier.

If your air purifier has a screen and shows the air quality, it's most probably using a PM sensor like the one I write about here.

How accurate is PMS7003? If for example, you need to know the precise and exact concentration of particulate matter in the air - then currently available low-cost PM sensors are not to be considered accurate. But, if you need to know if the air quality in your home is good, fair, moderate, poor or very poor, then it's good enough.

These sensors also need calibration every week or so, which basically involves opening the windows to feed fresh air.

Does anyone know how accurate this set up would be be in comparison with the NetAtmo Indoor Air Quality monitor [0]?

[0] https://www.netatmo.com/en-us/aircare/homecoach

If you could find out what sensor the NetAtmo is using you could do an apples to apples comparison.

I bought a cheap soil sensor from microcenter that is absolute garbage. According to a few YouTubers it would corrode in a couple weeks. They recommended some higher quality sensors.

Netatmo only measures CO2 and depending on your location it would be more useful to know about particulate matter in the air.

What's the RuuviTag for? I can't see it mentioned in the article.

RuuviTag is a sensor capable of measuring the temperature, relative air humidity, and atmospheric pressure and sending the data over Bluetooth. I wrote about it in a linked article - https://joshefin.xyz/temperature-humidity-pressure-with-ruuv...

What is the difference between an indoor air quality monitor and an outdoor one?

Can't I just put this one outdoors in an out-of-the-rain-and-sun area and call it an outdoor air quality monitor?

PMS7003, and most probably all other low-cost PM sensors with the same working principle, is not made to be used outdoors. Although used in many DIY projects for outdoor air quality monitoring, researches show that high humidity badly affects the PM measurements. Some have tried to heat the air before entering the sensor or to derive a correction factor, but mostly unsuccessfully.

These sensors are not as accurate as more expensive professional devices but are good enough to give an idea of the pollution in the air.

From my experience so far, PMS7003 measurements are comparable to official government air quality measurements available for my neighborhood.

whats the next step up then? the unit you'd buy for an outdoor sensor.

Sorry, I can't recommend any. If you just want to know if the air is polluted or not, and humidity does not go over 70%, any low-cost sensor would be good.

I assume that humidity messes with the detection of particle size. I have a LaserEgg particulate matter detector and they use a laser beam to count the particles in the air that flows through the device (via a small aspirating fan). So if particles are more clumped due to higher humidity, then I assume that would give you faulty/misleading readings?

Maybe add another sensor? Humidity and temperature seem like useful readings for these sorts of monitors, and a lot of those sensors include barometric pressure for free.

Although there is an old joke about their accuracy: "how do you use a cheap pressure sensor to determine altitude? Drop it out the window and count how long it takes to hit the ground."

There are also affordable gas concentration sensors which can be useful for this sort of thing. Some are even marketed as 'air quality sensors' because they exhibit sensitivity to several different types of gases, but they aren't always useful because the output is usually just the sum of the sensor's response to each individual gas. Still, if you want a project to probably depress you in 10 years, get a CO2 sensor like the MH-Z19B and make yourself a datalogger. (Keep in mind that it's a little power-hungry, up to 150mA @5V = 0.75W)

The CO2 sensor would be a nice addition to my project. Do you have experience with the MH-Z19B, is it accurate enough for indoor use?

I've only used it briefly, but I have also seen it used in DIY building management projects. The biggest issue I saw with it was power consumption: up to 150mA @5V is 0.75W, and I think it can take a bit of time to 'warm up' so you can't just turn it on for a few milliseconds every hour. But that should be fine if it's plugged into the wall.

It's also fairly expensive, on the order of $10 rather than $1 last I checked.

Humidity is the biggest confounding variable for pm measurement. A bme280 is recommended to be able to compensate

Also likely not made to deal with high and low temps, probably components that rust, etc.

I've got a rasp + air sensor.

Quickly turned it off. It has a tiny fan that goes bzzzz. No thanks - my peace & quiet trumps my need to know air particle count

The fan inside the PMS7003 sensor is very quiet.

The only thing worse than no data is bad data. I wouldn't trust these cheap sensors people keep hawking.

I love the way this blog displays code. Just beautiful.

Looks like it's using Prism.js: https://prismjs.com

Yes, Prism is great. Most of the blogs cramp the code in width, I let it spread it's wings full width.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact