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 » STM32 NRF24L01 Sensor Node with ESP32 NRF24L01 Gateway
IoT Projects STM32 Projects

STM32 NRF24L01 Sensor Node with ESP32 NRF24L01 Gateway

Mamtaz AlamBy Mamtaz AlamUpdated:May 29, 20234 Comments7 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ESP32 NRF24L01
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this project, we will monitor the sensor data wirelessly using the NRF24L01 STM32 Board & ESP32 Wifi Module. We will first make a Wireless Sensor Node. A sensor node is made up of four basic components such as sensing unit, processing unit, transceiver unit, and a power unit. The Sensing unit can be made up of any Sensor. I am using the BME280 Barometric Pressure Sensor. The processing unit is the STM32F103C Microcontroller and the transceiver unit is the NRF24L01 2.4 GHz Wireless transceiver Module which works as a transmitter unit. While considering the power unit, the device can be powered up using 3.7V Lithium-Ion Battery.

We will make Wifi Gateway using ESP32 Wifi Module & NRF24L01 Module. An IoT gateway performs several critical functions from translating protocols to encrypting, processing, managing, and filtering data. If you imagine an IoT ecosystem, a gateway sits between devices and sensors to communicate with the cloud. In this project, the gateway collects the sensor data from multiple sensor nodes, and using the wifi network it uploads the data to the cloud. The cloud server that we are using here is the Thingspeak Server. ThingSpeak is an open-source Internet of Things application and API to store and retrieve data from things using the HTTP and MQTT protocol over the Internet or via a Local Area Network.

In one of our previous project we made a gateway using ESP8266 & NRF24L01 & Sensor Node using Arduino & NRF24L01. You can check the project here: NRF24L01 Gateway + Node


Bill of Materials

All the components required for making the gateway and sensor node is listed below. You can purchase all of the components from Amazon.

S.N.Components NameQuantityPurchase Links
1ESP32 Board1Amazon | AliExpress
2STM32 Microcontroller2Amazon | AliExpress
3 NRF24L01 PA+LNA2Amazon | AliExpress
4BME280 Barometric Pressure Sensor1Amazon | AliExpress
5Power Supply 5V2Amazon | AliExpress
6Connecting Wires20Amazon | AliExpress
7Breadboard1Amazon | AliExpress




NRF24L01 Module

NRF24L01

The nRF24L01 is a wireless transceiver module, i.e. each module can both send & receive data. It works within the frequency of 2.4GHz. This frequency falls under the ISM band and is legal to use in most countries for engineering projects. The modules when operated efficiently can cover a distance of 100 meters.

The module operates at 3.3V but its SPI pins are 5V tolerable. Each module has an address range of 125 and every module can communicate with 6 other modules hence mesh networking can be established with this module. The NRF24L01 module works with the help of SPI communications hence you can use NRF24L01 with any microcontroller with SPI Pins like STM32 or Arduino Boards.


Sensor Node Using NRF24L01 & STM32F103C

Let us see the Sensor Node Circuit. We can use any microcontroller with NRF24L01 for designing a Sensor Node. For example, STM32F103C Bluepill Board is the best option. Apart from the microcontroller, you can use any sensor and interface it with STM32 Board. I prefer BME280 Barometric Pressure Sensor for demonstration purpose.

The connection between STM32F103C Board, NRF24L01 Wireless Transceiver Module & BME280 Sensor is given below.

NRF24L01 VCC ………………………………………… 3.3V of STM32F103C
NRF24L01 CSN ………………………………………… PA4 of STM32F103C
NRF24L01 MOSI ………………………………………… PA7 of STM32F103C
NRF24L01 GND ………………………………………… GND of STM32F103C
NRF24L01 CE ………………………………………… PB0 of STM32F103C
NRF24L01 SCK ………………………………………… PA5 of STM32F103C
NRF24L01 MISO ………………………………………… PA6 of STM32F103C

You can also design a simple Sender and Receiver Circuit with a pair of NRF24L01 & STM32 Board. Check it here: Interfacing NRF24L01 Transceiver Module with STM32.




WiFi Gateway Using NRF24L01 & ESP32

The Gateway receives the data from the single or multiple Sensor Node using the NRF24L01 Transceiver Module. After receiving data it uploads the data to Server. For establishing a connection with the Server, the WiFi Network can be used. The ESP32 along with NRF24L01 is best preferred for designing the WiFi Gateway.

The connection between ESP32 Board & NRF24L01 Wireless Transceiver Module is given below.

circuit ESP32 nRF24L01

NRF24L01 VCC ………………………………………… 3.3V of ESP32
NRF24L01 CSN ………………………………………… D5 of ESP32
NRF24L01 MOSI ………………………………………… D23 of ESP32
NRF24L01 GND ………………………………………… GND of ESP32
NRF24L01 CE ………………………………………… D4 of ESP32
NRF24L01 SCK ………………………………………… D18 of ESP32
NRF24L01 MISO ………………………………………… D19 of ESP32


Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the ESP32 NRF24L01 Gateway & STM32 NRF24L01 Node is designed using EasyEDA online Circuit Schematics & PCB designing tool. The image of the Sender PCB is given below.

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.

  1. Download Gerber File for Node PCB: Sender PCB
  2. Download Gerber File for Gateway PCB: Receiver PCB

You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.

You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.

After filling all details, select your country and shipping method. Finally you can place the order.


Library Installation

1. BME280 Library

The BME280 library provides a library for reading and interpreting Bosch BME280 environmental sensor data over I2C, SPI or Sw SPI. It reads the temperature, humidity, and pressure by including environment calculations.

Download BME280 Library

2. NRF24L01 Library

The STM32 Board doesn’t support nRF24L01 RadioHead Library (#include <RH_NRF24.h>). Hence we need to use RF24 Library. This library is designed to be maximally compliant with the intended operation of the chip & built against the standard SPI library. You can download the library from the following Github link. Add the library to the Arduino IDE.

Download NRF24L01 Library


Setting Up Thingspeak Server

ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. You can send data to ThingSpeak from your devices, create instant visualization of live data, and send alerts.

We need to Setup Thingspeak dashboard to receive the data and display in graphical format. You can visit Thingspeak and create an account here.

Create a New Channel with the following Parameters as shown in the image below. After filling all these details, click on the Save channel.

Go to the API Key and copy the Write API Key. The API key is required in the Gateway Code.



Source Code/Program for Sensor Node

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
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <nRF24L01.h>
#include <RF24.h>
 
RF24 radio(PB0, PA4); // CE, CSN on Blue Pill
const uint64_t address = 0xF0F0F0F0E1LL;
int counter = 0;
 
 
float temperature;
float humidity;
float altitude;
float pressure;
 
#define SEALEVELPRESSURE_HPA (1013.25)
 
Adafruit_BME280 bme;
 
struct MyData
{
  int counter;
  float temperature;
  float humidity;
  float altitude;
  float pressure;
};
MyData data;
 
void setup()
{
Serial.begin(115200);
radio.begin();                  //Starting the Wireless communication
radio.openWritingPipe(address); //Setting the address where we will send the data
radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.stopListening();          //This sets the module as transmitter
 
if (!bme.begin(0x76))
{
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
 
}
 
void loop()
{
  data.counter = counter;
  data.temperature = bme.readTemperature();
  data.pressure = bme.readPressure() / 100.0F;
  data.altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  data.humidity = bme.readHumidity();
  
  Serial.print("Packet No. = ");
  Serial.println(data.counter);
  
  Serial.print("Temperature = ");
  Serial.print(data.temperature);
  Serial.println("*C");
 
  Serial.print("Pressure = ");
  Serial.print(data.pressure);
  Serial.println("hPa");
 
  Serial.print("Approx. Altitude = ");
  Serial.print(data.altitude);
  Serial.println("m");
 
  Serial.print("Humidity = ");
  Serial.print(data.humidity);
  Serial.println("%");
 
  Serial.println();
  
  radio.write(&data, sizeof(MyData));
  
  Serial.println("Data Packet Sent");
  Serial.println("");
  
  counter++;
  delay(5000);
}


Source Code/Program for ESP32 Wifi Gateway

Before uploading the code, make changes to the Wifi SSID & Password. Also replace the Thingspeak API Key with your own API Key.

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
#include <WiFi.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
 
String apiKey = "C25ICK6FHOR7PST4";
 
const char* ssid = "Alexahome";
const char* password = "loranthus";
 
const char* server = "api.thingspeak.com";
 
RF24 radio(4, 5);
const uint64_t address = 0xF0F0F0F0E1LL;
 
struct MyData
{
  int counter;
  float temperature;
  float humidity;
  float altitude;
  float pressure;
};
MyData data;
 
WiFiClient client;
 
void setup()
{
  Serial.begin(115200);
  radio.begin();
  
 
  Serial.println("Receiver Started....");
  Serial.print("Connecting to ");
  Serial.println(ssid);
  Serial.println();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
  radio.startListening();              //This sets the module as receiver
}
 
int recvData()
{
  if ( radio.available() )
  {
    radio.read(&data, sizeof(MyData));
    return 1;
    }
    return 0;
}
 
 
void loop()
{
  if(recvData())
  {
 
  Serial.println("Data Received:");
  Serial.print("Packet No. = ");
  Serial.println(data.counter);
  
  Serial.print("Temperature = ");
  Serial.print(data.temperature);
  Serial.println("*C");
 
  Serial.print("Pressure = ");
  Serial.print(data.pressure);
  Serial.println("hPa");
 
  Serial.print("Approx. Altitude = ");
  Serial.print(data.altitude);
  Serial.println("m");
 
  Serial.print("Humidity = ");
  Serial.print(data.humidity);
  Serial.println("%");
 
  Serial.println();
 
  if (client.connect(server, 80))
  {
        String postStr = apiKey;
        postStr += "&field1=";
        postStr += String(data.temperature);
        postStr += "&field2=";
        postStr += String(data.pressure);
        postStr += "&field3=";
        postStr += String(data.altitude);
        postStr += "&field4=";
        postStr += String(data.humidity);
        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(1000);
        Serial.println("Data Sent to Server");
      }
        client.stop();
  }
}


Result: ESP32+ NRF24L01 Wifi Gateway with STM32+ NRF24L01 Node

STM32 NRF24L01 ESP32 Gateway

After assembling the Sensor Node & Gateway on a breadboard, you can upload the above codes to the respective nodes.

Soon after the code is uploaded, you can open the respective Serial Monitor.

The BME280 Sensor Data from Transmitter is received by Receiver/Gateway. The Gateway displays the received data like temperature, humidity, pressure, and altitude on the Serial Monitor.


Similarly you can monitor the data online on Thingspeak Server. For that, go to the private view of Thingspeak Server. The data will be logged on after the interval of 15 seconds. To make the device more better, you can implement the Sleep Mode feature and change Data Sending Interval.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterfacing NRF24L01 Transceiver Module with STM32 Tx/Rx
Next Article DIY Infrared Thermometer using MLX90614, Arduino & OLED

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
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
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 4 Comments

4 Comments

  1. tomccs on March 26, 2021 2:49 AM

    Hello! Great project! The sender works fine on Arduino Pro Mini.
    I tried to make the reciever work on the esp32 but with no luck (WIFI, thingspeak part work only I’m having trouble with nrf24l01).
    First of all I used TMRh20’s RF24 library https://github.com/nRF24/RF24
    because with the one you linked didnt compile to esp32 board.
    The program started but the recvData() returns with 1 even if theres no sender plugged in, and also it shows 0 values if so.

    Could you confirm that this is working on your side?
    Thank you!

    Reply
    • Mr. Alam on March 26, 2021 10:26 AM

      The circuit is tested along with the code. It works perfectly.

      Reply
  2. [email protected] on October 8, 2021 12:55 AM

    SIR CAN WE GET THE HEX FILE OF THE CODE??

    Reply
  3. SunilDJ on November 28, 2021 8:08 PM

    use this modified revision of RF24 lib (works with esp32) https://github.com/nhatuan84/RF24

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 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
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module 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 (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • 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.