Hey, people, I have a problem with my project
I want to create a home security system and I'm coming to a problem where my Arduino does not receive data from the other two nrf2401 transmitters
Heres the code of my receiver:
#include<RF24.h>
#include<SPI.h>
RF24 radio(9, 10);
byte address[][6] = {"0"};
//second reciever
RF24 radio1(9, 10);
byte address1[][6] = {"1"};
void checkForWirelessData();
void checkForWirlessDatasecond();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.setChannel(124);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,address[0]);
radio.startListening();
radio1.begin();
radio1.setChannel(123);
radio1.setPALevel(RF24_PA_MAX);
radio1.setDataRate(RF24_250KBPS);
radio1.openReadingPipe(1,address[0]);
radio1.startListening();
}
void loop() {
// put your main code here, to run repeatedly:
void checkForWirelessData();
void checkForWirlessDatasecond();
}
void checkForWirelessData(){
char data;
if(radio.available()){
while(radio.available()){
radio.read(&data, sizeof(data));
if(data == 11){
Serial.println("Motion Detected At Kitchen");
}
}
}
}
void checkForWirelessDatasecond(){
char data2;
if(radio1.available()){
while(radio1.available()){
radio1.read(&data2, sizeof(data2));
if(data2 == 11){
Serial.println("Motion Detected At Bathroom");
}
}}}
and my first transmitter:
#include <SPI.h>
#include<RF24.h>
int stabilize = 30;
int pirState ;
RF24 radio(9, 10);
byte address[][6] = {"1"};
int PIRpin = 3;
int val;
void setup() {
// put your setup code here, to run once:
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(123);
radio.openWritingPipe(address[0]);
radio.stopListening();
pinMode(PIRpin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
readSensor();
radio.write(&val, sizeof(val));
delay(1000);
}
void readSensor(){
int message[1]= {00};
val = digitalRead(PIRpin);
if(val==HIGH){
if(pirState == LOW){
message[0] = 00;
radio.write(message,1);
pirState = HIGH;
}
}else if(pirState == HIGH){
message[0] = 11;
radio.write(message,1);
pirState = LOW;
}
}
and second with only a small change:
#include <SPI.h>
#include<RF24.h>
int stabilize = 30;
int pirState ;
RF24 radio(9, 10);
byte address[][6] = {"0"};
int PIRpin = 3;
int val;
void setup() {
// put your setup code here, to run once:
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(124); //over here
radio.openWritingPipe(address[0]);
radio.stopListening();
pinMode(PIRpin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
readSensor();
radio.write(&val, sizeof(val));
delay(1000);
}
void readSensor(){
int message[1]= {00};
val = digitalRead(PIRpin);
if(val==HIGH){
if(pirState == LOW){
message[0] = 00;
radio.write(message,1);
pirState = HIGH;
}
}else if(pirState == HIGH){
message[0] = 11;
radio.write(message,1);
pirState = LOW;
}
}
PIRMotionTransmitter2.0.ino (948 Bytes)
PIRMotionTransmitterSecond2.ino (948 Bytes)
PIRMotionReciever2.0.ino (1.45 KB)