Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » ESP32 LoRa Thingspeak Gateway with LoRa Sensor Node
ESP32 Projects IoT Projects LoRa/LoRaWAN Projects

ESP32 LoRa Thingspeak Gateway with LoRa Sensor Node

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20222 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ESP32 LoRa Thingspeak Gateway Sensor Node
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this project, we will make ESP32 LoRa Thingspeak Gateway with LoRa Sensor Node. The project is basically a sensor monitoring system on Thingspeak Server using an ESP32 board & LoRa Module SX1278 or SX1276.


Overview

In the last couple of years, there is a number of communication technologies available for interaction between IoT devices. The most popular ones are the Wi-Fi Technology and Bluetooth Module. But they have few limitations like limited range, limited access points & high power consumption. So LoRa technology is introduced by Semtech to fix all these issue. Using a single battery the device operates over a year.

So, in this IoT Project, we will design ESP32 LoRa Gateway & also ESP32 LoRa Sensor Node to monitor the sensor reading wirelessly from a few kilometer distances. The sender will read the humidity and temperature data using DHT11 Sensor. Then it transmits the data via LoRa Radio. The data is received by the receiver module. The receiver will then send the data to Thingspeak Server after certain interval.



Before getting started, you can visit the following posts:
1. Interfacing SX1278 (Ra-02) LORA Module with Arduino: Check Here
2. Sending Sensor Data Wirelessly with LoRa SX1278 & Arduino: Check Here
3. ESP8266 & LoRa SX1278 Transmitter Receiver with DHT11: Check Here
4. ESP32 & LoRa SX1278/76 Transmitter Receiver with OLED: Check Here
5. ESP32 LoRa Sensor Data Monitoring on Web Server: Check Here


Bill of Materials

Following are the components required for making this project. All the components can easily be purchased from Amazon. The components purchase link is given below.

S.N.Components NameQuantityPurchase Links
1ESP32 Board2Amazon | AliExpress
2LoRa Module SX12782Amazon | AliExpress
3DHT11 Sensor1Amazon | AliExpress
4Connecting Wires10Amazon | AliExpress
5Breadboard1Amazon | AliExpress

Installing the Required Libraries

Several Libraries are required for the project to program the ESP32 Board with Arduino IDE.

1. DHT11 Library

To read the temperature and humidity we need any temperature humidity sensor. For that DHT11 is the best and cheap sensor. We need to install DHT11 Library for that. Download the library from below and add to the Arduino IDE.

Download DHT11 Library

2. LoRa Library

We need an Arduino library for sending and receiving data using LoRa radios. The library supports module like Semtech SX1276, SX1277, SX1278, SX1279 and also HopeRF RFM95W, RFM96W and RFM98W.

Download LoRa Radio Library




Circuit: ESP32 LoRa Thingspeak Gateway with LoRa Sensor Node

Now let us see the sender and receiver circuit for building ESP32 LoRa Gateway & Sensor Node. I assembled both the circuit on breadboard. You can make it on PCB if you want.

ESP32 LoRa Sensor Node

Here is an ESP32 LoRa Sensor Node Circuit with DHT11 Sensor. This part work as a transmitter. The humidity and temperature data is read by DHT11 Humidity Temperature Sensor and transmitted using LoRa Radio.

ESP32 Lora Sensor Node

The connection is fairly simple. Simlarly connect the Lora SX1278 & ESP32 as follows.

ESP32 PinsSX1278 Pins
GND GND
3.3VVCC
D5NSS
D23 MOSI
D19 MISO
D18 SCK
D14 RST
D2 DIO0

Similarly connect the DHT11 digital input pin to GPIO4 of ESP32. Connect its VCC to 3.3V & GND to GND of ESP32.

ESP32 LoRa Sensor Node


ESP32 LoRa Thingspeak Gateway

Here is an ESP32 LoRa Module SX1278 Gateway Circuit. This part work as a Receiver. The humidity and temperature data is received using LoRa Radio & uploaded to Thingspeak Server.

ESP32 LoRa Gateway

The ESP32 & LoRa SX1278 connection same as above.

ESP32 LoRa Gateway



Setting Up Thingspeak

In order to Monitor the Sensor Data on Thingspeak Server, you first need to Setup the Thingspeak. To set up the Thingspeak Server, visit https://thingspeak.com/. Create an account or simply sign in if you created the account earlier. Then create a new channel with following details.


ESP32 LoRa Sensor Node Code

After assembling the circuit on breadboard for Sensor Node Circuit. Copy the following code and upload it to the ESP32 Board. Before uploading make sure to do the changes in the LoRa frequency according to region.

C++
1
#define BAND 433E6    //433E6 for Asia, 866E6 for Europe, 915E6 for North America

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
 
//Libraries for LoRa
#include "DHT.h"
#define DHTPIN 4          //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
 
//define the pins used by the LoRa transceiver module
#define ss 5
#define rst 14
#define dio0 2
 
#define BAND 433E6    //433E6 for Asia, 866E6 for Europe, 915E6 for North America
 
//packet counter
int readingID = 0;
 
int counter = 0;
String LoRaMessage = "";
 
float temperature = 0;
float humidity = 0;
 
 
 
//Initialize LoRa module
void startLoRA()
{
  LoRa.setPins(ss, rst, dio0); //setup LoRa transceiver module
 
  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!");
  delay(2000);
}
 
void startDHT()
{
  if (isnan(humidity) || isnan(temperature))
  {
  Serial.println("Failed to read from DHT sensor!");
  return;
  }
}
 
void getReadings(){
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();
  Serial.print(F("Humidity: "));
  Serial.print(humidity);
  Serial.print(F("%  Temperature: "));
  Serial.print(temperature);
  Serial.println(F("°C "));
}
 
void sendReadings() {
  LoRaMessage = String(readingID) + "/" + String(temperature) + "&" + String(humidity) ;
  //Send LoRa packet to receiver
  LoRa.beginPacket();
  LoRa.print(LoRaMessage);
  LoRa.endPacket();
  
  Serial.print("Sending packet: ");
  Serial.println(readingID);
  readingID++;
  Serial.println(LoRaMessage);
}
 
void setup() {
  //initialize Serial Monitor
  Serial.begin(115200);
  dht.begin();
  startDHT();
  startLoRA();
}
void loop() {
  getReadings();
  sendReadings();
  delay(500);
}


ESP32 LoRa Gateway Code

You can now copy the below code and upload the Gateway code to ESP32 Board. In the below code make changes to WiFi SSID, Password & Thingspeak API Key.

C++
1
2
3
String apiKey = "14K8UL2QEK8BTHN6"; // Enter your Write API key from ThingSpeak
const char *ssid = "Alexahome"; // replace with your wifi ssid and wpa2 key
const char *password = "12345678";


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Import Wi-Fi library
#include <WiFi.h>
 
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
 
//define the pins used by the LoRa transceiver module
#define ss 5
#define rst 14
#define dio0 2
 
#define BAND 433E6    //433E6 for Asia, 866E6 for Europe, 915E6 for North America
 
 
// Replace with your network credentials
String apiKey = "14K8UL2QEK8BTHN6"; // Enter your Write API key from ThingSpeak
const char *ssid = "Alexahome"; // replace with your wifi ssid and wpa2 key
const char *password = "12345678";
const char* server = "api.thingspeak.com";
 
WiFiClient client;
 
 
// Initialize variables to get and save LoRa data
int rssi;
String loRaMessage;
String temperature;
String humidity;
String readingID;
 
 
// Replaces placeholder with DHT values
String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATURE")
  {
    return temperature;
  }
  else if(var == "HUMIDITY")
  {
    return humidity;
  }
  else if (var == "RRSI")
  {
    return String(rssi);
  }
  return String();
}
 
void setup() {
  Serial.begin(115200);
  int counter;
 
  //setup LoRa transceiver module
  LoRa.setPins(ss, rst, dio0); //setup LoRa transceiver module
 
  while (!LoRa.begin(BAND) && counter < 10) {
    Serial.print(".");
    counter++;
    delay(2000);
  }
  if (counter == 10) {
    // Increment readingID on every new reading
    Serial.println("Starting LoRa failed!");
  }
  Serial.println("LoRa Initialization OK!");
  delay(2000);
 
  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
 
// Read LoRa packet and get the sensor readings
void loop()
{
  int packetSize = LoRa.parsePacket();
  if (packetSize)
  {
    Serial.print("Lora packet received: ");
    while (LoRa.available())    // Read packet
  {
    String LoRaData = LoRa.readString();
    Serial.print(LoRaData);
    
    
    int pos1 = LoRaData.indexOf('/');  
    int pos2 = LoRaData.indexOf('&');  
    readingID = LoRaData.substring(0, pos1);                   // Get readingID
    temperature = LoRaData.substring(pos1 +1, pos2);           // Get temperature
    humidity = LoRaData.substring(pos2+1, LoRaData.length());  // Get humidity
  }
  
  rssi = LoRa.packetRssi();       // Get RSSI
  Serial.print(" with RSSI ");    
  Serial.println(rssi);
}
 
  
  if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com
   {
      String postStr = apiKey;
      postStr += "&field1=";
      postStr += String(readingID);
      postStr += "&field2=";
      postStr += String(temperature);
      postStr += "&field3=";
      postStr += String(humidity);
      postStr += "&field4=";
      postStr += String(rssi);
      postStr += "\r\n\r\n\r\n\r\n";
    
      client.print("POST /update HTTP/1.1\n");
      client.print("Host: api.thingspeak.com\n");
      client.print("Connection: close\n");
      client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
      client.print("Content-Type: application/x-www-form-urlencoded\n");
      client.print("Content-Length: ");
      client.print(postStr.length());
      client.print("\n\n");
      client.print(postStr);
 
    }    
    //delay(30000);
}


Monitoring Sensor Data on Thingspeak Server

Once the code is uploaded, you can open the Serial Monitor on both the Gateway & Sensor Node Circuit. You will see the following output if the code is connections are correct.

Now you can visit Thingspeak Private View. There you can see the data for Packet Number, Temperature, Humidity & Gateway is uploaded after the interval of 15 seconds. You can modify the delay function in the code to change the timing of the data retrieval.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT Sound Level Monitor with ESP8266 & Sound Module
Next Article IoT Decibelmeter with Sound Sensor & ESP8266

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20262K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
View 2 Comments

2 Comments

  1. Andres Jaramillo on December 8, 2020 1:28 AM

    Hello, good afternoon, I have a question
    When I execute your code, the receiver node connects to my internet network but does not print the message of the received packets, the temperature, humidity and the rssi. Maybe you know why it is?

    Reply
  2. sandeep singh on May 12, 2021 11:10 PM

    sir i am not able to receive the data on lora gateway code is correct everything is correct can you tell me

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.