Here is a simple ESP8266 NRF24L01 Wifi Gateway with Arduino NRF24L01 Node. The data transfer can be done wirelessly from Sensor Node to Gateway and monitoring via Thingspeak on Cloud.
Overview: ESP8266 NRF24L01 Wifi Gateway + Arduino NRF24L01 Node
In this tutorial we will learn how to make wireless communication between Arduino board and NodeMCU ESP8266 using the NRF24L01 transceiver module. We will upload the received data on Thingspeak Server. The NRF24L01 can receive data up to 100m distance whereas we can monitor data worldwide using NodeMCU.
The sensor Node comprises of NRF24L01 interfaced with any Microcontroller Board like Arduino or NodeMCU ESP8266. In my case, I am using NodeMCU Board as a Sensor Node Circuit. The sensor Node contains a Sensor whose data is to be transmitted to the Gateway using the NRF24L01 transceiver module. Here for a simple demonstration, I am using DHT11 Humidity & Temperature Sensor. Thus we will be sending the Humidity & Temperature Data to Gateway.
On the receiver end, we will be interfacing NodeMCU ESP8266-12E Board with the NRF24L01 transceiver module. This is the Receiver or also called as Gateway. The Gateway has the ability to get connected to the WiFi Network. The Gateway Receives Temperature & Humidity Data wirelessly via the NRF24L01 transceiver module. The Gateway will now upload the Temperature & Humidity value to Thingspeak Server.
Before moving ahead, I would like to highly recommend you to read the previous article on NRF24L01 with Arduino: Check the link here to clear all the basics related to the cheap Transceiver Module.
Read Here: NRF24L01 Arduino Transmitter Receiver Tutorial
Bill of Materials
Following are the components required for making this project. All the components can be eaily purchased from Amazon. The components purchase link is given below.
| S.N. | Components | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino UNO Board | 1 | Amazon | AliExpress |
| 2 | NodeMCU ESP8266 Board | 1 | Amazon | AliExpress |
| 3 | NRF24L01 | 2 | Amazon | AliExpress |
| 4 | DHT11 Sensor | 1 | Amazon | AliExpress |
| 5 | Connecting Wires | 20 | Amazon | AliExpress |
| 6 | Breadboard | 1 | Amazon | AliExpress |
Circuit Diagram & Connections
Here we need two circuit assembly to make a wireless communication. The first circuit is the Node Circuit & the second circuit is the Gateway Circuit. The Node Circuit doesn’t need Wifi Connection and can be made using any microcontroller. You can either use NodeMCU ESP8266 or just an Arduino Board.
The second circuit is the Gateway Receiver Circuit and it needs Wifi Connection. So we need NodeMCU ESP8266 Board.
Transmitter Circuit: NRF24L01 Arduino/ESP8266 Node
Assemble the Transmitter circuit as shown in the figure below. It consists Arduino Uno, nRF24L01 & DHT11 Sensor.

Here is a The NRF24L01 pins Connection with Arduino Nano:
MISO connects to pin 12 of the Arduino Nano
MOSI connects to pin 11 of the Arduino Nano
SCK connects to pin 13 of the Arduino Nano
CE connects to pin 7 of the Arduino Nano
CSN connects to pin 8 of the Arduino Nano
GND and VCC of the NRF24L01 are connected to GND and 3.3V of the Arduino Nano
The DHT11 Humidity & Temperature Sensor is connected to pin 2 of the Arduino Board. Connect its VCC & GND to Arduino Nano 5V & GND Pin.
In case if you want to use NodeMCU ESP8266 Board as Sensor Node instead of Arduino Board, you can use the following circuit. Assemble the circuit as shown in the circuit diagram below.

Here is a The NRF24L01 pins Connection with NodeMCU ESP8266 Board:
MISO connects to pin D6 of the NodeMCU
MOSI connects to pin D7 of the NodeMCU
SCK connects to pin D5 of the NodeMCU
CE connects to pin D4 of the NodeMCU
CSN connects to pin D2 of the NodeMCU
GND and VCC of the NRF24L01 are connected to GND and 3.3V of the NodeMCU
The DHT11 Humidity & Temperature Sensor is connected to the D1 pin of NodeMCU. Connect its VCC & GND to NodeMCU 3.3V & GND Pin.
Receiver Circuit: NRF24L01 ESP8266 Gateway
Assemble the Receiver circuit as shown in the figure below. It consists of Nodemcu ESP8266 Board & nRF24L01 Module.

Here is a The NRF24L01 pins Connection with NodeMCU ESP8266 Board:
MISO connects to pin D6 of the NodeMCU
MOSI connects to pin D7 of the NodeMCU
SCK connects to pin D5 of the NodeMCU
CE connects to pin D4 of the NodeMCU
CSN connects to pin D2 of the NodeMCU
GND and VCC of the NRF24L01 are connected to GND and 3.3V of the NodeMCU
PCB Designing & Ordering Online
The PCB for this project has been designed in EasyEDA online PCB making tool. Below is the front view and Back View of the PCB.


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. Gerber File for Gateway: Download
2. Gerber File for Sensor Node using ESP8266: Download
3. Gerber File for Sensor Node using Arduino Nano: Download
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.
Setting up Thingspeak
Now we need to setup the Thingspeak Account. To set up Thingspeak follow the following Steps:
Step 1: Visit https://thingspeak.com/ and create your account by filling up the details.
Step 2: Create a New Channel by Clicking on “Channel” & fill up the following details as shown in the image below.
Step 3: Click on API Key, you will see the “Write API Key“. Copy the API Key. This is very important, it will be required in Code Part.
Step 4: You can click on the “Private View” & customize the display window as you want.
So, that’s all from the Thingspeak Setup Part. Now let us move to the programming Part.
Installing Required Libraries
Before directly jumping into the coding part, we need to install few Libraries to Arduino IDE.
1. NRF24L01 Library
This is the RadioHead Packet Radio library for embedded microprocessors. It provides a complete object-oriented library for sending and receiving packetized messages via a variety of common data radios and other transports on a range of embedded microprocessors.
2. 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.
Source Code/program
Code for Assigning Unique Gateway & Node ID
In order to give each node and gateway it’s own unique address, we can use the following code to store the value in the EEPROM. The EEPROM has a lifespan of around 100,000 erase/writes.
Copy the below code & upload to the Gateway and Node, assigning a unique ID to each of them. The data ID is stored in EEPROM, so even after uploading any other code to the board, the ID won’t get erased.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <EEPROM.h> int deviceID = 0, curDeviceID; void setup() { Serial.begin(9600); EEPROM.write(0, deviceID); curDeviceID = EEPROM.read(0); if (curDeviceID == deviceID) { Serial.print("Arduino ID successfully changed to: "); Serial.println(curDeviceID); } } void loop() { // put your main code here, to run repeatedly: } |
Arduino/ESP8266 NRF24L01 Node Code
Here is the code for NRF24L01 Arduino Node. The code need to be uploaded to the Node Circuit. The code supports both the board, i.e. Arduino as well as NodeMCU ESP8266 Board.
|
1 2 3 4 5 |
RH_NRF24 nrf24(2, 4); // RH_NRF24 nrf24(8, 7); #define DHTPIN D1 //#define DHTPIN 2 |
Make modification on these lines by uncommenting/commenting if you are using Arduino Nano instead of NodeMCU Board.
|
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 |
#include <RH_NRF24.h> #include "DHT.h" #include <EEPROM.h> RH_NRF24 nrf24(2, 4); // use this for NodeMCU Amica/AdaFruit Huzzah ESP8266 Feather // RH_NRF24 nrf24(8, 7); // use this with Arduino UNO/Nano #define DHTPIN D1 //#define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); int deviceID = EEPROM.read(0); int humidity, temperature; void setup() { Serial.begin(115200); dht.begin(); while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only if (!nrf24.init()) { Serial.println("init failed"); } // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm if (!nrf24.setChannel(3)) { Serial.println("setChannel failed"); } if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm)) { Serial.println("setRF failed"); } Serial.println("Transmitter started"); } void loop() { humidity = dht.readHumidity(); temperature = dht.readTemperature(); if (isnan(humidity) || isnan(temperature)) { Serial.println(F("Failed to read from DHT sensor!")); return; } Serial.println("Sending to gateway"); uint8_t data[4]; data[0] = humidity; data[1] = temperature; data[2] = deviceID; Serial.println("------------- Measurements -------------"); Serial.print("Humidity: "); Serial.print(data[0]); Serial.print(", Temperature: "); Serial.print(data[1]); Serial.print(", ID: "); Serial.print(data[2]); Serial.println(); nrf24.send(data, sizeof(data)); nrf24.waitPacketSent(); // Now wait for a reply uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (nrf24.waitAvailableTimeout(1000)) { // Should be a reply message for us now if (nrf24.recv(buf, &len)) { Serial.print("got reply: "); Serial.println((char*)buf); } else { Serial.println("recv failed"); } } else { Serial.println("No reply."); } delay(5000); } |
ESP8266 NRF24L01 Gateway Code
Here is a code for ESP8266 NRF24L01 Gateway.
|
1 2 3 4 |
String apiKey = "KBD1JSZTUKCXJ15V"; const char* ssid = "**************"; const char* password = "****************"; |
Make changes to the Wifi SSID & Password as well as “Thingspeak 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 |
#include <RH_NRF24.h> #include <EEPROM.h> #include <ESP8266WiFi.h> String apiKey = "KBD1JSZTUKCXJ15V"; const char* ssid = "Alexahome"; const char* password = "loranthus"; WiFiClient client; int gatewayID = EEPROM.read(0); const char* server = "api.thingspeak.com"; RH_NRF24 nrf24(2, 4); // use this for NodeMCU Amica/AdaFruit Huzzah ESP8266 Feather void setup() { Serial.begin(115200); Serial.print("Receiver Started, ID: "); Serial.print("Connecting to "); Serial.println(ssid); Serial.print(gatewayID); Serial.println(); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); nrf24.init(); nrf24.setChannel(3); nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm); } void loop() { if (nrf24.available()) { // Should be a message for us now uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (nrf24.recv(buf, &len)) { // Send a reply uint8_t sdata[] = "Data Received."; nrf24.send(sdata, sizeof(sdata)); nrf24.waitPacketSent(); int humidity = buf[0]; int temperature = buf[1]; int deviceID = buf[2]; Serial.println("--- Data retrieved from device ---"); if (client.connect(server, 80)) { // "184.106.153.149" or api.thingspeak.com String postStr = apiKey; postStr += "&field1="; postStr += String(temperature); postStr += "&field2="; postStr += String(humidity); postStr += "&field3="; postStr += String(gatewayID); postStr += "&field4="; postStr += String(deviceID); postStr += "\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); Serial.println("---- Data sent to Thingspeak ----"); Serial.print("Device ID: "); Serial.print(deviceID); Serial.print(", Temperature:"); Serial.print(temperature); Serial.print(", Humidity:"); Serial.println(humidity); } delay(1000); client.stop(); } } else { //Serial.print("No New Message"); } //delay(15000); } |
Monitoring Data on Thingspeak Server
After uploading the code on both the board, you can open the Serial Monitor on both Port. If the wiring connections are correct and the device is working, then Serial Monitor will show the following data.
Now you can open your “Thingspeak Account” & go to the Private View. The data will be uploaded to Thingspeak Server after the Interval of every 15 seconds.
So, this is how we can make communication between ESP8266 NRF24L01 Wifi Gateway with Arduino NRF24L01 Node. There are a number of additions that would greatly improve the circuit. You can include local webserver to set up SSID/Passwords. You can make a deep sleep implementation to use with battery-powered nodes & reduce battery Life. Similarly, moving to an MQTT server will make data communication more smooth between nodes and a gateway.















18 Comments
The reviever section doesn’t receive humidity. It only recieves temperature.
Sender section send humidity @data[0]
Receiver section reviever temp @data[0]
Plz look into this
It’s logically wrong
Hi, Thank you for the comment. I have rectified the mistake. Now the code is correct and tested
hi alam
i have a similar project but i have to do something else..
i want to serial communication and wireless communication.
can you help me?
could you help me, I don’t have much programming knowledge, I can’t get the receiver code to work, send compilation error exit status 1
Sir,
I am having “Error compiling for board NodeMCU 1.0 (ESP-12E Module).”, when I am trying to compile the exact same code provided by you for Nodemcu. Please help me.
Hi!
i’m currently doing this kind of program. but, when i use this code it’s always shows “No Reply” in the Serial Monitor even if i used the exact same code and wiring connection with yours. there are no error message in the IDE and the temperature and humidity data from DHT are successfully read. Any Solutions?
This is a common problem with the NRF24L01 Module. They are prone to too much noise which doesn’t allow good communication.
You can add a 10uF electrolytic capacitor to VCC and GND pin of the NRF24L01 Module to reduce the noise.
Hi, is possible send floats on this program?
Hi, is it possible to use two transmitter and send to only one receiver?
our project is creating a separate transmitter (one consist of dht22 and the other one is for heart rate sensor) these will be send to one receiver.
hola, mi consulta es la siguiente: como puedo conectar la ESP32 con la NRF24
Hi, could you help me, your program is good, but when I add the gas sensor MQ135, it not read the value of gas sensor, the data type of gas sensor is int
Its work..! THANK YOU
Can the number of transmitters be increased?
You can use multiple transmitter bit assign them the unique address to identify each nodes.
How can we do object tracking by using GY-NEO6MV2 GPS module instead of DHT11 module?
Can esp8266 & nrf24l01 be used to make a remote for drones or car? I am having trouble can any one recomment me useful guide. I am having hardtime
Hello.
I want to implement a Wi-Fi TCP-IP network based on the esp8266+ nrf24l01<>nrf24l01+esp8266 scheme. Please advise if this is technically possible and if I should continue to study the issue.