ESP32 LoRa Sensor Monitoring with Web Server (Long Range Communication)
Build a sensor monitoring system with ESP32 TTGO LoRa32 SX1276 board that sends temperature, humidity and pressure readings via LoRa to a LoRa receiver web server.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
In this project, you’ll build a sensor monitoring system using a TTGO LoRa32 SX1276 OLED board that sends temperature, humidity and pressure readings via LoRa radio to an ESP32 LoRa receiver. The receiver displays the latest sensor readings on a web server.
With this project you’ll learn how to:
Send sensor readings via LoRa radio between two ESP32 boards;
Add LoRa and Wi-Fi capabilities simultaneously to your projects (LoRa + Web Server on the same ESP32 board);
Use the TTGO LoRa32 SX1276 OLED board or similar development boards for IoT projects.
Recommended reading:
TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE
Project Overview
The following image shows a high-level overview of the project we’ll build throughout this tutorial.
The LoRa sender sends BME280 sensor readings via LoRa radio every 10 seconds;
The LoRa receiver gets the readings and displays them on a web server;
You can monitor the sensor readings by accessing the web server;
The LoRa sender and the Lora receiver can be several hundred meters apart depending on their location. So, you can use this project to monitor sensor readings from your fields or greenhouses if they are a bit apart from your house;
The LoRa receiver is running an asynchronous web server and the web page files are saved on the ESP32 filesystem (LittleFS);
The LoRa receiver also shows the date and time the last readings were received. To get date and time, we use the
Network Time Protocol with the ESP32
For an introduction to LoRa communication:
what’s LoRa, LoRa frequencies, LoRa applications and more, read our
Getting Started ESP32 with LoRa using Arduino IDE
Parts Required
For this project, we’ll use the following components:
TTGO LoRa32 SX1276 OLED board
(2x):
this is an ESP32 development board with a LoRa chip and a built-in OLED. You can use similar boards, or you can use an
ESP32 + LoRa chip + OLED separately
BME280 temperature, humidity and pressure sensor
. You should be able to modify this project to use any other sensor.
You’ll also need some
jumper wires
and a
breadboard
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Preparing the Arduino IDE
To program the TTGO LoRa32 SX1276 OLED boards we’ll use
Arduino IDE
. To upload files to the ESP32 filesystem, we’ll use the
ESP32 LittleFS filesystem uploader plugin
So, before proceeding, you need to install the
ESP32 boards
and the
ESP32 filesystem uploader plugin
in your Arduino IDE.
Installing libraries
For this project, you need to install several libraries.
LoRa, BME280, OLED, and Web Server Libraries
The following libraries can be installed through the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the libraries’ name.
LoRa library:
arduino-LoRa library by sandeep mistry
OLED libraries:
Adafruit_SSD1306 library
and
Adafruit_GFX library
BME280 libraries:
Adafruit_BME280 library
and
Adafruit unified sensor library
Web Server libraries:
ESPAsyncWebServer
(by ESP32Async) and
AsyncTCP
(by ESP32Async)
NTPClient Library
Everytime the LoRa receiver picks up a new a LoRa message, it will request the date and time from an NTP server so that we know when the last packet was received.
For that we’ll be using the
NTPClient library forked by Taranais
. Follow the next steps to install this library in your Arduino IDE:
IMPORTANT
: we’re not using the default NTPClient library. To follow this tutorial you need to install the library we recommend using the following steps.
Click here to download the NTP Client library
. You should have a .zip folder in your
Downloads
In your Arduino IDE, go to
Sketch
>
Include Library
>
Add . ZIP library
…
Select the .ZIP file of the library you just downloaded.
The library will be installed after a few seconds.
LoRa Sender
The LoRa Sender is connected to a
BME280 sensor
and sends temperature, humidity, and pressure readings every 10 seconds. You can change this period of time later in the code.
Recommended reading:
ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)
LoRa Sender Circuit
The BME280 we’re using communicates with the ESP32 using I2C communication protocol. Wire the sensor as shown in the next schematic diagram:
BME280
ESP32
VIN
3.3 V
GND
GND
SCL
GPIO 13
SDA
GPIO 21
LoRa Sender Code
The following code reads temperature, humidity and pressure from the BME280 sensor and sends the readings via LoRa radio.
Copy the following code to your Arduino IDE.
/*********
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Libraries for BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 866E6
//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//BME280 definition
#define SDA 21
#define SCL 13
TwoWire I2Cone = TwoWire(1);
Adafruit_BME280 bme;
//packet counter
int readingID = 0;
int counter = 0;
String LoRaMessage = "";
float temperature = 0;
float humidity = 0;
float pressure = 0;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
//Initialize OLED display
void startOLED(){
//reset OLED display via software
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
//initialize OLED
Wire.begin(OLED_SDA, OLED_SCL);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("LORA SENDER");
}
//Initialize LoRa module
void startLoRA(){
//SPI LoRa pins
SPI.begin(SCK, MISO, MOSI, SS);
//setup LoRa transceiver module
LoRa.setPins(SS, RST, DIO0);
while (!LoRa.begin(BAND) && counter < 10) {
Serial.print(".");
counter++;
delay(500);
}
if (counter == 10) {
// Increment readingID on every new reading
readingID++;
Serial.println("Starting LoRa failed!");
}
Serial.println("LoRa Initialization OK!");
display.setCursor(0,10);
display.clearDisplay();
display.print("LoRa Initializing OK!");
display.display();
delay(2000);
}
void startBME(){
I2Cone.begin(SDA, SCL, 100000);
bool status1 = bme.begin(0x76, &I2Cone);
if (!status1) {
Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
while (1);
}
}
void getReadings(){
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
}
void sendReadings() {
LoRaMessage = String(readingID) + "/" + String(temperature) + "&" + String(humidity) + "#" + String(pressure);
//Send LoRa packet to receiver
LoRa.beginPacket();
LoRa.print(LoRaMessage);
LoRa.endPacket();
With this project you’ll learn how to:
Send sensor readings via LoRa radio between two ESP32 boards;
Add LoRa and Wi-Fi capabilities simultaneously to your projects (LoRa + Web Server on the same ESP32 board);
Use the TTGO LoRa32 SX1276 OLED board or similar development boards for IoT projects.
Recommended reading:
TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE
Project Overview
The following image shows a high-level overview of the project we’ll build throughout this tutorial.
The LoRa sender sends BME280 sensor readings via LoRa radio every 10 seconds;
The LoRa receiver gets the readings and displays them on a web server;
You can monitor the sensor readings by accessing the web server;
The LoRa sender and the Lora receiver can be several hundred meters apart depending on their location. So, you can use this project to monitor sensor readings from your fields or greenhouses if they are a bit apart from your house;
The LoRa receiver is running an asynchronous web server and the web page files are saved on the ESP32 filesystem (LittleFS);
The LoRa receiver also shows the date and time the last readings were received. To get date and time, we use the
Network Time Protocol with the ESP32
For an introduction to LoRa communication:
what’s LoRa, LoRa frequencies, LoRa applications and more, read our
Getting Started ESP32 with LoRa using Arduino IDE
Parts Required
For this project, we’ll use the following components:
TTGO LoRa32 SX1276 OLED board
(2x):
this is an ESP32 development board with a LoRa chip and a built-in OLED. You can use similar boards, or you can use an
ESP32 + LoRa chip + OLED separately
BME280 temperature, humidity and pressure sensor
. You should be able to modify this project to use any other sensor.
You’ll also need some
jumper wires
and a
breadboard
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Preparing the Arduino IDE
To program the TTGO LoRa32 SX1276 OLED boards we’ll use
Arduino IDE
. To upload files to the ESP32 filesystem, we’ll use the
ESP32 LittleFS filesystem uploader plugin
So, before proceeding, you need to install the
ESP32 boards
and the
ESP32 filesystem uploader plugin
in your Arduino IDE.
Installing libraries
For this project, you need to install several libraries.
LoRa, BME280, OLED, and Web Server Libraries
The following libraries can be installed through the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the libraries’ name.
LoRa library:
arduino-LoRa library by sandeep mistry
OLED libraries:
Adafruit_SSD1306 library
and
Adafruit_GFX library
BME280 libraries:
Adafruit_BME280 library
and
Adafruit unified sensor library
Web Server libraries:
ESPAsyncWebServer
(by ESP32Async) and
AsyncTCP
(by ESP32Async)
NTPClient Library
Everytime the LoRa receiver picks up a new a LoRa message, it will request the date and time from an NTP server so that we know when the last packet was received.
For that we’ll be using the
NTPClient library forked by Taranais
. Follow the next steps to install this library in your Arduino IDE:
IMPORTANT
: we’re not using the default NTPClient library. To follow this tutorial you need to install the library we recommend using the following steps.
Click here to download the NTP Client library
. You should have a .zip folder in your
Downloads
In your Arduino IDE, go to
Sketch
>
Include Library
>
Add . ZIP library
…
Select the .ZIP file of the library you just downloaded.
The library will be installed after a few seconds.
LoRa Sender
The LoRa Sender is connected to a
BME280 sensor
and sends temperature, humidity, and pressure readings every 10 seconds. You can change this period of time later in the code.
Recommended reading:
ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)
LoRa Sender Circuit
The BME280 we’re using communicates with the ESP32 using I2C communication protocol. Wire the sensor as shown in the next schematic diagram:
BME280
ESP32
VIN
3.3 V
GND
GND
SCL
GPIO 13
SDA
GPIO 21
LoRa Sender Code
The following code reads temperature, humidity and pressure from the BME280 sensor and sends the readings via LoRa radio.
Copy the following code to your Arduino IDE.
/*********
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Libraries for BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 866E6
//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//BME280 definition
#define SDA 21
#define SCL 13
TwoWire I2Cone = TwoWire(1);
Adafruit_BME280 bme;
//packet counter
int readingID = 0;
int counter = 0;
String LoRaMessage = "";
float temperature = 0;
float humidity = 0;
float pressure = 0;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
//Initialize OLED display
void startOLED(){
//reset OLED display via software
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
//initialize OLED
Wire.begin(OLED_SDA, OLED_SCL);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("LORA SENDER");
}
//Initialize LoRa module
void startLoRA(){
//SPI LoRa pins
SPI.begin(SCK, MISO, MOSI, SS);
//setup LoRa transceiver module
LoRa.setPins(SS, RST, DIO0);
while (!LoRa.begin(BAND) && counter < 10) {
Serial.print(".");
counter++;
delay(500);
}
if (counter == 10) {
// Increment readingID on every new reading
readingID++;
Serial.println("Starting LoRa failed!");
}
Serial.println("LoRa Initialization OK!");
display.setCursor(0,10);
display.clearDisplay();
display.print("LoRa Initializing OK!");
display.display();
delay(2000);
}
void startBME(){
I2Cone.begin(SDA, SCL, 100000);
bool status1 = bme.begin(0x76, &I2Cone);
if (!status1) {
Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
while (1);
}
}
void getReadings(){
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
}
void sendReadings() {
LoRaMessage = String(readingID) + "/" + String(temperature) + "&" + String(humidity) + "#" + String(pressure);
//Send LoRa packet to receiver
LoRa.beginPacket();
LoRa.print(LoRaMessage);
LoRa.endPacket();
Technologies used
Hardware components
- ESP32
- Arduino
- BME280
- SSD1306
- OLED
- SX1276
Software & tools
- Arduino IDE
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.