🛠 Nœud capteur sans fil : nRF24L01+ sur le bus SPI
Objectives
Build the iconic Pro Mini setup: a battery-powered sensor node with an nRF24L01+ radio — the architecture historically deployed by the MySensors library on Pro Mini + nRF24L01+. We wire the module to the hardware SPI bus (10 SS, 11 MOSI, 12 MISO, 13 SCK), reserve two pins for software serial debugging (SoftwareSerial works on any digital pin since the single hardware UART is used by the programmer), and carefully manage the module's power supply.
Hardware
- 1 × Arduino Pro Mini 3.3 V/8 MHz (recommended: the nRF24L01+ is a 3.3 V max component)
- 1 × nRF24L01+ module (6 or 8-pin break-out)
- 1 × 10-100 µF electrolytic capacitor for decoupling, placed directly on the module's VCC/GND
- Power supply: 3.7 V LiPo on RAW (≤ 12 VDC via the onboard linear regulator) or external regulated 3.3 V on VCC
- RF24 library (or MySensors); a second module on the PC/gateway side for testing
- >
Complete Code
// Reception nRF24L01+ via SPI materiel (13 SCK / 12 MISO / 11 MOSI)
#include <SPI.h>
#include <RF24.h>
#include <SoftwareSerial.h>
RF24 radio(9, 8); // CE=9, CSN=8 (libres de SPI)
SoftwareSerial dbg(6, 7); // debug serie sans occuper D0/D1
const uint64_t PIPE = 0xF0F0F0F0E1LL;
void setup {
dbg.begin(9600);
radio.begin;
radio.openReadingPipe(1, PIPE);
radio.setChannel(100);
radio.setDataRate(RF24_1MBPS); // 1 Mbps plus robuste a 3,3 V
radio.setPALevel(RF24_PA_LOW); // puissance mini : menage la pile
radio.startListening;
dbg.println(F("noeud pret, ecoute..."));
}
void loop {
if (radio.available) {
char buf[32] = {0};
radio.read(buf, sizeof(buf) - 1);
dbg.print(F("msg: ")); dbg.println(buf);
}
}
Expected Verification
The transmitter module (another Pro Mini or USB gateway) sends a message every second; the node displays it on the SoftwareSerial link at 9600 bauds, leaving the hardware UART free for uploading via the 6-pin connector. Without the decoupling capacitor, random packet losses or resets occur during transmission — restoring the capacitor makes the failures disappear, proving its role.
Common Errors
- Powering the nRF24L01+ with 5 V: the module is 3.3 V max; many "break-out" modules have no regulator and die instantly.
- Forgetting the decoupling capacitor: transmission peaks cause voltage drops, silently resetting the nRF — a classic symptom of packets lost in bursts.
- Moving SCK/MISO/MOSI to other pins: the ATmega328P's hardware SPI is fixed at 13 SCK, 12 MISO, 11 MOSI (and 10 SS); only CE and CSN are free.
- Using Serial (D0/D1) for debugging and suffering collisions with the programming port's auto-reset: the single UART is already dedicated to the 6-pin connector — hence SoftwareSerial.
- Powering RAW with > 12 V: the onboard linear regulator dissipates the difference as heat (12 V → 3.3 V = 8.7 V burned); on LiPo, stay below 12 V and limit radio power.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinopwm-fade.inoArduinocapteur-lumiere-ldr.inoArduinoservo-balayage.inoArduinoruban-neopixel.inoArduino