Wireless PIR Sensor Alarm

by MisloElectronics in Circuits > Arduino

23982 Views, 100 Favorites, 0 Comments

Wireless PIR Sensor Alarm

wireless pir.jpg
wireless pir3.jpg
wireless pir2.jpg

This is a simple wireless PIR sensor alarm.The device consists of two parts.One is a transmitter that contains PIR sensor and a transmitter module.A second receiver consisting receiving module and piezo speaker. Test your PIR sensor before you made this with any code from internet.

Parts

Uno_Protoboard.jpg
piezo.jpg
PIR.jpg
rf 433.JPG
433 MHz Module.jpg

You need:

1. Two arduinos any version

2. PIR sensor

3. Piezo speaker

4: RF 433MHz or 315 MHz module

5. 10Kohm resistor

Transmitter

TX.jpg
TX schematic.png

This is code of transmitter. When PIR sensor detects human movement transmitter sends uppercase letter A. When pir sensor it holds no signal transmitter sends lowercase letter a.

int pirPin = 2;
int statePir = 0;

#include <VirtualWire.h>

void setup(){

Serial.begin(9600);

vw_setup(2000);

vw_set_tx_pin(3);

pinMode(pirPin,INPUT);

}

void loop(){

statePir = digitalRead(pirPin);

if (statePir == HIGH){

const char *msg = "A";

vw_send((uint8_t *)msg, strlen(msg));

vw_wait_tx();

}

if (statePir == LOW){

const char *msg = "a";

vw_send((uint8_t *)msg, strlen(msg));

vw_wait_tx();

}

}

Receiver

RX.jpg
RX Schematic.png

Here is the code for receiver. Piezo play very loud alarm sound.

int led = 13;
int speaker = 10;

#define wait 1

#define time 100

int freq = 0;

#include

void setup(){

Serial.begin(9600); // Debugging only

vw_setup(2000);
vw_set_rx_pin(11);

vw_rx_start();

pinMode(speaker, OUTPUT);
pinMode(led, OUTPUT);

}

void loop(){

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen))
{

for (int i = 0; i < buflen; i++)

{

if(buf[i] == 'A') {

digitalWrite(led, 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(buf[i] == 'a')

{ digitalWrite(led, LOW); digitalWrite(speaker, LOW);

}

}

}

}

Library

For this project you need VirtualWire libraries. In the link below have all the files needed for this project. In video see how this work.