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));
}
}