🛠 Nœud capteur sans fil : nRF24L01+ sur le bus SPI

Arduino Pro Mini · avance · Schéma : IMG-pro-mini-avance-8-promini-node-sans-fil.svg — Arduino Pro Mini 3,3 V pilotant un module nRF24L01+ via le bus SPI (broches 10 SS, 11 MOSI, 12 MISO, 13 SCK), condensateur de découplage sur l'alimentation du module, debug série via SoftwareSerial

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials