Wireless motion sensor using 3 nodes (NRF24L01+)

My Project: I am trying to use a PIR sensor to detect motion outside at one end of my property, then send a signal using the NRF24L01+ to a relay station, and then from the Relay to a base station in my house at the other end of the property. I have been using How To Mechatronics video as the base of my coding for the different nodes (How To Build an Arduino Wireless Network with Multiple NRF24L01 Modules - YouTube). But I do not think I am getting the network established correctly or I am not sending and receiving correctly. I am very new to using the NRF24 in a network setting and I have been stuck on this for a week or so now. I could really use some guidance.

My Setup: I have three nano’s currently. One at the Base(node 00), one at the Relay(node01), and one at the Sensor(node011). See code and basic setup visual below. The base end has three LED’s and a buzzer. The Relay just has an NRF24. And the Senor has a HC-SR501 PIR sensor and an LED

My Problem: I cannot get communication established between all three nodes. The motion sensor will still detect and light up a LED. However, I cannot get the signal to flow and light up the LEDs at the base node. Any insight to my issue would be greatly appreciated.

Base code(node 00):

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

int Loading = 2;
int Ready = 3;
int Alarm = 4;

const int buzzer = 5;

bool Motion = 0;
unsigned long SensData = 0;

RF24 radio(7,8);                 
RF24Network network(radio);      
const uint16_t this_node = 00;   
const uint16_t Relay = 01;      
const uint16_t Sensor = 011;

void setup() {
  SPI.begin();
  radio.begin();
  network.begin(90, this_node);  
  radio.setDataRate(RF24_2MBPS);

  pinMode(buzzer, OUTPUT);
  pinMode(Loading, OUTPUT);
  pinMode(Ready, OUTPUT);
  pinMode(Alarm, OUTPUT);

  digitalWrite(Loading, HIGH);
  delay(3000);
  digitalWrite(Ready, HIGH);
  delay(3000);
  digitalWrite(Loading, LOW);
}
void loop() {
   network.update();
  //===== Receiving =====//
  while ( network.available() ) {    
    RF24NetworkHeader header;
    unsigned long SensData;
    network.read(header, &SensData, sizeof(SensData)); 
    Motion = SensData;
    if (Motion == 1) {
        digitalWrite(Ready, LOW);
        //delay(500);
        digitalWrite(Alarm, HIGH);
        delay(500);
        tone(buzzer, 500);
        delay(1000);
        noTone(buzzer);
        delay(500);
        digitalWrite(Alarm, LOW);
        Motion = 0;
        digitalWrite(Loading, HIGH);
        delay(4000);
        digitalWrite(Loading, LOW);
        digitalWrite(Ready, HIGH);
        delay(5);
  }
  else (delay(5));{}
  }
  
}

Relay code (node01):

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(7,8);               
RF24Network network(radio);      
const uint16_t this_node = 01;   
const uint16_t Base = 00;    


void setup() {
  SPI.begin();
  radio.begin();
  network.begin(90, this_node); 
  radio.setDataRate(RF24_2MBPS);
}
void loop() {
  network.update();
  //===== Sending =====//
}

Sensor Code (node011);

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

int Sensor = 5;
unsigned long SensData = 0;
int LED = 3;

RF24 radio(7,8);               
RF24Network network(radio);      
const uint16_t this_node = 011;  
const uint16_t Base = 00;    

void setup() {
  SPI.begin();
  radio.begin();
  network.begin(90, this_node);  
  radio.setDataRate(RF24_2MBPS);

  pinMode(Sensor, INPUT);
  pinMode(LED, OUTPUT);

  digitalWrite(LED, HIGH);
  delay(60000);
  digitalWrite(LED, LOW);
}
void loop() {
  unsigned long SensData = digitalRead(Sensor);
   if (SensData == HIGH) {
    digitalWrite(LED, HIGH);
    delay(2000);
    digitalWrite(LED, LOW);
    delay(4005);
}

  network.update();
  //===== Sendinging =====//
  while ( network.available() ) {    
    
  RF24NetworkHeader header(Base);    
  network.write(header, &SensData, sizeof(SensData));   
    
}

}

It's not clear to me whether you have any successful communication between your nRF24s. If not then I suggest you start with the first example in this Simple nRF24L01+ Tutorial

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin - especially with a nano. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

I don't have any personal experience with the Network library. If this was my problem I think I would just program the man-in-the-middle to receive data from the first Arduino and send it to the third Arduino. Another possibility might be to use a high-power nRF24 module (with external antenna) which may have the range to go all the way.

...R

Hello, I have a project that I want to develop with the same logic. so did you realize your project? If you have made it or made progress, we can help each other and if you wish. I recently started such a topic. Gateway or Routing Operation using NRF24 - #3 by juliabellan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.