LoRa Powered Air Quality Monitoring System

by AkarshA2 in Circuits > Arduino

45 Views, 1 Favorites, 0 Comments

LoRa Powered Air Quality Monitoring System

AnyConv.com__1.png
AnyConv.com__2.png

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

AnyConv.com__3.png

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

4.png

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.

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 setup an Helium hotspot in India, but nothing I did worked. 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.

Hardware and Software Components for This Project

AnyConv.com__5.png
AnyConv.com__6.png
AnyConv.com__7.png
AnyConv.com__8.png
AnyConv.com__9.png
AnyConv.com__10.png
AnyConv.com__11.png
AnyConv.com__12.png

Hardware Components of the Project:-

  • LG01N 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.
  • Dragino Lora Shield for Arduino v1.4 (EU868): LoRa Shield is a long-range transceiver on an Arduino shield form factor and based on an 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. Features:
    • 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
  • CCS811 Ultra-Low-Power Digital Gas Sensor: 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.
  • PM2.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 particles like 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.
  • 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.

Software components 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.

Schematic Diagram of the Gateway and Node and Working

AnyConv.com__13.png
AnyConv.com__14.png

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 there are some additional settings that 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.

Sensor Interfacing

15.png
16.png
AnyConv.com__17.png
18.png
AnyConv.com__19.png
20.png
AnyConv.com__21.png

Now, 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.

  • 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:0x5A and 0x5B 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 the ground pin of Arduino. The interfacing diagram is shown below.
  • Next, Download the 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 that shown in the image above.

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

  • GP2Y1014AU0FInterfacing with Arduino: The image above shows which wire needs to be connected to which now of the Arduino UNO. Please note that all the demo codes for these sensors are included in the Github repo.

Gateway Setup

22.png
23.png
AnyConv.com__24.png
25.png
AnyConv.com__26.png
27.png
AnyConv.com__28.png

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:

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:
    • 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 ’10.130.1.1’ on your favorite browser.
    • (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 ’10.130.1.1’ on your favorite browser (not Internet Explorer)
  • 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 log in 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!
  • 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 the 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 the 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.
    • 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 that 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 set up 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.

​TTN Account Setup for Lora Air Quality Project

AnyConv.com__29.png
AnyConv.com__31.png
32.png
AnyConv.com__33.png
AnyConv.com__42.png
AnyConv.com__35.png
AnyConv.com__40.png
AnyConv.com__36.png
AnyConv.com__37 (1).png
AnyConv.com__39.png
AnyConv.com__41.png
AnyConv.com__42 (1).png
56.png
AnyConv.com__46.png
AnyConv.com__47.png
48.png

Change Activation method from OTAA to ABP

Creating Account in TTN:

  • Signup TTN network by visiting the URL https://www.thethingsnetwork.org/
  • Give your details and create a new account.
  • Log in with your credentials using the sign-in page.
  • After you have Logged in, go to the console page using the menu shown in the figure below.
  • On that console page, you can see Tab create your page for Application and Gateway.

Gateway Registration:

  • First, Register GATEWAY using the GATEWAY tab. Click GATEWAYS Tab and register gateway.
  • Then Give Details as follows:
    • Gateway ID: as per the format, it should be unique.
    • Tick I’m using the legacy packet forwarder.
    • Description: anything for your reference
    • Frequency Plan: Europe 868MHz
    • Router: ttn-router-eu
    • 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.

  • Check your Gateway Registration here to ensure the highlighted fields.

Application Registration:

  • Click the Application tab and add the application
  • 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.
  • Check the highlighted parameters.
  • This step is not Mandatory To change the Application EUI go to the settings tab and add EUI to your new EUI and Remove the old EUI.
  • After step 11, Click on 0 Registered Device.
  • You will get the following screen in that click register device
  • On this Register device page, you have to give the following details and give Register.
    • Device EUI
    • Device ID
  • On successful registration, Check the Device Overview in the following location as per the image.

  • 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 the remaining thing's 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.
  • Check the Device overview in the following location as in the image.

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

  • Also, you can copy the key by clicking the option highlighted in blue color to paste it into the program. Device address, Network session key, and App session key all should be in the format as displayed in the image to use in the program.
    Now, the TTN account is all set up. All that remains is the Node setup.

Node Setup

49.png
AnyConv.com__50.png
AnyConv.com__51.png
52.png
53.png
AnyConv.com__54.png
AnyConv.com__55.png
AnyConv.com__45.png
58.png
AnyConv.com__57.png

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 the gateway.

  • Go to traffic to see the data in the gateway.

  • Click on the field to see the physical payload in the gateway.

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

  • Go to the 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.

Final System Implementation

59.jpg
60.png
61.png

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 several 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 at 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 about 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.

Pi Dashboard Setup

AnyConv.com__62 (1).png

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.

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