Sending data from Arduino nano to Raspberry Pi using lora communication

Sending data from Arduino nano to Raspberry Pi using lora communication


Discover the seamless world of wireless data transfer with LoRa communication as we delve into a captivating journey in this blog. Starting with an introduction to the concept, we explore the power of Arduino Nano as the data sender. Unravel the magic of LoRa-enabled devices with our detailed sender program guide. Uniting the Arduino Nano and Raspberry Pi, we unleash the full potential of data transmission. Join us in exploring the wonders of LoRa communication and how it bridges the gap between these two powerful devices. Get ready to embark on a thrilling tech adventure!


In this tutorial, we will learn how to connect the LORA Module to the Arduino Nano and Raspberry Pi. We will use the Raspberry Pi, Arduino Nano, and Lora to create a transmitter and receiver for data transmission and reception respectively. The tutorial will provide step-by-step instructions on how to connect the LORA Module to the Arduino Nano and Raspberry Pi. It will explain how to use these components to create a transmitter and receiver for data transmission and reception.

Arduino nano:

STEP 1(Hardware connection):

Let us first setup the transmitter part first. The transmitter part contains Arduino Nano Board, DHT11 Humidity & Temperature Sensor and LoRa Module. Assemble the connection between Arduino nano and DHT sensor as shown in the table below:

Arduino nano 

DHT11 Sensor 

5 v 




Digital Pin 7 



And the connection between Lora and Arduino nano: 

Lora module 

Arduino nano 

2,3,4,5,6,7,8,9 (8 Pin connector) 

Keypad connector (2,3,4,5,6,7,8,9) 

4 Pin connector (G, 5V, 10, 11) 

4 Pin connector (G, 5V, 10, 11) 

4 Pin connector (G, 5V, 12, 13) 

4 Pin connector (G, 5V, 12, 13) 


STEP 2(downloading the libraries):

Connect your Arduino nano with DHT11 Sensor. For DHT11 sensor, install the dht library and for send the sensor readings to Raspberry Pi, install the lora library using the Library Manager in the Arduino IDE. Go to Sketch > Include Library > Manage Libraries and search for library name in the library manager.

STEP 3 (Explanation of the program):


Including the necessary libraries: We include the required libraries, such as LoRa, SPI, and DHT (for the DHT11 sensor).

Defining the constant: The code defines the type and digital pin of DHT sensor and define the required frequency for the Lora module. The ss, rst, and dio0 are the pin numbers used by the LoRa transceiver module that is connected to Arduino nano pin 10, 9, 2.

Create necessary objects: It defines the DHT sensor object called dht.

Setup Function: The setup function initializes the serial communication, the DHT sensor and the Lora module. It set the pin for lora transceiver using setPins() function. The code waits until LoRa initialization is successful before printing a confirmation message.

Loop Function: The loop function reads the temperature and humidity values from the DHT sensor. Then it prints these values to the serial monitor. After that, it starts a LoRa packet, writes the temperature and humidity values to the packet, and ends the packet transmission.

Sender program:





#define LORA_FREQUENCY 868E6 

#define DHTPIN 7 // Digital pin connected to the DHT sensor  

#define DHTTYPE DHT11 //DHT sensor type 



//define the pins used by the transceiver module 

#define ss 10 

#define rst 9 

#define dio0 2 


void setup() { 



  while (!Serial); 

  Serial.println("LoRa Sender"); 


  //setup LoRa transceiver module 

  LoRa.setPins(ss, rst, dio0); 

  while (!LoRa.begin(LORA_FREQUENCY)) { 




  Serial.println("LoRa Initializing OK!"); 



void loop() { 

  float temperature = dht.readTemperature(); 

  float humidity = dht.readHumidity(); 


  Serial.print("Temperature: "); 

  Serial.print(temperature, 2); 

  Serial.print("\t Humidity: "); 

  Serial.println(humidity, 2); 



  LoRa.print("Temperature: "); 


  LoRa.print("\t Humidity: "); 





Raspberry Pi:

STEP 1(Hardware connection):

Let us setup the Receiver part. Assemble the connection between Raspberry Pi and Lora as shown in the table below:

Lora module 

Raspberry Pi 

2,3,4,5,6,7,8,9 (8 Pin connector) 

Keypad connector (2,3,4,5,6,7,8,9) 

4 Pin connector (G, 5V, 10, 11) 

4 Pin connector (G, 5V, 10, 11) 


STEP 2(Install the library):

For lora communication we need to Install wiringPi library: 

You'll need git. If git is not installed, enter the following into the command line. 

sudo apt-get install git-core 

We highly recommend using Git to download the latest version. To check the version of wiringPi, enter the following command. 

gpio -v 

If you receive an output similar to the following with the Unknown17, you'll want to update WiringPi on a Raspberry Pi 4 or above. 

gpio version: 2.50 

Copyright (c) 2012-2018 Gordon Henderson 

This is free software with ABSOLUTELY NO WARRANTY. 

For details type: gpio -warranty 

Raspberry Pi Details: 

  Type: Unknown17, Revision: 02, Memory: 0MB, Maker: Sony 

    * Device tree is enabled. 

    * --> Raspberry Pi 4 Model B Rev 1.2 

    * This Raspberry Pi supports user-level GPIO access. 

Enter the following to remove the wiringPi and configuration files. 

sudo apt-get purge wiringpi 

Then type the following for the Pi to remove all locations that remember wiringPi. 

hash -r 

As long as you have Git installed, these commands should be all you need to download and install Wiring Pi. 

git clone  

This will make a folder in your current directory called WiringPi. Head to the Wiring Pi directory. 

cd WiringPi 

Then pull the latest changes from the origin. 

git pull origin 

Then enter the following command. The ./build is a script to build Wiring Pi from the source files. This builds the helper files, modifies some paths in Linux and gets WiringPi ready to rock.  


At this point, the library should work. Run the gpio command shown below to view some information about the wiringPi version and the Pi that it is running on. 

gpio -v  

Entering the following command will draw a table illustrating the configuration for the pins in the 40-pin connector. 

gpio readall 

STEP 3 Download the Lora-transceiver code

In the terminal, run 


Unzip the library 

unzip master 

STEP 4(Pin numbers and frequency update):

Update the pin numbers and frequency by opening the main.c file. Change directory to go inside the folder with the main.c file using the command given below: 

cd rpi-lora-transceiver-master/ dragino_lora_app 

Then, using the nano editor, open the main.c file using the command below: 

Nano main.c 

Scroll down in the main.c file the line shows frequency and raspberry connection according to the below image: 


Change the pin numbers and frequency in the nano editor. Press Ctrl+X to exit nano. Upon exiting, the save prompt will be displayed. Press Y and then press the Enter key. 

STEP 5(Rebuild the main.c file):

Every time the code is edited, it needs to be rebuilt in order for the changes to take effect. Use the commands below to clean any previous build files present and to rebuild the source 

make clean  


STEP 6(Explanation of the code):

Lora initialization: The SetupLoRa function prepares the LoRa module for operation by setting the necessary parameters and configurations specific to the chosen chip version (SX1272 or SX1276). 

Receiver part: In the receiver part, the receivepacket function is called repeatedly in the receiver part of the code to check for incoming packets and print their details. It provides insights into the received signal's strength, quality, and payload content. In the main function, the receiver part initializes the LoRa module for reception and continuously listens for incoming packets, printing information about each received packet.

else { 


        // radio init 




        printf("Listening at SF%i on %.6lf Mhz.\n", sf,(double)freq/1000000); 


        while(1) { 






STEP 7(Running the receiver):

Run the receiver code using the command below 

./dragino_lora_app rec 


The integration of Arduino Nano and Raspberry Pi through LoRa communication presents a revolutionary approach to data transmission. The seamless connection between these two powerful devices offers a myriad of possibilities in the realm of IoT and remote sensing applications. By harnessing the Arduino's versatility and the Pi's processing capabilities, this setup enables efficient and reliable data exchange over long distances, even in challenging environments. So, whether you're a tech enthusiast, a hobbyist, or an aspiring engineer, dive into this fascinating world of LoRa communication to unlock endless potential for innovation and exploration. Experience the thrill of connecting devices like never before - embark on your own journey of discovery today!


If you appreciate our work don't forget to share this post and leave your opinion in the comment box.


Please do check out other blog posts about Popular Electronics 


Make sure you check out our wide range of products and collections (we offer some exciting deals!)

You may also like to read

Frequently Asked Questions

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.

You may also like to read