THIEF ALARM WITH PIR SENSOR AND RF24

The code can be downloaded at:

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

for alternative we can use RCWL module instead of PIR sensor, see on https://arduinoproyek.wordpress.com/thief-alarm-rcwl-rf24/

TRANSMITTER

PIR trans

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

int pirPin = 2;

int statePir = 0;

int DataMsg[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F482LL;

void setup()

{

pinMode(pirPin,INPUT);

Serial.begin(9600);

Serial.println(“NRF24L01 Transmitter”);

radio.begin();

radio.openWritingPipe(pipe);

}

void loop()

{

statePir = digitalRead(pirPin);

if (statePir == HIGH)

{

DataMsg[0] = 1;

radio.write(DataMsg, 1);

}

if (statePir == 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…”);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s