Help - NRF24L01 Random Receivings/ No Show

Hi friends,

I am new to arduino, have done a bit of programming in the past. Decided to seek help after 2 complete days of trying.

I have setup 2 nodes. 2 Nano units, 2 PIR sensors and 2 NRF24L01 transceivers (10uF capacitor connected to first 2 pins) and 4 LEDs. [two identical nodes, Base node (ID=44, 54 in Octal) and Child node (ID=22, 26 in Octal)]
PIR sensors are powered by 5V and transceivers are powered by 3.3V from breadboard power supply with capacitor in parallel (not by pin 3V3).

CE 9, CSN 10, SCK 13, MOSI 11, MISO12

This is a gradual learning/progressing project, and the current phase is used to do the following:

Part 1:
Child Node: PIR sensor will detect a motion and when it does, its Nano unit receives the signal (pin D2), powers up an LED (pin D4) and transmits the sensor output (integer 1) to the Base node.

Base Node: Transceiver receives the signal from the Child node, updates it's respective Nano board, powers up an LED when it receives (pin D6).

Part 2: (identical to Part 1, works in opposite direction)
Base Node: PIR sensor will detect a motion and when it does, its Nano unit receives the signal (pin D2), powers up an LED (pin D4) and transmits the sensor output (integer 1) to the Child node.

Child Node: Transceiver receives the signal from the Base node, updates it's respective Nano board, powers up an LED when it receives (pin D6).

Now the results:
Good ones:
Both PIR sensors do detect and both respective LED's light up when it happens.
Serial plotter also shows the sensor results correctly.

Bad ones:
Child node doesn't seem to receive/post any input.
Base node, posted random values as received a few times. But no result when the child node is sending.

Further observations:
Child node: Nano board's onboard Tx LED blinks when the PIR sensor is active, and stops when its inactive. L remains the same.
Base node: Nano board's onboard L LED blinks so fast and Tx stays on while the PIR sensor is active. Both stop when its inactive.

Base node code:


#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
#define led1 6
#define led2 4

RF24 radio(9, 10);                                                        // nRF24L01 (CE,CSN)
RF24Network network(radio);                                     // Include the radio in the network
const uint16_t this_node = 54;                                  // Node ID 44, in octal is 54
const uint16_t node00 = 26;                                     // Node ID 22, in octal is 26  
int pirSensor = 2;                                                          //pin D2

void setup() {

  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  pinMode(pirSensor,INPUT);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  network.begin(this_node);                                     //(node address)
  radio.setDataRate(RF24_2MBPS);
}//setup


void loop() {
  network.update();
  
//----------------------------------------------RECEIVING------------------------------------------------------//


  while ( network.available() )                                  // Is there any incoming data?
  {

    RF24NetworkHeader header;
    int incomingData = 0;
    network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data

    if (incomingData != 0 )
    {
      digitalWrite(led1,HIGH);
      Serial.print("receiving from child node: ");
      Serial.println(incomingData);
    }//if   
    
    else{
      digitalWrite(led1,LOW);
    } 
     
  }//while
  
         
   //-------------------------------------------------SENDING------------------------------------------------//

   int sensorValue = digitalRead(pirSensor);                                 //read PIR sensor output

  if(sensorValue == 1)                                                      //if PIR sensor detects, it sends 1. 
  { 
    RF24NetworkHeader header(node00);                                       // (Address where the data is going)
    bool ok = network.write(header, &sensorValue, sizeof(sensorValue));     // Send the data
    digitalWrite(led2,HIGH);
    Serial.print("sending from base node: ");
    Serial.println(sensorValue);
  }//if
 if(sensorValue == 0 ){
    digitalWrite(led2,LOW);
    }


}//loop

Child node code:


#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
#define led1 4
#define led2 6

RF24 radio(9, 10);               // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 26;   // Node ID 22, in octal is 26  
const uint16_t node01 = 54;      // Node ID 44, in octal is 54
int pirSensor = 2;                //pin D2


void setup() {
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  pinMode(pirSensor,INPUT);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  network.begin(this_node);                                                 //(node address)
  radio.setDataRate(RF24_2MBPS);
}

void loop() {
 
  network.update();                                                         //first line in keeping up with the network

//---------------------------------------------RECEIVING-------------------------------------------//

  while ( network.available() )                                  // Is there any incoming data?
  {
    RF24NetworkHeader header;
    unsigned long incomingData;
    network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data

    if (incomingData != 0 )
    {
      digitalWrite(led2,HIGH);
      Serial.print("receiving from base node: ");
      Serial.println(incomingData);
    }//if
    else{
      digitalWrite(led2,LOW);
    }   
  }//while


  //-------------------------------------------SENDING-------------------------------------------------//
  int sensorValue = digitalRead(pirSensor);                                 //read PIR sensor output

  if(sensorValue == 1)                                                      //if PIR sensor detects, it sends 1. 
  { 
    RF24NetworkHeader header(node01);                                       // (Address where the data is going)
    bool ok = network.write(header, &sensorValue, sizeof(sensorValue));     // Send the data
    digitalWrite(led1,HIGH);
    Serial.print("sending from child node: ");
    Serial.println(sensorValue);
    
  }//if

 if(sensorValue == 0 ){
    digitalWrite(led1,LOW);
    }

}//loop


Hi kuseetha welcome to the arduino user-forum,

did you do a test if your nRF24-modules are working with a demo-code that is well know for working? Anything that goes beyond a simple LED should be first tested with a working demo-code.

Robin2 has some demo-codes

best regards Stefan

Hi Stefan,

Thank you for the tip. I tried Robin2's simple demo and the outputs were erratic, maybe there are hardware faults, loose connections etc, that needs looking in to.
I will re-try the code once these basic issues are sorted out and report the findings.

Cheers,
Kuseetha

If you read and, closely, follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me.

There is a sketch in reply #30 of Robin2's simple rf24 tutorial that will test the physical wiring connections between the radio and the Arduino to which the radio is connected.

Some other things to look at:

Make sure the rf24 power supply can provide enough current. This is especially true for the high power (external antenna) modules. I use homemade adapters like these. They are powered by 5V and have a 3.3V regulator on the board. Robin2 also has suggested trying with a 2 AA cell battery pack.

If using the high powered radios make sure to separate them by a few meters. They may not work too close together. Try the lower power settings.

Reset the radios by cycling power to them after uploading new code. I have found that to help. They do not reset with the Arduino.

Switch to 1MB data rate to catch the not so cloned clones.
radio.setDataRate( RF24_1MBPS );