Interfacing SX1278 LoRa Module with ESP32
In this tutorial we will learn how we can use the LoRa module SX1278 with ESP32. Here we will use two LoRa modules- one with ESP32 and another with Arduino Board
- Suitable forB.Tech IoT students
- Build time3-4 weeks
- LevelIntermediate
- Available atAjvika Labs, Kakinada
About this project
LoRa is a wireless Radio frequency technology introduced by a company called Semtech intended to be used to transmit bi-directional information to a long-distance without consuming much power. If you are new to LoRa, then learn about LoRa and LoRaWAN Technology and check LoRa interfacing with Arduino and Raspberry pi.
In this tutorial, we will learn how we can use the LoRa module SX1278 with ESP32. Here we will use two LoRa modules- one with ESP32 and another with Arduino Board. ESP32 LoRa setup will request the weather data from an API for any given city and send it to the Arduino LoRa setup. Then Arduino LoRa will receive the data and display it on 16x2 LCD. So ESP32 LoRa will act as a transmitter and Arduino LoRa as a receiver. An OLED is also connected at ESP32 to display the temperature and humidity on the sender's side.
LoRa -02 SX1278 Module (2)
Arduino LoRa shield can be built by following the link, where you can find Gerber files for PCB and all the required steps to build it.
Circuit diagram for the LoRa transmitter/Server and Receiver/Client section is given below. In this project, we are going to send weather data from the ESP32 module to Arduino Uno using the LoRa SX1278 module. The temperature and humidity data will be read from the internet using an API with the ESP32 module and then sent to Arduino using the LoRa module.
Transmitting Side- Interfacing LoRa with ESP32
On the transmitting side, we are using ESP32 with the LoRa module and OLED Display. Circuit diagram for the same is shown below.
Complete connections are given in the below table.
We previously used OLED in many applications ; follow the link to learn more.
Receiver Side- Interfacing LoRa with Arduino UNO
On the Receiver side, we are using the Arduino Lora Shield that we earlier designed for Lora Based GPS Tracker project. You can follow this article for the Gerber file and other information on the LoRa shield.
This shield consists of the SX1278 433MHz module with a 3.3V regulator designed using LM317 Variable regulator. The Shield will directly sit on top of Arduino providing it LoRa capabilities. The complete circuit diagram for the LoRa Arduino Shield is given below:
API Link for Getting the Weather Data
Now go back and click on “ API Explorer”
Now on API explorer page, enter the API and the City name.
Then scroll down and click on the ‘ Show Response’ button to make a request. It will give you the API key.
Now paste your API URL into a new browser tab and the output of that query will look like this (JSON data):
After getting the JSON data, generate the code by which we can read the JSON data and phrase it according to our needs. For that, go to the ArduinoJson Assistant and paste the JSON data in the Input section.
Now scroll down to the parsing program and copy the code section that is useful for you.
ESP32 LoRa Transmitter Code
Complete code for the LoRa transmitter and receiver side is given at the end of the document. Here we are explaining some important snippets of code.
First, include all the required libraries. SPI.h is used for SPI communication between ESP32 and LoRa, Wire.h Library is used for communication between I2C devices. You can download the required libraries from here:
LoRa library by Sandeep Mistry.
Then create an instance for the OLED display that includes the Address and pins where the display is connected.
After that, enter the Wi-Fi name and password. ESP32 needs the internet connection as it is getting the weather data from a website.
In the next lines, define the pins where the LoRa Module is connected.
Now enter the API link that is generated earlier. Using this link, we will get the temperature and humidity data for Jaipur City.
Inside the setup function, initialize the Serial Monitor at a baud rate of 115200 for debugging purposes, and also initialize the OLED display and LoRa communication with the begin() function.
Now inside the void loop() function, we will check if the JSON file is received by ESP32 and printing JSON data on the serial monitor using the following lines.
After that, use the phrasing program that is generated using the ArduinoJson Assistant. This phrasing program will give us temperature and humidity data for Jaipur.
Now in the last step, send the temperature and humidity values to LoRa receiver.
Arduino LoRa Receiver Code
Similarly, add the library for the LoRa module and LCD and define which pins the LCD is connected to.
Inside the void loop function, we receive the data packets from the transmitter module. After receiving the packets, Arduino starts reading them as characters and print them on the LCD. When it receives the keyword “c,” it prints the remaining information on the second line.
Working of ESP32 LoRa Setup
Once the hardware and program are ready, upload the below given codes in ESP32 and Arduino modules. Transmitter module will send the temperature and humidity values to Receiver Module. And receiver LoRa module will display them on LCD connected to Arduino as shown below.
Complete code along with the video for this ESP32 LoRa project is given below.
Complete Project Code
In this tutorial, we will learn how we can use the LoRa module SX1278 with ESP32. Here we will use two LoRa modules- one with ESP32 and another with Arduino Board. ESP32 LoRa setup will request the weather data from an API for any given city and send it to the Arduino LoRa setup. Then Arduino LoRa will receive the data and display it on 16x2 LCD. So ESP32 LoRa will act as a transmitter and Arduino LoRa as a receiver. An OLED is also connected at ESP32 to display the temperature and humidity on the sender's side.
LoRa -02 SX1278 Module (2)
Arduino LoRa shield can be built by following the link, where you can find Gerber files for PCB and all the required steps to build it.
Circuit diagram for the LoRa transmitter/Server and Receiver/Client section is given below. In this project, we are going to send weather data from the ESP32 module to Arduino Uno using the LoRa SX1278 module. The temperature and humidity data will be read from the internet using an API with the ESP32 module and then sent to Arduino using the LoRa module.
Transmitting Side- Interfacing LoRa with ESP32
On the transmitting side, we are using ESP32 with the LoRa module and OLED Display. Circuit diagram for the same is shown below.
Complete connections are given in the below table.
We previously used OLED in many applications ; follow the link to learn more.
Receiver Side- Interfacing LoRa with Arduino UNO
On the Receiver side, we are using the Arduino Lora Shield that we earlier designed for Lora Based GPS Tracker project. You can follow this article for the Gerber file and other information on the LoRa shield.
This shield consists of the SX1278 433MHz module with a 3.3V regulator designed using LM317 Variable regulator. The Shield will directly sit on top of Arduino providing it LoRa capabilities. The complete circuit diagram for the LoRa Arduino Shield is given below:
API Link for Getting the Weather Data
Now go back and click on “ API Explorer”
Now on API explorer page, enter the API and the City name.
Then scroll down and click on the ‘ Show Response’ button to make a request. It will give you the API key.
Now paste your API URL into a new browser tab and the output of that query will look like this (JSON data):
After getting the JSON data, generate the code by which we can read the JSON data and phrase it according to our needs. For that, go to the ArduinoJson Assistant and paste the JSON data in the Input section.
Now scroll down to the parsing program and copy the code section that is useful for you.
ESP32 LoRa Transmitter Code
Complete code for the LoRa transmitter and receiver side is given at the end of the document. Here we are explaining some important snippets of code.
First, include all the required libraries. SPI.h is used for SPI communication between ESP32 and LoRa, Wire.h Library is used for communication between I2C devices. You can download the required libraries from here:
LoRa library by Sandeep Mistry.
Then create an instance for the OLED display that includes the Address and pins where the display is connected.
After that, enter the Wi-Fi name and password. ESP32 needs the internet connection as it is getting the weather data from a website.
In the next lines, define the pins where the LoRa Module is connected.
Now enter the API link that is generated earlier. Using this link, we will get the temperature and humidity data for Jaipur City.
Inside the setup function, initialize the Serial Monitor at a baud rate of 115200 for debugging purposes, and also initialize the OLED display and LoRa communication with the begin() function.
Now inside the void loop() function, we will check if the JSON file is received by ESP32 and printing JSON data on the serial monitor using the following lines.
After that, use the phrasing program that is generated using the ArduinoJson Assistant. This phrasing program will give us temperature and humidity data for Jaipur.
Now in the last step, send the temperature and humidity values to LoRa receiver.
Arduino LoRa Receiver Code
Similarly, add the library for the LoRa module and LCD and define which pins the LCD is connected to.
Inside the void loop function, we receive the data packets from the transmitter module. After receiving the packets, Arduino starts reading them as characters and print them on the LCD. When it receives the keyword “c,” it prints the remaining information on the second line.
Working of ESP32 LoRa Setup
Once the hardware and program are ready, upload the below given codes in ESP32 and Arduino modules. Transmitter module will send the temperature and humidity values to Receiver Module. And receiver LoRa module will display them on LCD connected to Arduino as shown below.
Complete code along with the video for this ESP32 LoRa project is given below.
Complete Project Code
Technologies used
Hardware components
- ESP32
- ESP8266
- Arduino
- DHT22
- Relay
- OLED
- NodeMCU
Software & tools
- Arduino IDE
- Blynk
- Firebase Console
- Node-RED
- MQTT Broker
Project demo video
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.