The Mega makes a good “base station” for a wireless sensor network: it has the pins for an LCD, an SD card and an Ethernet or GSM link alongside the radio. The nRF24L01+ wires to the Mega’s SPI pins 50–52, with CE on 48 and CSN on 53.
The sketch opens five reading pipes, one per node, and prints which node sent each value. Pair it with Nano or Pro Mini nodes that send a reading every few seconds.
Wiring
| Arduino Mega 2560 | nRF24L01+ 2.4 GHz transceiver | Wire | Notes |
|---|---|---|---|
| GND | GND | black | |
| 3.3V | VCC | red | Basic module only, with 10 µF across VCC/GND at the radio. PA+LNA modules need their own 3.3 V regulator. |
| D48 | CE | orange | |
| D53 | CSN | purple | |
| D52 | SCK | yellow | |
| D51 | MOSI | green | |
| D50 | MISO | blue |
1.9–3.6 V — use 3.3 V part, 5 V board. VCC must be 3.3 V: 5 V destroys it. The signal inputs are 5 V tolerant, so an Uno can drive SCK, MOSI, CSN and CE directly; MISO is a 3.3 V output that every board reads fine.
Board quirks
- SPI on the Mega: 50 MISO, 51 MOSI, 52 SCK. CSN on 53 also keeps the SS pin an output, which SPI master mode needs.
- The Mega’s 3.3V pin is a real regulator (about 50 mA) — enough for a basic nRF24L01+ with a capacitor, unlike a CH340 Nano’s 3V3.
- One radio listens on up to six pipes. Pipes 2–5 may only differ from pipe 1 in the first byte of the address — “NODE1” … “NODE5” follows that rule.
- Each node runs the transmitter side of the Nano nRF24 guide with its own address and the same channel, data rate and payload size.
Code
// nRF24L01+ on an Arduino Mega 2560 as a base station that listens to up to 5 sensor nodes.
// CE → D48, CSN → D53, SCK → D52, MOSI → D51, MISO → D50, VCC → 3.3V (10 µF at the radio), GND.
// Each node sends a 4-byte value on its own address: "NODE1" ... "NODE5".
#include <SPI.h>
#include <RF24.h>
RF24 radio(48, 53); // CE, CSN
const uint8_t ADDR[5][6] = {"NODE1", "NODE2", "NODE3", "NODE4", "NODE5"};
void setup() {
Serial.begin(115200);
if (!radio.begin() || !radio.isChipConnected()) {
Serial.println(F("nRF24 not responding - check 3.3V and pins 48/50-53"));
for (;;) {}
}
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(108);
radio.setPayloadSize(sizeof(long));
for (uint8_t i = 0; i < 5; i++) radio.openReadingPipe(i + 1, ADDR[i]); // pipes 1-5
radio.startListening();
Serial.println(F("Base station listening on pipes 1-5"));
}
void loop() {
uint8_t pipe;
if (radio.available(&pipe)) {
long value;
radio.read(&value, sizeof(value));
Serial.print(F("Node "));
Serial.print(pipe);
Serial.print(F(": "));
Serial.println(value);
}
}// nRF24L01+ on an Arduino Mega 2560 as a base station that listens to up to 5 sensor nodes.
// CE → D48, CSN → D53, SCK → D52, MOSI → D51, MISO → D50, VCC → 3.3V (10 µF at the radio), GND.
// Each node sends a 4-byte value on its own address: "NODE1" ... "NODE5".
#include <SPI.h>
#include <RF24.h>
RF24 radio(48, 53); // CE, CSN
const uint8_t ADDR[5][6] = {"NODE1", "NODE2", "NODE3", "NODE4", "NODE5"};
void setup() {
Serial.begin(115200);
if (!radio.begin() || !radio.isChipConnected()) {
Serial.println(F("nRF24 not responding - check 3.3V and pins 48/50-53"));
for (;;) {}
}
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(108);
radio.setPayloadSize(sizeof(long));
for (uint8_t i = 0; i < 5; i++) radio.openReadingPipe(i + 1, ADDR[i]); // pipes 1-5
radio.startListening();
Serial.println(F("Base station listening on pipes 1-5"));
}
void loop() {
uint8_t pipe;
if (radio.available(&pipe)) {
long value;
radio.read(&value, sizeof(value));
Serial.print(F("Node "));
Serial.print(pipe);
Serial.print(F(": "));
Serial.println(value);
}
}Library: RF24 (TMRh20) — compiled with RF24 1.6.2.
Expected serial output
Base station listening on pipes 1-5
Node 1: 2741
Node 3: 1198Base station listening on pipes 1-5 Node 1: 2741 Node 3: 1198
Common errors
nRF24 not responding
SPI on 11–13 (Uno habit) or VCC on 5V. Full fix.
Only node 1 is heard
Other nodes’ addresses differ in more than the first byte, or their payload size doesn’t match.