LoRa Powered Air Quality Monitoring System

2 1632 Easy

In the recent years, air pollution has been a growing concern for the harmful effects it has on our environment. The problem is prevailing particularly in urban cities because of the increased traffic and a wide array of industries which produce a lot of harmful gases as a bi-product of manufacturing. Apart from this, indoor air pollution is also a great concern in metro cities. According to research, the air inside our house is even more polluted compared to the air in outdoor environments.

Hence, a number of countries have already taken preventive measures and setup various air and weather quality monitoring systems in the popular destinations of their big cities so that they can obtain the data and take the necessary steps to prevent the adverse effects of air pollution. But there are several problems with the present systems. Firstly, these systems use the primitive methods which includes collecting air samples and get them tested in a laboratory and even though this methodology is reliable, it is highly ineffective and very expensive (the laboratory equipment). Secondly, there is no system yet created to address the issue of indoor air pollution which has a harmful effect on the health of a great number of individuals every year. So, it is of utmost importance to develop an advanced system which can overcome the above drawbacks.




Get PCBs for Your Projects Manufactured


You must check out PCBWAY for ordering PCBs online for cheap!

You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. Check out their online Gerber viewer function. PCBWAY takes care of its customers a lot that's why they offer reward points with every purchase that you make from them these reward points can be redeemed for various useful items from their gift shop.




So, what is the Solution?? This Project!!


This project presents a real-time and long-range air pollution monitoring system for indoor and outdoor environments. The system implemented a wireless sensor network using LoraWAN technology for data communication between all nodes and sensors. The system consists of two nodes distributed within 1 Km distance to the gateway for measuring the concentration of VOCs (Volatile Organic Compounds), carbon dioxide andPM2.5 (Particulate Matter 2.5um) readings. Experimental results show the system is reliable in both indoor and outdoor applications. The distance coverage achieved up to 900m and can be displayed through a web-based client (Thingspeak) and also from an Android or iOS application. The experiment with LoraWAN transmission has shown that the LoraWAN technology is very suitable for the air pollution system especially in long-range transmission compared to other wireless transmission techniques and the power consumption of the system is also considerably lower than the existing systems and also some actuation techniques would be discussed and demonstrated.

Before we get started, please have a look at the note below. It is addressed to the judges of the Helium Contest.




2. Important Note

Even though this project is not created using the Helium Network or Console, it is very easy to migrate from the platform we will be using now.

I would like to request the judges to regard this submission as I tried for almost 2 months to set up a Helium hotspot in India, but nothing I did work. I even tried creating my own Hotspot but I had no luck there too. Finally, I picked up a generic LoRa Gateway and created my whole project on the Indian Lora sub-band of 865-867 Mhz. I would again like to apologize for not using the provided Hardware for this project but I assure you that I will be using it for my future projects once the Helium Network support comes to India.

But this project can be easily migrated to any platform of our choice and so I will also cover the Helium console setup and setting up the Helium Miner in this project. So, let's get started with the Hardware and software requirements of this project.




3. Hardware and Software Components for this Project

3.1 Hardware Components of the Project

3.1.1LG01N Single Channel LoRa Gateway by Dragino


LG01-N is an open-source single-channel LoRa Gateway. It lets you bridge LoRa wireless network to an IP network via Wi-Fi, Ethernet, Or 3G/4G cellular via an optional LTE module. The LoRa wireless allows users to send data and reach extremely long ranges at low data rates. It provides ultra-long range spread spectrum communication and high interference immunity. LG01-N has rich internet connection methods such as a Wi-Fi interface, Ethernet port, and USB host port.

LG01-N can support Limited LoraWAN protocol in single frequency and customized LoRa transmit protocol. Different from LG01-P/LG01-S, LG01-N uses Linux to directly control the sx1276/sx1278 LoRa module which increases communication efficiency and simplifies software design.


3.1.2 Dragino Lora Shield for Arduino v1.4 (EU868)


LoRa Shield is a long-range transceiver on an Arduino shield form factor and based on Open source library. The Shield allows the user to send data and reach extremely long ranges at low data-rates. It provides ultra-long range spread spectrum communication and high interference immunity whilst minimizing current consumption.

LoRa Shield is based on Semtech SX1276/SX1278 chip, it targets professional wireless sensor network applications such as irrigation systems, smart metering, smart cities, smartphone detection, and so on.


Compatible with 3.3v or 5v I/O Arduino Board.

Frequency Band: 915MHz/868 MHZ/433 MHZ (Pre-configure in factory)

Low power consumption

Compatible with Arduino Leonardo, Uno, Mega, DUE

External Antenna via I-Pex connector

3.1.3 CCS811 Ultra Low Power Digital Gas Sensor



The CCS811 is an ultra-low power digital gas sensor solution which integrates a metal oxide (MOX) gas sensor to detect a wide range of Volatile Organic Compounds (VOCs) for indoor air quality monitoring with a microcontroller unit (MCU), which includes an Analog-to-Digital converter (ADC), and an I²C interface.

CCS811 is based on ams unique micro-hotplate technology which enables a highly reliable solution for gas sensors, very fast cycle times and a significant reduction in average power consumption. The integrated MCU manages the sensor drive modes and raw sensor data measured while detecting VOCs. The I²C digital interface significantly simplifies the hardware and software design, enabling a faster time to market.

CCS811 supports intelligent algorithms to process raw sensor measurements to output a TVOC value or equivalent CO2 (eCO2) levels, where the main cause of VOCs is from humans. CCS811 supports multiple measurement modes that have been optimized for low-power consumption during an active sensor measurement and idle mode extending battery life in portable applications.


Modes of Operation

The CCS811 has 5 modes of operation as follows

Mode 0: Idle, low current mode

Mode 1: Constant power mode, IAQ measurement every second

Mode 2: Pulse heating mode IAQ measurement every 10 seconds

Mode 3: Low power pulse heating mode IAQ measurement every 60 seconds

Mode 4: Constant power mode, sensor measurement every 250ms

3.1.4 MICS – 5524 Gas Sensor Module


This breakout makes it easy to use this nice sensor from SGX Sensortech. The MiCS-5524 is a robust MEMS sensor for indoor carbon monoxide and natural gas leakage detection, it's suitable also for indoor air quality monitoring; breath checker and early fire detection.

Please note: This sensor is sensitive to CO (~ 1 to 1000 ppm), Ammonia (~ 1 to 500 ppm), Ethanol (~ 10 to 500 ppm), H2 (~ 1 - 1000 ppm), and Methane / Propane / Iso-Butane (~ 1, 000++ ppm). However, it can't tell you which gas it has detected.

3.1.5PM2.5 GP2Y1010AU0F Dust Smoke Particle Sensor


This PM2.5 GP2Y1010AU0F Dust Smoke Particle Sensor is an infrared emitting diode (IRED) and a phototransistor are diagonally arranged into this device. It detects the reflected light of dust in the air. Especially, it is effective to detect very fine particle like the cigarette smoke. In addition, it can distinguish smoke from house dust by the pulse pattern of the output voltage.

The module is mainly used for dust removal equipment alarm equipment, air purification equipment, dust robots, fire alarm, etc. industry equipment can detect smoke particles, pollen spores, and other particles.

3.1.6 Raspberry Pi


The Raspberry Pi is a series of small single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and in developing countries. The original model became far more popular than anticipated, selling outside its target market for uses such as robotics. It now is widely used even in research projects, such as for weather monitoring, because of its low cost and portability. It does not include peripherals (such as keyboards and mice) or cases.

We will be using the Pi just to create a Home visualization and control system which would allow us to view our sensor data on a Dashboard.

3.2 Software Components of the Project

The following software components are used in this project:

The Things Network - To connect our gateway data to various integrations. Please note that if we use the Helium Network, we just have to substitute this with the Helium Console.

ThingspeakIoT - This is the integration we use to view our sensor data on an online dashboard and also perform analytics on this data using Matlab analytics provided by Thingspeak.

ArduinoIDE to program our LoRa Node with is made using an Arduino UNO with a LoRa Shield.

Raspbian - The OS we use on our Pi.




4. Schematic Diagram of the Gateway and Node and Working

Before diving into the implementation of the whole project, I would like to give a brief note on how will this system work and what are the main components that will be a part of this system. For that, first have a look at the Schematic Diagram of the system.


Note: When we use the Helium Network, we substitute the Arduino Node with the STM node which is the Helium Developer Kit.

From the above schematic diagrams, we can get a clear understanding of how the whole system will work. So, here is a step by step explanation of what will happen in the system:

1. Node Data Acquisition: First, each node is battery-powered. They have 3 air quality sensors attached to the Arduino I/O ports, two to digital pins and one to an analog pin. Each sensor will be sending the measured data to the Arduino every 10-20 seconds.

2. Sensor Data Transmission: Once the data has been received by the Arduino microcontroller, it is then pre-processed (converted in bytes format so it can be easily transmitted). Now, this processed data is sent via the LoRa shield at a specific frequency of 868.3MHz.

3. Data Reception: Now that the data has been transmitted, it will be received by the gateway in a specific amount of time, depending on the distance between the Node and the Gateway. This received data can be viewed on the Things Network Page for that particular node. Please note that some additional settings need to be applied to get the data in a proper format. These settings will be discussed later in this chapter.

4. Thingspeak Dashboard Update: After receiving the data, we have set up our things network such that it will funnel all its received data to the Thingspeak IoT dashboard. There we can view any of the changes in the sensor data in real-time and even create graphical user interfaces for better understanding.




5. Sensor Interfacing

we will see how to interface the 3 given sensors to an Arduino UNO or Arduino compatible board. So, let us start with the first sensor that is the CCS811 Sensor.

1.1 CCS-811 Gas Sensor Arduino Interfacing

The CCS811 is an I2C sensor hence the interfacing part will be similar to any other I2C sensor that we have.

You can easily wire this breakout to any microcontroller; we'll be using an Adafruit Metro (Arduino compatible) with the Arduino IDE. But you can use any other kind of microcontroller as well as long as it has an I2C clock and I2C data lines. Note this chip uses clock stretching so make sure your microcontroller supports that in hardware!



Now, for microcontrollers with dedicated SCL and SDA pins, please use them instead of using the A4 and A5 pins like me. Moreover, there are 2 addresses in general used for this sensor, which are:



In my case, even though the default address is 0x5A, my sensor had the address 0x5B which can be easily checked using the i2cdetect Arduino code. I have added all the codes in a later section titled “Codes” as there are many codes involved in this project. Please remember to connect the Wake pin of the sensor to ground pin of Arduino. The interfacing diagram is shown below.


Next, Download Adafruit_CCS811 library

To begin reading sensor data, you will need to download Adafruit_CCS811 from the Arduino library manager.

Open up the Arduino library manager and search for this library and download it.


Next, Open up File->Examples->Adafruit_CCS811->CCS811_test and upload to your Arduino wired up to the sensor. This example connects to the sensor and starts taking readings.

Once uploaded to your Arduino, open up the serial console at 9600 baud speed to see the readings. Your sensor will take 3 zero readings while it does some internal calibration and correction things and then start outputting real data. In clean air and a typical indoor space your serial monitor will look something like this:


5.2 Mics5524 Gas Sensor Arduino Interfacing

The MiCS-5524 is a robust MEMS sensor for indoor carbon monoxide and natural gas leakage detection; suitable also for indoor air quality monitoring; breath checker and early fire detection.

Detectable gases

• Carbon monoxide CO 1 – 1000ppm• Ethanol C2H5OH 10 – 500ppm• Hydrogen H2 1 – 1000ppm• Ammonia NH3 1 – 500ppm• Methane CH4 >1000ppm

One thing to note is that this sensor is sensitive to multiple gases, as you can see above – but does not know which gas it is.


5.3GP2Y1014AU0FInterfacing with Arduino

Below shown is the wire numbering of the sensor and its interfacing diagram with the Arduino Uno.


Please note that all the demo codes for this sensors are included in the Github repo.




6. Lora Components Setup

This chapter covers the following topics in this order:

1. Gateway Setup

2. TTN Account Setup

3. Node Setup

After this setup, you would be able to send the “Hello World!” String via Lora from your Node to your TTN Gateway and Device on an interval of 30 seconds to 1 minute.

So, let us get started:

6.1 Gateway Setup

This document has been written for the gateway version LG-01 N manufactured by Dragino. So, follow the below steps to get your gateway up and running for LoraWAN applications.

· Unbox the gateway, connect the given antenna in the ANT-1 port and power it using the given power supply in the box.

· Now, after it starts up, wait for a few seconds and then you will see that there will be 2 yellow lights glowing as shown in the figure below.


Now, there are 2 options to connect the gateway to your PC:

(Note – If you have done this process before for different gateways (with different firmware files), just do this setup in an incognito or private Window to prevent cached addresses, so you do not get the error as shown below


i) When you see the Wi-Fi symbol light blinking on the board, this means that it has set up a local Wi-Fi network. The name of the network will be ‘dragino-xxxxx’. Just connect to this network and then open ’’ on your favorite browser.

ii) (Recommended) For this method, you will need an Ethernet cable. So, first, connect the LAN port of the gateway to the LAN port of your PC. Now, follow the same procedure as above and open the default gateway IP ’’ on your favorite browser (not Internet Explorer)

After this process, you will see that your device is up and you will see it as follows:


After the 3rd step, your will see the following window on your browser:


Now, just go on and sign in with the default credentials, which are as follows:

Username: root

Password: dragino

If everything is good, you will successfully login to your gateway page, from where we can set it up to work as a number of things. For example, A MQTT Server, A Mesh Node of a bigger Lora Network, A Lora Gateway (we are interested in this), etc.

· Now, this will take you to the home screen of your gateway. Congratulations, your PC is successfully connected to your PC! The home screen will look something like this:


Please note that you will need the firmware version LG02_LG08-5.2.15xxxxxxxx for this project. If you have any other firmware, just go to System >> Backup/Flash Firmware and reflash the desired firmware. You can download the firmware from this link.

Now, the next step is to connect the gateway to Internet.

· For connecting to the internet (specifically Wi-Fi), just go to the following from the menu:

Network >> Wireless

After that, just follow the given steps:

· First, disable the block with SSID name “dragino-xxxx” so that we can use that to connect to our own Wi-Fi Network

· Now, on top you will find a block saying Generic MAC80211 802.11bgn. In that, just press the Scan button and you will be redirected to the following page:


Now, connect to your Wi-fi network and enter your Password in the field “WPA Passphrase”. After that, press the Submit button.

· Now, you will be taken to the next page wherein you have to change nothing, go to the bottom of the page and press on Save and Apply button.

· After pressing it, you will see that on the screen it will show something like “Applying Configuration, wait for xx seconds”. After some seconds, the new config will be applied.

· To confirm that you are connected to the internet, check the Wi-fi Symbol light on the gateway is blinking and just go to Network >> Diagnostics and ping any random URL. If you get a response, it means you are connected. Or else, you will see something like this:

$$URL$$ Bad Address……”

If you get this, just repeat the process again and make sure you enter the right address and all.

· Now that Wi-fi is connected, we can go on and setup the LoRaWAN Gateway part. For that, go to “Service >> LoraWAN Gateway”. You will be taken to a new page


Now, just refer to the above figure and fill in all the details as given. Just change the gateway address with the address that you have given in your TTN Gateway Page. (TTN part will be covered in the next step, so you can just enter any arbitrary value for now (TTN Part – step 7))

After everything is entered, just press Save and Apply and let the new configurations be added. After this process, your Gateway is Ready!

Now, we will move to the next step of this setup, the TTN (The Things Network) Account setup.

6.2TTN Account Setup


TTN Account Setup for Lora Air Quality Project


Creating Account in TTN


1. Signup TTN network by visiting the URL https://www.thethingsnetwork.org/


2. Give your details and create a new account.


3. Login with your credentials using the sign-in page.


4. After you have Logged in, go to console page using the menu shown in the figure below.


5. In that console page you can see Tab to create your page for Application and Gateway.


Gateway Registration


6. First, Register GATEWAY using the GATEWAY tab

Click GATEWAYS Tab a registered gateway


7. Then Give Details as follows

a. Gateway ID: <as per the format in below image — it should be unique>

b. Tick I’m using the legacy packet forwarder

c. Description: <anything for your reference>

d. Frequency Plan: <Europe 868MHz>

e. Router: <ttn-router-eu>

f. Antenna Placement: <Indoor / Outdoor>

Once you have given Gateway ID in the format given then it converts it into Gateway EUI. If it shows any warning or error click on that message then it will go. Then click Register Gateway

Here My gateway ID is 12 34 56 7A BC DE FF FF

8. Check your Gateway Registration here ensure the highlighted fields


Application Registration

9. Click Application tab and add application


10. Give Details and Add Application


Note: Application ID can only exist of lowercase alphanumeric characters, non-consecutive — and it cannot start or end with a — or a. _

11. Check the highlighted parameters


12. This step is not Mandatory <Suggested to use default EUI> To change the Application EUI go to settings tab and add EUI your new EUI and Remove the old EUI


13. After step 11, Click on 0 Registered Device


14. You will get the following screen in that click register device


15. On this Register device page, you have to give the following details and give Register

a. Device ID: <Give Unique ID for your reference.>

b. Device EUI: <Give 8 bytes Hexadecimal unique ID.>


16. On successful registration, Check the Device Overview in the following location as per the image


17. Change Activation method from OTAA to ABP

To change the modes from OTAA to ABP go to Settings and click on ABP and save the changes by keeping remaining things default.


For More details on OTAA and ABP visit the following Link https://static1.squarespace.com/static/560cc2c2e4b01e842d9fac18/t/5a938d38ec212d945 1fbecf8/1519619387035/OTAA_or_ABPv3.pdf

18. Check the Device overview in the following location as in the image


19. Click on “< > “options in Network Session key and APP Session Key to see the Hexadecimal values of key.


Also, you can copy the key by clicking option highlighted in blue color to paste it in program. Device address, Network session key and App session key all should be in the format as displayed in the image to use it in the program.

Now, the TTN account all setup. All that remains is the Node setup.

6.3 Node Setup

The only pre-setup that needs to be done is to connect the DIO and reset pins of the Dragino shield v1.4 to the specific pins of the Arduino, as given in the pin map. They are:

DIO0 >> Arduino pin 2

DIO1 >> Arduino pin 6

DIO2 >> Arduino pin 7

Reset pin >> Arduino pin 9

After this is done, just follow the same steps for both boards as given below:

· Install Arduino Software

Download the “Hello World” test Program from the given link https://github.com/dragino/Arduino-Profile-Examples/blob/master/libraries/Dragino/examples/LoRa/LoRaWAN/Arduino_LMIC/Arduino_LMIC.ino and install necessary Library Packages as per.ino file downloaded. The link to the library:

https://github.com/matthijskooijman/arduino-lmic. Add this Library to Arduino IDE.

Open the downloaded.ino file in Arduino and find the following lines


Change those NWKSKEY, APPSKEY, and DEVADDR as in step 19

Connect your Arduino with LoRa Shield to Computer through USB then Select Arduino/Genuino Uno.


And Select Tools >> Port >> COM port of Arduino.


Compile and Upload the code to Arduino Shield


Open Serial Monitor to see the process

Go to Things Network to see the uploading data in gateway


Go to traffic to see the data in gateway


Click on the field to see the physical payload in gateway


Go to your application to see the uploaded frames as in below image


Go to Data tab to see the uploaded data in End Application


Click on the field highlighted to see the Payload


This is the Hexadecimal Value of “Hello, world!” So, this concludes this chapter. All the necessary settings are done and the Lora components are set up. Now, the next chapter will deal with putting all these things together and set up the final implementation of our project.




7. Final System Implementation

We will now proceed to put everything together. That is, connecting the sensors to the nodes, setting up the LoRa Gateway, setting up the software side of the project, and then after that we will proceed to set up the Raspberry Pi Dashboard and also have a look into the implementation of Machine Learning algorithms in the next chapter.

Now, first, we will set up the nodes.

For that, we will connect all the sensors according to the schematics shown in the sensor interfacing chapter. After that, we will have to set up the node as per the instructions given in the last chapter.

So, after connecting all the sensors as shown, we will get a node something like this.


The final code is attached below.

Now that the node is set up and fully functioning, we can see the data in the Traffic section of that particular node on the things network application page something like this.


Apart from this code, we need an additional Decoder function so that we can decode the Byte data in decimal format. The decoder function for our project will be as follows:

function Decoder(bytes, port) {
if(bytes.length == 1) {
if(bytes[0] == 1) {
return {
'button': 'activated'
} else {
return {
'error': 'button action unknown'
} else if(bytes.length == 6) {
var CCS_CO2 = (bytes[0]<<8) | bytes[1];
var CCS_TVOC = (bytes[2]<<8) | bytes[3];
var MICR = (bytes[4]<<8) | bytes[5];
return {
field1 : CCS_CO2,
field2 : CCS_TVOC,
field3 : MICR
} else {
return {
'error': 'payload unknown'

Moreover, we will also need to perform some additional steps to funnel this sensor data to the Thingspeak IoT Dashboard page, which will let us perform additional analysis of the data we just got. So, to do that:

· First, go to the Applications page from the Console of the Things Network

· After that, open your application so that you can see several functions on the top right side of the page.

· Go to the Integrations tab, and click on the add integration button.

· After that, you can see a number of supported integrations on the next page. We will now select the one which we will be using, Thingspeak. You will find it at the bottom of the list and the version number is v2.7.14

· After clicking on that, you will see 3 fields that need to be filled: Process ID, Authorization and Channel ID. Just find that info from your Thingspeak channel that you will be using and then press on add integration button on the bottom of the page.

· Hence, you have successfully connected the Things Network application with your Thingspeak IoT channel.

Now, the next step in this will be the Thingspeak IoT channel part. After starting Thingspeak, just sign up and create a free account. After verifying the email that you used to create your account, you are now ready to use the Thingspeak channel.

Just create fields according to your needs and then there will be graphs automatically created on the dashboard for you. This is actually all that is initially required for Thingspeak setup. Now, we will require some information of the channel we are using:

· Thingspeak channel id

· Read API Key

· Write API Key

· Authorization (for the things network)

Now after setting up everything, we are ready to test our whole system. The dashboard of Thingspeak will look something like this.


This is all for the LoRa components setup of the project. We set up the gateway first, by loading in the appropriate firmware and then set up the software components. After that, we interfaced different sensors with our node that will help us measure the required air quality parameters. Now after this, the next chapter will discuss the following details:

· Setting up the Raspberry Pi.

· Setting it up to receive the data from Thingspeak using a simple python code.

· Creating a dashboard of the received data

· Collecting the sensor data on the device and then running this data through simple Machine Learning models which have been trained on a graphic intensive device.




8. Pi Dashboard Setup

The Raspberry Pi can be used as a server for your home which will fetch the sensor data and display it on a Dashboard which will be on a TFT or a large OLED display. Now when it comes to dashboards, there are 2 options – create your own dashboard website using a web development language like node.js or use an existing website that provides this feature. For our project, we will be using the Thingspeak dashboard as our home system. In that, we will be able to visualize graphical data, see the actual and predicted readings, etc.

Now, if we choose the second option, there is a very easy alternative for that too – Node-Red. This is a programming language that needs no code to run. We just have to use the drag and drop feature to create functions, fetch data from ThingSpeak, parse the JSON data to staring and use the node-red dashboard module to make a simple dashboard with several gauges and/or graphs or simply string data. A typical node-red dashboard will look something like this:


The flow for this dashboard is as follows:


I have added the exported node setup is linked below.

This completes our project. I would again like to apologize to Helium as I was not able to use the provided free Hardware but I wanted to present my idea anyway. I have also integrated the TTN to AWS IOT which is very similar on the Helium Console.

Please regard this as my contest entry.

Thank you Helium for this opportunity and I would like to thank Whizkey OPC for making this project possible.

All Rights