Interfacing LORA SX1278 Module With Arduino

Long-distance communication (or constant transmissions of data) has become an essential part of modern industries, the medical sector, and even the residential sector. These data include the status/outputs of sensors, operation logs of machines, images or videos, scheduled events, etc. The transfer of these data between machines via wired or wireless medium without human input is called Machine-to-Machine communication (M2M). The same communication if done using a cloud platform instead of point-to-point becomes IoT. Realizing the growing demand for faster, more secure, and more efficient communication, technologies that enable long-range communication wirelessly were developed. Out of many ones namely “LoRa” stood out by satisfying the need for low power consumption, higher communication range, interference immunity, mobility, and energy efficiency. It was designed for sensor data transmission at low speeds (around 20-50 Kbps).

In this article, we will be interfacing Arduino Nano and a special transponder module called LoRa SX1278 (which utilizes the patented “LoRa” modulation technique). After interfacing the module we will also learn to transmit some data between two LoRa sensor nodes. In this article, we will be using the DHT11 sensor to transmit humidity and temperature data as an example.

After completing this article you will be able to:

  1. Interface the LoRa-02 module with Arduino Nano.
  2. Transmit sensor data between LoRa nodes.
  3. Display the readings on the LCD.

Introduction to “LoRa”:

“LoRa” meaning “Long Ranged”, is a well-known radio communication method. LoRa in itself is a physical layer protocol that is derived from Chirp Spread Spectrum (CSS). CSS is a wideband linear frequency modulation in which carrier frequency varies for the defined extent of time. Whereas a chirp is a sinusoidal signal whose frequency increases or decreases over time (often with a polynomial relationship between time and frequency). Due to this, CSS is ideal for applications requiring low power usage with lower data rates (<1 Mbit/s), longer ranges, and when devices moving at high speeds are part of your network.

The “LoRa module” supports different ISM band frequencies, namely 868MHz (Europe), 915MHz (North America), and 433 MHz (Asia), and encodes information on radio waves using chirp pulses. So we can conclude that LoRa targets key: Internet of Things (IoT) requirements such as bi-directional communication, end-to-end security, mobility, and localization services.

lora sx1278

Figure 1: LoRa SX1278 Module

For this article, we will be using a specific LoRa SX1278 module consisting of a “Ra-02” chip from AI-Thinker. This chip supports the ISM band of range: 410-525MHz, Power amplifier (PA) of +18dBm, and modulation techniques of LoRa/FSK/OOK. The features and Specification of the whole package are given as follows:

Features of SX1278 LoRa:

  • works in ISM bands (Industrial Standard Medical band)
  • Half-duplex SPI communication
  • Low powered consumption 
  • High-range coverage (~10Km)
  • Operates on low bandwidth
  • Supports Preamble detection
  • excellent blocking and interference immunity
  • Built-in temperature sensor and battery indicator.
  • Built-in bit synchronizer for clock recovery

Specification:

  • Module Model: Ra-02
  • Package: SMD-16
  • Size/Dim: 17*16*(3.2 ± 0.1) mm 
  • Programmable bit rate up to 300 kbps
  • Frequency Range: 410 MHz – 525 MHz
  • Operating temperature: -30℃ to 85℃
  • Power Supply: 2.5 ~ 3.7V (Typically : 3.3V)
  • industry-leading 168dB max Link budget
  • High sensitivity: down to -148 dBm
  • +20 dBm (i.e ~ 100 mW) RF transmit power
  • can use FSK, GFSK, MSK, GMSK, OOK, and LoRa (default) modulation
  • Low RX current of 9.9 mA, 200 nA register retention
  • Bullet-proof front end: IIP3 = -11 dBm
  • 127dB RSSI Dynamic Range

Components Required

Arduino Nano x 2

LoRa-2 SX1278 x 2

DHT11 (Hum & Temp) x 1

16X2 – I2C LCD display x 2

Interfacing Sx1278 with Nano:

The table given below describes the wiring between I2C_LCD, LoRa, and Nano for both the transmitter and receiver nodes.

As the figures below demonstrate, the I2C_LCD has its VCC & GND pin connected to 5V & ground, whereas its SDA & SCL pin to analog pins A4 & A5 of Nano.

For LoRa and Nano interfacing below table is given:

LoRa-02 SX1278 NANO pins
VCC (3.6V max) 3.3V
GND GND
SCK (SPI clock) D13
DIO0 (Digital I/O) D2
RST (Reset) D9
NSS (Chip select) D10
MOSI (SPI data input) D11
MISO (SPI data output) D12

Transmitter circuit of lora sx1278

Use 3.3V of Arduino Nano to connect it to the VCC pin of the LoRa module. Connect all the GND pins to GND. Connect the RST pin to D9 and DIO0 to D2 of Arduino. Connect the SPI Pins NSS, MOSI, MISO, and SCK to Arduino D10, D11, D12, and D13 Arduino respectively as shown in the circuit diagram above. Then connect the VCC, DATA & GND pins of the DHT11 (humidity & temperature) sensor to the 5V, D3, and GND pins of Nano, respectively as shown above.

receiver circuit of lora sx1278

Use 3.3V of Arduino Nano to connect it to the VCC pin of the LoRa module. Connect all the GND pins to GND. Connect the RST pin to D9 and DIO0 to D2 of Arduino. Connect the SPI Pins NSS, MOSI, MISO, and SCK to Arduino D10, D11, D12, and D13 Arduino respectively as shown in the circuit diagram above. Then connect the D3 pin of nano to the cathode of LED and then to gnd via a 470Ω resistor as shown.

How to transmit Sensor Data:

Firstly we require two libraries for the operation of the LoRa-02 SX1278 module via the Nano, namely <SPI.h> and <LoRa.h>. The “SPI.h” library is responsible for serial communication between module and nano whereas “LoRa.h” is responsible for transmitting/Receiving operations.[Note: This “LoRa.h” library allows you to send data to any radios in range with the same radio parameters. All data are broadcasted without any addressing.]. For the sensor, we are using DHT11(temperature & humidity sensor). So the <DHT.h> library is required for extracting the temperature and humidity data captured by the DHT11 sensor.

After successfully interfacing all the hardware as instructed, the step-by-step explanation of the code for sensor data reading and transmission process is given below:

Software Code

Transmitter Side Code

Including necessary libraries:

Three libraries:  DHT.h, SPI.h, and LoRa.h are included for sensor data generation/reading, Serially transferring that data from Nano to the LoRa module and then transmitting it.

Defining important parameters:

Here the incoming data from DHT11 is assigned to digital pin D3 of nano. We also have to specify the sensor model type while initializing the sensor. Then two variables to hold the humidity and temperature data are required.

Initialize Setup Function:

Here we initialize the LoRa library with 433MHz frequency using LoRa.begin(). This function also scans if a message has been sent or not. If not It displays” Starting LoRa failed!”

Read and transmit sensor Data: 

Read the temperature and humidity data using “dht” objects and store them into respective variables. Then transmit the using LoRa.print() function. When the transmitted message ends with a “*” character which is then used by the receiver to break the combined serial characters into a meaningful message.

After the transmission is done, now for step by step explanation of the code performing the data reception process is given below:

Receiver Side Code

Initialize the necessary libraries and parameters:

We include the SPI.h and LoRa.h libraries for serial communication and LoRa module operations. Then a String type variable (inString) captures the incoming character and merges them into one string. The counter is the count no of captured characters.

Initialize the Setup function:

Here we initialize the LoRa library with 433MHz frequency using LoRa.begin(). This function scan if a message has been sent or not. If not It displays “Starting LoRa failed!”.

Void loop:

Here we will check if a packet has been received using “LoRa.parsePacket()”. This function returns the packet size in bytes or 0 if no packet was received. Then read the character and append them to a string variable (inString). Then display the message/combined data in the serial monitor. If the “*” character is received, then it indicates the end of the message.

Complete Code:

Displaying the Sensor Data in LCD

The transfer of sensor data has been modified and displayed in LCD. The code is as follows:

Transmitter Code:

Receiver Code:

author prototype of lora interfacing

Figure 4: Author Prototype of LoRa Interfacing Transmitter Circuit

Figure 5: Author Prototype of LoRa Interfacing Receiver Circuit

Leave a Comment