Instructables
I think we all have the dream to became a super spy, so if you are in a secret mission, you are doing something in your house and you don't want to get caught, our you are just eating all the cookies in the kitchen and you want to know if your mother is coming, the wireless motion sensor devices are for you.

I see a lot of wireless in de web and in movies, but i want to figure out the way to make it cheap for everyone so I use an attiny85, a pir sensor (motion sensor)  and a rf link to make the project work.
 
Remove these adsRemove these ads by Signing Up

Step 1: Material

I order my material from a sparkfun distribution in México because is where i live but if you live in USA you can order barely all the material from sparkfun.

1 pir sensor

http://www.sparkfun.com/products/8630

9.95 dolar


1 rf receiver 315mhz

http://www.sparkfun.com/products/10533

4.95 dolar


1 rf transmiter 315mhz

http://www.sparkfun.com/products/10535

3.95 dolar


1 attiny85

http://www.sparkfun.com/products/9378

2.84 dolar


1 arduino uno


1 switch

4 resistance 180ohm

1 resistance 10k ohm

normally open button (optional)

1 8 ohm speaker (optional)

1 ic 8 pin base

1pnp transistor ( you can use the 2n2222, just check out the collector and emitter pins are in the right place)

1 lm7805 (5v regulator)

3 electrolitic capacitors 10uf 50v

Step 2: Hardware

Picture of Hardware
transmitter.bmp
conections in protoboard.png
As you can see in the image everything in the circuits works with 5Volts but the pir sensor works with 9 to 12 volts. To fix this and save the work and spend of connecting the circuits to 2 different kind of voltage i use a lm7805, that is a 5Volts regulator, and connect everything to a 9V(square) battery.

If you want to make a pcb to have all the connections in a cleaner way I will put a pdf file below so you can print it and transfer with the method you want.

2 connection do not fit in the design so y place them with wires. (the two connections are the yellow ones in the second image)

For the receiver I was going to do also a attiny85 device, but I was short in time so I end up making an arduino shield with a speaker.  (If somebody want the pcb for the attiny85 receiver I'm in half production and I will upload it later. thanks for the comprehension).

If you print the arduino receiver shield you got to be careful, the bottom copper side ends up in the top, also the pins are place in the bottom and solder though the holes in the pcb, but all the other component are solder from the upper part directly bending the legs. you can have a better look in  the 5 to 8 images.

Step 3: Software

Picture of Software
To program the attiny85 you can use the arduino uno as isp programmer. You can look this link (http://hlt.media.mit.edu/?p=1706) for more information about this procces, but you dont need to because im gonna explain everything in detail. 

I use a attiny because is cheaper than use an arduino. you can buy a attiny85 for 2.84USD, compare to an arduino for about 38 dolars. Using an attiny to comunicate through a rf link represent a chalenge  because the attiny doesn't have a rx or tx serial comunication by default. I want to thanks this blog (http://mchr3k-arduino.blogspot.mx/) for make the program that make possible to comunicate with an attiny.

ok. so let go to step by step programing.

1. go to the arduino oficial site and download the arduino-0022 software. (don't use the arduino 1.0, it doesn't work). Unzip the file. you should see a folder name arduino-0022.

2. go to this link.

http://mchr3k-arduino.blogspot.mx/2012/01/wireless-sensor-node-part-2.html?showComment=1338749638806#c853067277980266192

download the attiny45_85.zip and the manchester.zip files. 

3. Unzip the attiny45_85.zip file. copy the folder. 
open the arduino-0022 folder. Open hardware and paste the attiny45_85 folder there.

4.Unzip the manchester.zip file. open that manchester folder and you should see two other folders. core and MANCHESTER.
copy de MANCHESTER folder.
open again the arduino-0022 folder. but this time open the libraries folder. paste the MANCHESTER folder there.

Now you have the software ready to program.

5. launch the arduino-0022 program. click in the arrow poining up (open) and open the ArduinoISP example. click in tools>board>arduino uno. (look you now have all the attiny in there).

Upload the program.

6. Place the attiny85 in a protoboard (breadboard), and connect everythingh to the arduino as the image. Be shure you place the attiny in the correct way or you are going to burn it. (happened to me :P) .

7. On the arduino program go to tools>board>attiny85 (w/ Arduino as ISP). click again tools>burn bootloader>w/ Arduino as ISP. (you may see a error but that's ok).

ok, So let's make the program for the transmitter.


Step 4: Transmitter

Picture of Transmitter
transmitter.bmp
transmisor.png
here is the program for the transmitter. if you make the last step in order now you just have to place the code in the arduino program and upload it.

#include <MANCHESTER.h> //include the library to comunicate
#define TxPin 2 //the pin that is used to send data

unsigned int Tdata = 0; //begin the data in 0

int TRANSISTOR_PIN = 1; //pin that turn ON and OFF the transistor
int PIR_SENSOR_PIN = 0; //the motion sensor pin


void setup()
{
  MANCHESTER.SetTxPin (TxPin); //set the pin of comunication
  pinMode(TRANSISTOR_PIN, OUTPUT); 
  pinMode(PIR_SENSOR_PIN, INPUT);
}

void loop()
{
int pirVal=digitalRead(PIR_SENSOR_PIN); //read the state of the motion sensor
  if(pirVal == LOW)//if pir sensor detect movement then
 
  {/*action, in this case turn ON the transistor to power
  the transmitter then send the message,
  the turn OFF the transistor*/
 
    digitalWrite(TRANSISTOR_PIN, HIGH);//transistor ON
    delay(1000);
   
    Tdata = 50; //I use 50 as sensor1alarm number but you can use the number that you want
//be sure you use the same number in transmiter and receiver

    MANCHESTER.Transmit(Tdata); //transmit the signal
    delay(100);
   
    digitalWrite(TRANSISTOR_PIN, LOW);//turn OFF transistor to save battery
  }
  delay(2000);
}

Step 5: Receiver

DSC01335.JPG
DSC01336.JPG
for the receiver you just have to program the arduino. So go to tools>board and select arduino uno.
copy this code. and Upload it.

#include <MANCHESTER.h> //include the comunication library
#define RxPin 6 //define the receiver pin
#define speaker 9
#define sensor1alarm 12
#define sensor2alarm 11
#define sensor3alarm 10

void setup()
{
MANCHESTER.SetRxPin(RxPin); //user sets rx pin default 6
MANCHESTER.SetTimeOut(1000); //user sets timeout default blocks
Serial.begin(9600); // Debugging only
//setting the pins in arduino
pinMode(sensor1alarm, OUTPUT);
digitalWrite(sensor1alarm, LOW);
  pinMode(sensor2alarm, OUTPUT);
digitalWrite(sensor2alarm, LOW);
  pinMode(sensor3alarm, OUTPUT);
digitalWrite(sensor3alarm, LOW);
pinMode(speaker, OUTPUT);
digitalWrite(speaker, LOW);
}//end of setup

void loop()
{
unsigned int data = MANCHESTER.Receive();

if(data==50) //match this number with the sensor number
{
digitalWrite(sensor1alarm, HIGH); //turn ON the sensor1alarm led


for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(speaker, HIGH);
  delayMicroseconds(500);
  digitalWrite(speaker, LOW);
  delayMicroseconds(500);
  } //end of for speaker


     digitalWrite(sensor1alarm, LOW); //turn OFF the sensor1alarm led
     delay(500);

}//end of if


//paste in here if you have another transmitter

}//end of loop



/*if you have more than one transmiter you just have to give a diferent number to the transmiter and copy from if(data==50) to end of if, and paste it in the indication. and change the number 50 to the number in the other transmitter.*/

Step 6: Conclusion

You can place your sensor in every case you want. I place mine in soda cans because I think no one is going to check if there is something wrong with a can. and you can place everywhere and doesn't seems weird.  So enjoy been a secret spy or just protect your house from strangers in the night. the uses are endless, you just have to put your creativity to work a little.

p.d. (you can change the motion sensor, for a lot of other sensors with a little changes in the design and you can have temperature sensors, sound sensors, ultrasonic sensors, gas sensors, infrared sensors, and a lot of other sensors for a cheap price that can sense things from a safe distance). 

I hope you enjoy this instructable :), sorry if my english is not the best. 

Step 7: How to use 3 transmitters with one receiver

Picture of how to use 3 transmitters with one receiver
this is the code for using 3 motion sensors with one receiver:

//use this for the receiver
//***********************************************************************************************

#include <MANCHESTER.h> //include the comunication library
#define RxPin 6 //define the receiver pin
#define speaker 9
#define sensor1alarm 12
#define sensor2alarm 11
#define sensor3alarm 10

void setup()
{
MANCHESTER.SetRxPin(RxPin); //user sets rx pin default 6
MANCHESTER.SetTimeOut(1000); //user sets timeout default blocks
Serial.begin(9600); // Debugging only
//setting the pins in arduino
pinMode(sensor1alarm, OUTPUT);
digitalWrite(sensor1alarm, LOW);
  pinMode(sensor2alarm, OUTPUT);
digitalWrite(sensor2alarm, LOW);
  pinMode(sensor3alarm, OUTPUT);
digitalWrite(sensor3alarm, LOW);
pinMode(speaker, OUTPUT);
digitalWrite(speaker, LOW);
}//end of setup

void loop()
{
unsigned int data = MANCHESTER.Receive();

if(data==50) //match this number with the sensor number
{
digitalWrite(sensor1alarm, HIGH); //turn ON the sensor1alarm led


for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(speaker, HIGH);
  delayMicroseconds(500);
  digitalWrite(speaker, LOW);
  delayMicroseconds(500);
  } //end of for speaker


     digitalWrite(sensor1alarm, LOW); //turn OFF the sensor1alarm led
     delay(500);

}//end of if
else if(data==100) //match this number with the sensor number
{
digitalWrite(sensor2alarm, HIGH); //turn ON the sensor1alarm led


for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(speaker, HIGH);
  delayMicroseconds(500);
  digitalWrite(speaker, LOW);
  delayMicroseconds(500);
  } //end of for speaker


     digitalWrite(sensor2alarm, LOW); //turn OFF the sensor1alarm led
     delay(500);
}
else if(data==150) //match this number with the sensor number
{
digitalWrite(sensor3alarm, HIGH); //turn ON the sensor1alarm led


for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
  digitalWrite(speaker, HIGH);
  delayMicroseconds(500);
  digitalWrite(speaker, LOW);
  delayMicroseconds(500);
  } //end of for speaker


     digitalWrite(sensor3alarm, LOW); //turn OFF the sensor1alarm led
     delay(500);
}

}//end of loop

//**************************************************************************************************
//use this for one of the transmitters
//transmitter 1.

#include <MANCHESTER.h> //include the library to comunicate
#define TxPin 2 //the pin that is used to send data

unsigned int Tdata = 0; //begin the data in 0

int TRANSISTOR_PIN = 1; //pin that turn ON and OFF the transistor
int PIR_SENSOR_PIN = 0; //the motion sensor pin


void setup()
{
  MANCHESTER.SetTxPin (TxPin); //set the pin of comunication
  pinMode(TRANSISTOR_PIN, OUTPUT);
  pinMode(PIR_SENSOR_PIN, INPUT);
}

void loop()
{
int pirVal=digitalRead(PIR_SENSOR_PIN); //read the state of the motion sensor
  if(pirVal == LOW)//if pir sensor detect movement then

  {/*action, in this case turn ON the transistor to power
  the transmitter then send the message,
  the turn OFF the transistor*/

    digitalWrite(TRANSISTOR_PIN, HIGH);//transistor ON
    delay(1000);
  
    Tdata = 50;

    MANCHESTER.Transmit(Tdata); //transmit the signal
    delay(100);
  
    digitalWrite(TRANSISTOR_PIN, LOW);//turn OFF transistor to save battery
  }
  delay(2000);
}

//********************************************************************************************
//use this for the secod transmitter.
//transmitter 2.

#include <MANCHESTER.h> //include the library to comunicate
#define TxPin 2 //the pin that is used to send data

unsigned int Tdata = 0; //begin the data in 0

int TRANSISTOR_PIN = 1; //pin that turn ON and OFF the transistor
int PIR_SENSOR_PIN = 0; //the motion sensor pin


void setup()
{
  MANCHESTER.SetTxPin (TxPin); //set the pin of comunication
  pinMode(TRANSISTOR_PIN, OUTPUT);
  pinMode(PIR_SENSOR_PIN, INPUT);
}

void loop()
{
int pirVal=digitalRead(PIR_SENSOR_PIN); //read the state of the motion sensor
  if(pirVal == LOW)//if pir sensor detect movement then

  {/*action, in this case turn ON the transistor to power
  the transmitter then send the message,
  the turn OFF the transistor*/

    digitalWrite(TRANSISTOR_PIN, HIGH);//transistor ON
    delay(1000);
  
    Tdata = 100;

    MANCHESTER.Transmit(Tdata); //transmit the signal
    delay(100);
  
    digitalWrite(TRANSISTOR_PIN, LOW);//turn OFF transistor to save battery
  }
  delay(2000);
}

//*******************************************************************************************
//use this for transmitter 3
//transmitter 3.

//receiver 2.

#include <MANCHESTER.h> //include the library to comunicate
#define TxPin 2 //the pin that is used to send data

unsigned int Tdata = 0; //begin the data in 0

int TRANSISTOR_PIN = 1; //pin that turn ON and OFF the transistor
int PIR_SENSOR_PIN = 0; //the motion sensor pin


void setup()
{
  MANCHESTER.SetTxPin (TxPin); //set the pin of comunication
  pinMode(TRANSISTOR_PIN, OUTPUT);
  pinMode(PIR_SENSOR_PIN, INPUT);
}

void loop()
{
int pirVal=digitalRead(PIR_SENSOR_PIN); //read the state of the motion sensor
  if(pirVal == LOW)//if pir sensor detect movement then

  {/*action, in this case turn ON the transistor to power
  the transmitter then send the message,
  the turn OFF the transistor*/

    digitalWrite(TRANSISTOR_PIN, HIGH);//transistor ON
    delay(1000);
  
    Tdata = 150;

    MANCHESTER.Transmit(Tdata); //transmit the signal
    delay(100);
  
    digitalWrite(TRANSISTOR_PIN, LOW);//turn OFF transistor to save battery
  }
  delay(2000);
}

Step 8: Receiver 2.0

Picture of Receiver 2.0
imagen_componentes.bmp
imagen_todo.bmp
Some of you ask if I can upload the receiver pcb for making the receiver with a attiny85 like the transmitters, to avoid using the arduino uno. Sooo here they are the files to make the receiver for cheap. I hope you like them.

I leave the 3 leds as in the arduino version but instead of placing a speaker y place a relay so you can activate any device you like. For example your house lights, an alarm or any device that you like. 

Warning: make sure you use a relay made for the voltage you are going to use for the circuit. If you are using a 12V relay make sure you use 12v in the BAT1 place

here is the code:

/***********************************************************************************/
#include <MANCHESTER.h> //include the comunication library
#define RxPin 0 //define the receiver pin
#define relay 4
#define sensor1alarm 1
#define sensor2alarm 2
#define sensor3alarm 3

void setup()
{
MANCHESTER.SetRxPin(RxPin); //user sets rx pin default 6
MANCHESTER.SetTimeOut(1000); //user sets timeout default blocks
Serial.begin(9600); // Debugging only
//setting the pins in arduino
pinMode(sensor1alarm, OUTPUT);
digitalWrite(sensor1alarm, LOW);
  pinMode(sensor2alarm, OUTPUT);
digitalWrite(sensor2alarm, LOW);
  pinMode(sensor3alarm, OUTPUT);
digitalWrite(sensor3alarm, LOW);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
}//end of setup

void loop()
{
unsigned int data = MANCHESTER.Receive();

if(data==50) //match this number with the sensor number
{
  for(int i=0 ; i<15 ; i++)
  {
     digitalWrite(sensor1alarm, HIGH); //turn ON the sensor1alarm led
     delay(500);
     digitalWrite(sensor1alarm, LOW); //turn OFF the sensor1alarm led
     delay(500);
  }

}//end of if

if(data==100) //match this number with the sensor number
{
  for(int i=0 ; i<15 ; i++)
  {
     digitalWrite(sensor2alarm, HIGH); //turn ON the sensor2alarm led
     delay(500);
     digitalWrite(sensor2alarm, LOW); //turn OFF the sensor2alarm led
     delay(500);
  }

}//end of if

if(data==150) //match this number with the sensor number
{
  for(int i=0 ; i<15 ; i++)
  {
     digitalWrite(sensor3alarm, HIGH); //turn ON the sensor3alarm led
     delay(500);
     digitalWrite(sensor3alarm, LOW); //turn OFF the sensor3alarm led
     delay(500);
  }

}//end of if

if(data==200) //match this number with the sensor number
{
  for(int i=0 ; i<15 ; i++)
  {
     digitalWrite(relay, HIGH); //turn ON the relay
     delay(500);

  }

}//end of if


}//end of loop
/***************************************************************************************/

any questions write me in the coments please :)

luisfocosta4 months ago

How would it work with an existing wireless motion sensor ?

I am trying to re-use some wireless motion sensors from my previous Wireless Home Alarm system

hotcheezy7 months ago
Hi, can I do 1 transmitter and maybe 3 receivers?
Jochefor (author)  hotcheezy7 months ago

you can make 1 transmitter with all the receivers you want

fmuhammad311 months ago
ok..use arduino 1.0.3 and compile without error..
now the weird thing is why the proteus picture got many component(2 resistor etc) and the other picture only got like 7 component..did i miss something or that circuit include with voltage regulator??
Jochefor (author)  fmuhammad311 months ago
yes, is because in the component picture I only add the most important components, and if you see the picture you need 5v and 12v. In the proteus picture I add a voltage regulator so you only need one 12V voltage source, and the 5 volts are regulated from there.
ok..thanks sir..u are so helpful
ok..thanks sir..u are so helpful
Jochefor (author) 11 months ago
this two messages are normal

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

but the two below are not normal, I think you select the wrong programmer. You need to select the "arduino as isp" programmer, I think you select "avrdude" as programmer in your options
fmuhammad311 months ago
i got this error message..is that normal??
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: invalid byte value (null) specified for immediate mode
avrdude: write to file 'null' failed
Ridach1 year ago
Ouch thats expensive you relize on Ebay you can get everything for this project for a lot less, exp PIR sensor is only 1.75
Jochefor (author) 1 year ago
I forgot to mention, the red pad its actually a wire that you need to place in the component side. I place it like that because i dont have more room in the bottom part.
Neg41 year ago
hey i was thinking of building a similar device and i had two questions.
One is there any way i can use this device to trigger a video to play?
and am not that much of a hardware connoisseur but i can follow some good instruction well, so could i build this thing and expect it to work?
Jochefor (author)  Neg41 year ago
yes i think you can make that, but if you are not really good with hardware i recomend you to make the easy way. buy two arduinos, the motion sensor and the tranmiter and receiver. its a little more expensive but is way easier. instead of the attiny conect all to the arduino and program the arduino the normal way. to trigger a video i recomen you to get an old keyboard, sold the enter button the arduino and in that way you can concet the arduino to the pc without connecting the arduino phisicaly. if you have more questions please ask. and i will like to see the final proyect when you finish it :)
Neg4 Jochefor1 year ago
thanks! i'll give it a shot somehow since i have access to an arduino it will be much cheaper if i attempt your model. maybe i'll make an extension to your intractable on how to make it play video.
Is it possible to use an attiny45 for either the xmitter or receiver? I ordered the xmit/rcv pair but forgot that I'd need another uC. All I have on hand atm are 45's and tiny13's :(
Jochefor (author)  computurwizard2 years ago
yes you can usea attiny45's just when you program them make sure you select that option. I never used them but I look in the sources I used and you can use them.
diy_bloke2 years ago
interesting. May build this :-)
Jochefor (author)  diy_bloke2 years ago
thanks :)
¡Yo vivi en Centro America por casi siete años y su ingles es mucho mas mejor que mi español!

This is a great Instructible and very well written.
rimar20002 years ago
I don't know electronics, but this seems a very useful project.
Jochefor (author)  rimar20002 years ago
thanks. it's really useful for me. I live in mexico and having this make me feel a little safer