Ultra Low Cost Air Quality Monitoring with LoRaWAN and The Things Network

One of the first use cases we considered for The Things Network in Birmingham was air quality monitoring. A few fun facts about air quality in Birmingham. According to The American Lung Association, Birmingham ranks in the top 20 for annual particle pollution, even though our 24 hour numbers are quite good. It was right here in Birmingham that the first ever emergency shutdown of smokestack industry was ordered by a judge under the provisions of The Clean Air Act in response to extremely unhealthy conditions. Things are a lot better now, but they still aren’t great. One of our nonprofit partners would like to understand air pollution on a much more granular level than the government monitoring stations allow. How can we achieve that?

To start with, we need a sensor package that is cheap. Really cheap. It also has to be accurate. We need the ability to deploy it anywhere, even in places where power and an internet connection aren’t available. Let’s see… Low enough power to run on a battery or small solar panel, and able to broadcast data for long distances. Sound familiar? We think LoRaWAN is a pretty good place to start.

Building on the successes we have had getting the commodity ESP32 + LoRa boards connected to The Things Network, we have started prototyping a low cost, low power air quality monitor for remote deployments. For the processing and connectivity, we are using the Heltec dev boards we already have on hand, and for the particulate measurements we are turning to the Plantower PMS5003 sensor. This sensor uses a laser scattering technique for measuring various particle sizes, much like the more expensive sensors you see in commercial equipment. It’s easy to use, and communicates with our little dev board via a serial protocol. The ESP32 has plenty of ports, so hooking it up was not an issue. The total cost for the sensor and board? Less than $50, and that’s ordering single quantity. Add a LiPo battery, small solar panel and commodity enclosure, and the whole package can be built for well under $100. Not bad!

The setup is pretty simple, only four pins. 5v, ground, tx and rx. Easy. One of the things I kinda dig about the ESP32 board is that it is possible to direct the hardware UART to pins of your choice, assuming they aren’t used for some other function.  The annotated diagram below shows the pins that I used:

Screen Shot 2018-09-14 at 3.44.19 PM

One thing that is a bit different here from typical hardware serial code on Atmel processors like the popular 328 and others used in Arduinos is the way the port is initialized.  The first line below defines the port, and tells it to use UART2 which should be safe on most ESP32 boards.  Some of them use UART1 for flash, so it’s probably easiest to just avoid that one.  The second line below initializes the port with its speed, configuration, and the two pins that will be used for rx and tx, respectively.  for those that have used other Arduino boards, you’ll immediately notice the difference in the way Serial.begin() is structured.

HardwareSerial PMSSerial(2);

PMSSerial.begin(9600, SERIAL_8N1, 36, 37);

There are several Arduino libraries available to support the PMSX003 series of sensors.  I’ve had good luck with this one.

From this point on it is just a matter of reading the sensor and sending the data.  If you want to see an example that works on the Heltec ESP32 LoRa boards, I’ve dropped a quick and dirty example in Github.  This example will join The Things Network via OTAA, and then start sending a PM2.5 reading approximately every minute.

The next step is to take the data that we are sending up to TTN, map it, and start some trend analysis.  Those tasks will get their own writeups as the project progresses.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s