Robin2:
It may be a typo, but that bit in bold is silly. I believe you mean "Tx code for the slave". Computer programming only works when you are very precise.
It was a typing mistake by me sorry for that, i am going now with the "simple one way transmission" example making slave to transmit and master to receive and thinking of adding adding slave addresses in the master
// SimpleTx - the slave or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
int buttonInput = 2;
int pir1;
const byte slaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char pirData[5]="ON 0";
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 250; // send once per second
void setup() {
Serial.begin(9600);
Serial.println("SimpleTx Starting");
pinMode(buttonInput,INPUT_PULLUP);
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
}
//====================
void loop() {
pir1=digitalRead(buttonInput);
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
}
//====================
void send() {
bool rslt1;
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
pirTest();
rslt1 = radio.write( &pirData, sizeof(pirData) );
if (rslt1) {
Serial.println(" Acknowledge received");
updateMessage();
}
else {
Serial.println(" Tx failed");
}
}
//================
void updateMessage() {
// so you can see that new data is being sent
}
void pirTest()
{
if(pir1 == HIGH)
{
Serial.println("PIR 1");
strncpy(pirData, "ON 1", 5);
}
else if(pir1 == LOW)
{
Serial.println("PIR LOW");
strncpy(pirData, "ON 0", 5);
}
}
the master code
// SimpleRx - the master or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
char pirDataReceived[5];
bool newData = false;
//===========
void setup() {
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
//=============
void loop() {
getData();
showData();
}
//==============
void getData() {
if ( radio.available() ) {
radio.read( &pirDataReceived, sizeof(pirDataReceived) );
newData = true;
}
}
void showData() {
if (newData == true) {
Serial.println("Pir data ");
Serial.println(pirDataReceived);
call();
newData = false;
}
}
void call()
{
if(strcmp(pirDataReceived,"ON 1")==0)
{
Serial.println("Led On");
}
else if(strcmp(pirDataReceived,"ON 0")==0)
{
Serial.println("Led Off");
}
}
in the slave code i tried with powerUp and powerDown function to start sending data when PIR == HIGH
but couldn't get any success.