Impossible wireless communication using NRF24L01 + PA + LNA

Hi everyone i'm trying to do something that I thought would be simpler but it's turning out to be a real head-scratcher. I need to make two Arduino Mini Pro boards communicate with each other using 2 NRF24L01 + PA + LNA modules to control a MOSFET, but for now, an LED will suffice. Now, I've searched the forum and none of the suggested solutions have worked. I'm attaching the transmitter and receiver codes and I'm relying on you to solve the problem. I anticipate that in this configuration I've had intermittent success, meaning it worked for short periods and then stopped working multiple times.

receiver code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;  // Lo stesso pipe del trasmettitore
RF24 radio(CE_PIN, CSN_PIN);  // Oggetto per la comunicazione RF

byte datatoreceive = 0;  // Dato ricevuto
const int ledPin = 7;    // LED collegato al pin 7
unsigned long lastReceiveTime = 0; // Ultimo momento in cui sono arrivati dati
const unsigned long timeout = 2000; // Timeout di 2 secondi

void setup() {
  Serial.begin(9600);  // Inizializza la comunicazione seriale
  radio.begin();
  radio.setPALevel(RF24_PA_HIGH);  // Imposta la potenza di trasmissione
  radio.openReadingPipe(1, pipe);  // Imposta il pipe di lettura
  radio.startListening();  // Inizia ad ascoltare i dati
  pinMode(ledPin, OUTPUT); // Configura il pin del LED come OUTPUT
  digitalWrite(ledPin, LOW); // Spegne il LED all'inizio
  Serial.println("Ricevitore pronto!");
}

void loop() {
  if (radio.available()) {  // Se ci sono dati disponibili
    radio.read(&datatoreceive, sizeof(datatoreceive));  // Leggi i dati ricevuti
    lastReceiveTime = millis();  // Aggiorna il tempo dell'ultimo dato ricevuto
    Serial.print("Dati ricevuti: ");
    Serial.println(datatoreceive);  // Mostra il dato ricevuto

    // Controlla lo stato dell'interruttore e accendi/spegni il LED
    if (datatoreceive == 1) {
      Serial.println("Interruttore chiuso - LED acceso");
      digitalWrite(ledPin, HIGH); // Accendi il LED
    } else if (datatoreceive == 0) {
      Serial.println("Interruttore aperto - LED spento");
      digitalWrite(ledPin, LOW); // Spegni il LED
    } else {
      Serial.println("Dati non validi ricevuti");
    }
  } else if (millis() - lastReceiveTime > timeout) {
    // Se non riceviamo dati per un certo tempo
    Serial.println("Comunicazione persa. Nessun dato ricevuto.");
    digitalWrite(ledPin, LOW); // Spegni il LED come fallback
  }
}


Transmitter code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;  // Pipe per la trasmissione
RF24 radio(CE_PIN, CSN_PIN);          // Oggetto per la comunicazione RF

const int buttonPin = 2;              // Pulsante collegato al pin 2
byte datatosend = 0;                  // Dato da inviare
byte lastState = 255;                 // Stato precedente del pulsante

void setup() {
  Serial.begin(9600);                 // Inizializza la comunicazione seriale
  pinMode(buttonPin, INPUT_PULLUP);   // Configura il pin del pulsante con resistenza interna
  radio.begin();
  radio.setPALevel(RF24_PA_HIGH);     // Imposta la potenza di trasmissione
  radio.openWritingPipe(pipe);        // Imposta il pipe di scrittura
  radio.stopListening();              // Imposta il modulo come trasmettitore
  Serial.println("Trasmettitore pronto!");
}

void loop() {
  // Leggi lo stato del pulsante (inverso perchΓ© Γ¨ in pull-up)
  byte buttonState = digitalRead(buttonPin) == LOW ? 1 : 0;

  // Invia il dato solo se lo stato Γ¨ cambiato
  if (buttonState != lastState) {
    lastState = buttonState;          // Aggiorna lo stato precedente
    datatosend = buttonState;         // Aggiorna il dato da inviare

    // Invia il dato
    bool success = radio.write(&datatosend, sizeof(datatosend));
    if (success) {
      Serial.print("Dati inviati: ");
      Serial.println(datatosend);
    } else {
      Serial.println("Errore nella trasmissione!");
    }
  }
  delay(100); // Piccola pausa per evitare rimbalzi eccessivi
}

the pinout is the same on both arduinos. The led on the receiver is on pin 7 and the switch on the transmitter is on pin 2

VCC β†’ 3.3V
GND β†’ GND
CE β†’ Pin 9
CSN β†’ Pin 10
SCK β†’ Pin 13
MISO β†’ Pin 12 (
MOSI β†’ Pin 1

I suspect one of your issues will be because you are using the 3v3 output of your Arduino to power the nRF24L01+PA+LNA. Your radio module likely requires more power than your Arduino can supply.

2 Likes

Power Stability Issues with RF24 Radio Modules

As described in the RF24 Common Issues Guide, radio modules, especially the PA+LNA versions, are highly reliant on a stable power source. The 3.3V output from Arduino is not stable enough for these modules in many applications. While they may work with an inadequate power supply, you may experience lost packets or reduced reception compared to modules powered by a more stable source.

Symptoms of Power Issues:

  • Radio module performance may improve when touched, indicating power stability issues.
  • These issues are often caused by the absence of a capacitor, a common cost-saving omission by some manufacturers.

Temporary Patch :

  • Add Capacitors: Place capacitors close to the VCC and GND pins of the radio module. A 10uF capacitor is usually sufficient, but the exact value can depend on your circuit layout.
  • Use Low ESR Capacitors: Capacitors with low Equivalent Series Resistance (ESR) are recommended, as they provide better power stability and performance.

Adding the appropriate capacitors can greatly improve the reliability of your RF24 module by ensuring a stable power supply, thus minimizing packet loss and enhancing overall performance. A separate power supply for the radios is the best solution.

==> Before Posting

Before posting your code and schematic, please review the forum guidelines and use code tags to ensure clarity. Additionally, include links to the technical information for your hardware and provide a preliminary schematic that shows all power, ground, and power sources.

Important Notes: How to get the best out of this forum

1 Like