IoT LoRa Sensor Module and Gateway

by Draggfive in Circuits > Wireless

5056 Views, 40 Favorites, 0 Comments

IoT LoRa Sensor Module and Gateway

PXL_20210328_211555246.jpg
Interface.PNG

Ever wanted to know the temperature of your house everywhere in the world ? Want to add a feature to your weather station, or monitor the air of your workshop ? Let's have a look to this instructable !

This project is initially designed for internet of things (IoT) purposes. There is a Sensor Module measuring different ambient variables, this module sends its measurements through LoRa to a Gateway Module, which itself sends its data to the internet.

The modules are based on Arduino. the Sensor Module uses an Arduino UNO, and the gateway a NodeMCU, which embed an ESP8266 WiFi microcontroller. The WiFi is here used to connect the Gateway to the Internet, thanks to your home Router or a hotspot sharing !

Thanks to standardised protocols such as I2C or SPI, Arduino UNO, like other microcontroller is able to interact with several sensors and modules. It also has an analog to digital converter (ADC) which will be interesting to use in this project. Let's use an air quality sensor, a thermometer, and a hygrometer.

The air quality sensor used here is a MQ-135 module. This nice thing is able to measure the density of different gaz in the air, such as alcohol, benzene, CO2, ammonia, azote oxyde or smoke. Beside this module, the DHT11 sensor will be used. It is able to measure temperature and humidity.

Finally, you will be able to create a Sensor Module, which read ambiant values, and make it available on an interface which can be accessed from your web browser.

All of the ressources used are available on my Git Repository. The code work was not entirely made by me, and the credits are given accordig to. I also worked in collaboration with Thodor, who helped me to make this instructable.

Disclaimer: This project was made for educational purposes. Even if the MQ-135 is able to measure the air quality, it is not as efficient as professional devices and cannot be used for security purposes.

Supplies

Here is what you will need to perform this project.

Components :

  • An Arduino Uno. It will be needed for the Sensor Module
  • A NodeMCU Microcontroller board. It is based on an ESP8266 module, and can be programmed with Arduino
  • Two Ai-Thinker Ra-02 Lora Modules mounted with their sockets. One for the Sensor Module, and one for the Gateway. You can chose to take the "raw" module, but you then will need some skills in PCB making. The module used in this instructable can be found here
  • Two Antennas, one for the Sensor Module and one for the Gateway. It is needed for the Ra-02 to work, but BE CAREFUL to chose antennas adapted to the authorized frequency in your country ! The band allowed in Europe is in 433MHz. Such antennas can be found here
  • A MQ-135 based air quality sensor, used on the Sensor Module
  • A DHT11 temperature and humidity sensor, also used in the Sensor Module
  • A DC Jack connector, needed for the Gateway if you do not want to power it through USB
  • Two 5mm leds and their 1/4W resistances. If you're not sure about the values to take for the resistances, just take 1kOhm.

If you want to realize the "long lasting" modules, with their casing:

  • 8 M3, 5mm screws. 4 for the Sensor Module, 4 for the Gateway
  • 8 M3, 10mm screws. Newly, 4 for the Sensor Module, 4 for the Gateway
  • Single layered FR4 for the Gateway. The dimensions must be at minimum 70x80mm
  • Two layered FR4 for the Sensor Module. The dimensions must be at minimum 60x70mm


Note:

If you want to make more than one Sensor Module (to measure the air quality at different places), you will need to buy as much components needed for Sensor Modules than modules you plan to make.


Tools:

  • A 3D printer, for the casing. The one used here is the Original Prusa MK3S, but any other 3D printer is suitable for this project. The material used is not really critical in this project, the one used here is white PLA
  • A CNC 3018 engraving machine, needed if you want to make the PCB. You may also need an engraving mill, as well as a 0.8mm, 1.0mm, 1.2mm and 3.0mm drills, and a diamond cut mill
  • A Laser cuter. It is optional, but gives nice results for casing ! We had the chance to use the Trotec Speedy 100


Note:

You do not have a 3D printer, a CNC or a laser cutter at hand ? That's not a problem ! this project is mainly feasible with just the basic modules, some breadboards and jumpwires ! Just be careful when installing your prototype somewhere, as breadboarded project is not really suitable for long lasting operations...

Prepare Your Online Workspace

MQTT explorer.PNG
IoTHub.png
IotDevice.png

Because the transmission protocol is based on MQTT, the first thing needed is to choose a Cloud Provider with MQTT managed message broker. In this project we chose Scaleway, which offers an easy management of devices and of cloud data. Moreover, using Scaleway with Node-RED allow to create an IoT Hub to display all the data on a customizable interface, usable on any web search engine.

First thing is to create an account on Scaleway and make an IoT Hub : https://www.scaleway.com/

Several offers exists for MQTT brokers. Here an IoT Hub is used

Then add a device on the IoT Hub and look for the Device ID attached to it. It will be necessary next and later in to provide a MQTT connection between the cloud and the hardware.

Meanwhile, it is also needed to have a comprehensive MQTT client that provides a structured overview of the MQTT topics and makes sure devices and services are working.

A lightweight MQTT client, "MQTT Explorer" can be found here.

Now the MQTT connection can be configured with the Host ("iot.fr-par.scw.cloud" or other, depending on the region chosen on Scaleway) and the Username ("YourDeviceID").

From here we will be able to check our topics and see if our data was correctly published to the client.

Wiring Up

Gateway Schematic.PNG
Sensor Schematic.PNG

All the modules used can be implemented using breadboards and jump wires. The Sensor Module uses the Arduino UNO, and the Gateway the NodeMCU. Both modules can be powered through USB, or using a 7V to 12V supply to the DC Jack.

Prepare Your Arduino Environment

Lora Arduino.PNG
PubSubClient Arduino.PNG
ESP Arduino.PNG

To work with LoRa, sensors and NodeMCU, the Arduino Environment needs some additional libraries and devices support.

First, be sure to have the IDE and drivers installed.

Then, the NodeMCU support has to be added. It can be done by going to File > Preferences... > Additional Boards Manager URLs, and to add http: //arduino.esp8266.com/stable/package_esp8266com_index.json to the field. After that, going to Tools > Board > Board Manager... will allow to add esp8266 support.

Finally, the LoRa and PubSubClient libraries can be added with Sketch > Library > Manage Libraries... PubSubCLient is used to perform MQTT requests.

The sensors functions are provided with the Git repository, and based on the work of Mark Ruys for the DHT11 and Georg Krocker for the MQ-135.

Time to Code !

Code Sensors.PNG
Code Gateway.PNG

Two programs are needed. One for the gateway, and one for the Sensor Module.

The principle is simple. The sensor module sends the values measured by the sensors through LoRa, the Gateway receives the data and transmit it to the cloud under a MQTT request. Dead Simple !

The code is provided by the Git repository. Just be sure to:

  • Change the LoRa frequency to an allowed one in your country. Available bands are between 410MHz and 525MHz for the Ra-02 module. the Frequency allowed in Europe is 433MHz
  • Change ssid and password in order to be connected to your router. hname is the name used by the gateway, and displayed by the router in the connected devices list
  • Check the variables for the MQTT broker, in order to successfully connect to the server.

The MQ-135 also need to be calibrated. The procedure is well explained by the creator of the library himself here.

Display Your Data

NodeRed.png
Dashboard.png

To display our data we need to use the Development Instances application of Scaleway : Node RED.

On your IoT Hub click on the KickStart menu and create a new Kickstart. According to our interface specifications we select the use-case « Flow Programming ». Now wait a few seconds until your application is getting ready and click on Dashboard.

Click on « Manage palette » and install the following nodes to get more tools and functional boxes :

  • node-red
  • node-red-contrib-ui-media
  • node-red-dashboard

With the Dashboard Icon we can organize and manage the parameters of our different functionalities, to add one just drag and drop the functional boxes you need on the left. To display a specific data, choose a « MQTT in » box and link it to a visualizer of your choice (chart, gauge, …). Change the parameters for each one according to your data and don’t forget to precise the Topic in the MQTT input.

For other uses you can also plan to use a MQTT output and interact with your system thanks to numeric entries, switches and more.

To access your interface, put on the browser the following link : http://:1880/ui

Make It Last

Sensor PCB.PNG
Gateway PCB.PNG
IMG_20200217_191232.jpg
Sensor Case.PNG
Gateway Case.PNG
IMG_20200630_181420.jpg
PXL_20210328_121041614.jpg

If you have the necessary material, you can use the files provided in the Git repository to create some PCB and casing. If you have SOLIDWORKS, you can even modify the files to make custom casing. The PCBs were on their sides created with Autodesk Eagle.

Just uses the Gerber files to make the PCBs and the 3MF files to print the casing, and you will have some robust modules !

Go Further...

Beacon Sch 1.PNG
Beacon Sch 2.PNG
Beacon.PNG
Beacon Board.PNG

Now you have a working IoT system, you can imagine more complex probe to measure weather or ambient air.

Lets quickly present this work in progress, making a full standalone beacon, able to communicate its pose, geoposition, the ambient light, temperature, humidity and pressure.

Respecting the IoT principle, the module would consume few power. As Arduino and all made module are not really suitable for that, a microship PIC32 is used here. It has, among others, the ability to enter in deep sleep mode, and to manage a date to wake up.

The sensors used are the following:

All of these sensor's power sources are managed from the PIC in order to disable them during sleep.

The power source used for this module is a 3.7V Lithium Polymer battery, charged thanks to a solar panel module. The beacon is then fully autonomous, and can last forever when it is well configured.

As it uses the same LoRa module than before, the beacon can communicate with our Gateway !

This module embed very little parts. It then cannot be made with amateur tools. What is planned here is to manufacture the board, giving it to a company like PCBWay. If a "raw" PCB is quite easy to order provided you know how to generate Gerber Files, ordering an assembly requires to provide a Bill of Material (BOM), listing all the components references. A Pick and Place (PnP) file is also needed, which tells where the components are placed on the board. PCBWay then allows you to decide who provides the parts. it is important to notice that assembly service is more expensive than PCB manufacturing. Here, for example, 5 PCBs can be ordered for 5$. One Board to assemble costs 174$ (86$ for components, 88$ for assembly). But the result is much more professionnal !

As shown there, the possibilities are endless for IoT. Now have fun !