
How to Measure Indoor Air Quality with a Raspberry Pi, RuuviTags and PMS7003 - joshefin
https://joshefin.xyz/air-quality-with-raspberrypi-pms7003-and-java/
======
throwaway9d0291
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...](https://www.sciencedaily.com/releases/2018/08/180822091022.htm)

1:
[https://item.taobao.com/item.htm?id=550317428831](https://item.taobao.com/item.htm?id=550317428831)

~~~
electriclove
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?

~~~
throwaway9d0291
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.

~~~
joshefin
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...](https://www.letscontrolit.com/forum/viewtopic.php?t=3736&start=20)

~~~
throwaway9d0291
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.

------
paulgerhardt
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.

[1][https://m.mi.com/commodity/detail/1184500007](https://m.mi.com/commodity/detail/1184500007)

~~~
throwaway9d0291
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-...](https://smartairfilters.com/en/blog/xiaomi-particle-counter-
inaccurate-not-control-purifier/)

1: [https://www.sensirion.com/en/environmental-sensors/gas-
senso...](https://www.sensirion.com/en/environmental-sensors/gas-sensors/)

~~~
magicalhippo
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/](https://www.j-sens-sens-
syst.net/7/373/2018/) (pdf on the right)

~~~
throwaway9d0291
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.

~~~
magicalhippo
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.

------
AceJohnny2
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.

~~~
alex_dev
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.

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

------
simulate
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](https://news.ycombinator.com/item?id=19506983)

~~~
blaser-waffle
Thank you for sharing that.

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

------
ShakataGaNai
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.

~~~
joshefin
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.

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

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

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

~~~
SeanDav
> _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.

~~~
JudgeWapner
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!

------
sumoboy
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.

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

~~~
magoon
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”

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

------
softgrow
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?

~~~
joshefin
You can use the PM measurement that the sensor outputs to calculate the Air
Quality Index (for Europe:
[http://airindex.eea.europa.eu/](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.

------
_def
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.

------
heyoni
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.

~~~
joshefin
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.

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

------
tareqak
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](https://www.netatmo.com/en-us/aircare/homecoach)

~~~
wil421
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.

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

~~~
joshefin
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...](https://joshefin.xyz/temperature-humidity-
pressure-with-ruuvitag-raspberry-pi-and-java/)

------
amingilani
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?

~~~
solstice
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?

~~~
leggomylibro
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)

~~~
joshefin
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?

~~~
leggomylibro
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.

------
Havoc
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

~~~
joshefin
The fan inside the PMS7003 sensor is very quiet.

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

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

~~~
jbeales
Looks like it's using Prism.js: [https://prismjs.com](https://prismjs.com)

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

