THIEF ALARM RCWL-RF24

TRANSMITTER

RCWL RF24

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/THIEF%20ALARM.zip

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int ip = 2;
int val = 0;
int DataMsg[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F482LL;

void setup()
{
pinMode(ip,INPUT);
Serial.begin(9600);
Serial.println(“NRF24L01 Transmitter”);
radio.begin();
radio.openWritingPipe(pipe);
}

void loop()
{
val = digitalRead(ip);
if (val == HIGH)
{
DataMsg[0] = 1;
radio.write(DataMsg, 1);
}
if (val == LOW)
{
DataMsg[0] = 2;
radio.write(DataMsg, 1);
}
}

RECEIVER

PIR recv

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

int DataMgs[1];
RF24 radio(8,7);
const uint64_t pipe = 0xE14BC8F482LL;
int Relay1 = 5;
int speaker = 10;
#define wait 1
#define time 100
int freq = 0;
void setup()
{
pinMode(Relay1, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(speaker, OUTPUT);
}

void loop()
{
if (radio.available())
{
bool done = false;
while (!done)
{
done = radio.read(DataMgs, 1);
Serial.print(“NRF24L01 Receiver: “);
Serial.println(DataMgs[0]);

if (DataMgs[0] == 1)
{
digitalWrite(Relay1, HIGH);
digitalWrite(speaker, HIGH);
for (freq = 500; freq < 3000; freq += 10)
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 3000; freq > 500; freq -= 10)
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 500;
freq < 3000;
freq += 10) //
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 3000;
freq > 500; freq -= 10)
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 500;
freq < 3000;
freq += 10) //
{
tone(speaker,
freq, time);
delay(wait);
}
for (freq = 3000;
freq > 500;
freq -= 10)
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 500; freq < 3000; freq += 10)
{
tone(speaker, freq, time);
delay(wait);
}
for (freq = 3000;
freq > 500; freq -= 10)
{
tone(speaker, freq, time);
delay(wait);
}

}

if (DataMgs[0] == 2)
{
digitalWrite(Relay1, LOW);
digitalWrite(speaker, LOW);

}
delay(100);
}
}
else
{
Serial.println(“Waiting for signal…”);
}
}