Building a LoRa®-based Device End-to-End with Arduino
In this guide we will walk you through building your own LoRa®-based node from end-to-end using an Arduino board and Dragino shield. We are using a moisture sensor in this tutorial, but there are many potential uses for LoRa devices; alternative sensors for your node could include temperature, humidity, motion, air quality, light, accelerometers, and more.
What are LoRa and LoRaWAN®?
LoRa, is an RF modulation technique which allows for extremely low powered wireless communication systems. Since the frequencies used are orders of magnitude smaller than other common wireless communication methods, such as Wi-Fi, the range of transmission is much larger; up to 10 miles or more in rural areas with a clear line of sight. Coupling this long-range transmission with ultra-low power requirements makes LoRa an ideal choice for battery-powered Internet of Things (IoT) devices with applications that necessitate communication with widely-distributed systems.
LoRaWAN® is a protocol based on an open-source specification. In short, LoRaWAN is an example of a low power wide area network that is based on LoRa radio modulation. This standard allows the wireless connection of LoRa-based devices (nodes) to the internet and helps ensure compatibility of devices among manufacturers around the world. It is even possible, as we will outline in this guide, to build your own custom LoRa end node which can transmit information to other LoRa devices and the internet via a LoRaWAN network server (LNS).
Figure 1: LoRaWAN network high level architecture.
The architecture of a LoRaWAN network is shown in Figure 1. The end devices – or nodes – transmit their payloads in what is known as an uplink message, to be picked up by a LoRaWAN gateway. A key aspect of LoRaWAN is that a device is not associated with a single gateway and its payloads may be picked up by any number of LoRaWAN gateways within the device’s range. In theory an entire city could be covered by a just a handful of gateways and messages from devices belonging to any user could be detected anywhere in the city.
The gateway then passes messages to its associated network server, usually carried out over Wi-Fi or Ethernet. However, cellular and satellite gateways are available to enable very remote solutions without relying on an internet connection. There are various options for network servers, for example third-party public network servers are provided by The Things Network (TTN) and Helium, among others. For more information about choosing your network server refer to this guide.
The LNS receives the messages from the gateway and checks whether the device is registered on its network; the LNS also carries out deduping, since the message may be received and uploaded by multiple gateways. The message is then forwarded to the application server on which the device is registered.
Communication is also possible in the other direction, where a message is sent as a downlink to the node. The downlink message is sent from the application server to the network server. The network server then queues the downlink, and when the device next sends an uplink message, the network server will pass the downlink message to the nearest gateway which received the uplink. The gateway then broadcasts the downlink message for the device to receive.
Common uses for a downlink message are to update a device’s broadcast settings, for example, to trigger updates more or less frequently or trigger some other action, such as causing a device to open, closing a water valve or turning an A/C unit on or off.
For a detailed look at LoRa and LoRaWAN including RF modulation, more information on architecture including the technical detail on how devices join the network using a Join Server, and different classes of devices, refer to our technical paper on 'What are LoRa and LoRaWAN?'
What Will We Build?
This guide is split into three stages:
- We will build a LoRa-based end node to measure and communicate the moisture level in soil. This is a great example of the power of LoRa-based communication, since detecting soil moisture levels is key to many agricultural processes and is often challenging given the wide geographical areas where wireless monitoring is needed. We will set up a detector node which will connect to a moisture sensor and then send a LoRa payload containing the moisture level in the soil at regular intervals.
- We will build a LoRa receiver node which will receive the payload and log the moisture level to the console.
Figure 2: Schematic of the system for Stages 1 and 2.
The moisture level is read by the LoRa-based broadcast node which broadcasts a message. The receiver node receives the message, logging it to the Serial Monitor in the Arduino IDE
- We will then use the LoRaWAN specification and connect our moisture detection node to The Things Network, where we will be able to see the moisture level of the soil.
Figure 3: Schematic of the system for stage 3.
The moisture level is read by the LoRa broadcast node which broadcasts a LoRa uplink. The uplink is received by the LoRaWAN gateway. The gateway sends the message over Wi-Fi to the TTN network server. The node uplink is then visible in the TTN Console.
If you are limited by time, budget or hardware availability, it is possible to complete Stage 1 and then either: