Thursday, April 25, 2013

13. Remote PIR Project

PIR (Passive Infra Red) detectors are commonly used in intruder alarm systems, for example, in your home, and in motion-activated lighting systems.  This is a very clever device, from the focusing system (Fresnel Lens) to the twin-detector system, to the electronics.  A good description of how it is constructed and how it works, is given at http://www.glolab.com/pirparts/infrared.html.   The detection range of the PIR is about 5 metres.

The wavelength of the radiation detected is 9.4 micro meters.  This is described as long-wave infra red, mid or thermal infra red, or IR-C.  The component looks like this:
Its operating voltage is between 5 V and 12 V or a jumper wire can be used for it to operate at 3.3 V.  The 3 wires correspond to ground (GND), voltage in (VIN) and signal out (alarm).

I have connected my PIR to my Boarduino, which, when it receives an alarm signal, sends a signal to the XBee, which transmits this signal by radio waves to a second XBee.  This second XBee is connected to my Arduino Uno R3, which lights up an LED to tell me that something warm has moved in front of my remotely-positioned PIR (an intruder!!!). 

I had hoped that I could place the remote PIR with Boarduino, outside my house, so that I would get advanced notice of someone approaching the front door.  However, because there are a couple of thick walls in the way, the transmitted signal isn't strong enough.  Never mind - It still works well, telling me when somebody comes into the room, even though I already know that.

I'm not sure whether replacing my 1 mW transmitter with a higher-powered transmitter will solve my problem.  In the meantime, I'll just have to rely on the front door bell.

Here is my remotely-positioned PIR system:


And here it is, connected to the Boarduino.  You can see that the Boarduino is powered by my previously-described power supply/voltmeter display:


The sketch running on the Boarduino is as follows (please forgive the untidy coding - there may well be some redundant stuff):

1:  // RemotePIR  
2:  // PIR motion detector with LED indicator  
3:  // Status info by XBee to PC  
4:  // 11 Jan 2013  
5:  //  
6:    
7:  #include <Wire.h>  
8:    
9:  int PIRpin = 4;          // digital pin 4 for PIR  
10:  int LEDpin = 13;     // digital pin 13 for LED  
11:  int PIRval;       // PIR HIGH or LOW value  
12:    
13:  void setup() {  
14:   pinMode(LEDpin, OUTPUT);  // set the LED pin as ouput  
15:   pinMode(PIRpin, INPUT);   // set the PIR pin as an input  
16:    
17:   Serial.begin(9600);  
18:  }  
19:    
20:  void loop() {  
21:   PIRval = digitalRead(PIRpin);  // read PIR  
22:   if (PIRval == HIGH) {  
23:    Serial.print("H");  
24:    digitalWrite(LEDpin, HIGH);  // LED ON  
25:   }  
26:   else {  
27:    Serial.print("L");  
28:    digitalWrite(LEDpin, LOW);   // LED OFF  
29:   }  
30:   delay(100);  
31:  }  
32:    

And now - the other end of this project, the receiving part:




On the left is the receiving XBee mounted on a mini breadboard (the red light shows that it is in communication with the first XBee and the green LED on the left flashes to confirm that power is applied).  On the right is my Arduino Uno R3 with an activated LED connected to pin 13, indicating that someone has come into the room.

The sketch running on the Arduino is as follows:


1:  //XBeeReceive  
2:  //Sketch for receiving XBee transmissions from RemotePIR on remote   
3:  //Boarduino connected to a PIR and XBee  
4:  //KC 11-Jan-13  
5:    
6:  int LedPin = 13;  
7:    
8:  void setup() {  
9:   //   
10:   Serial.begin(9600);  
11:   pinMode(LedPin, OUTPUT);  
12:   pinMode(speakerPin, OUTPUT);  
13:  }  
14:    
15:  void loop() {  
16:   //    
17:   if (Serial.available())  
18:   {  
19:   int data = Serial.read();  
20:    if (data == 'H')  
21:    {  
22:     digitalWrite(LedPin, HIGH);  
23:     Serial.write(data);  
24:    }  
25:    else if (data == 'L')  
26:    {  
27:     digitalWrite(LedPin, LOW);  
28:     Serial.write(data);  
29:    }  
30:    else  
31:    {  
32:     digitalWrite(LedPin, LOW);     
33:    }  
34:   }   
35:  }  
36:    



As an extra, I connected my DSO Nano, the Digital Storage Oscilloscope I told you about earlier, to the receiving XBee's input, and as you will see from the first sketch above, either a "H" for "high" or "L" for "low" character is transmitted, according to whether the PIR "sees" an intruder or not.  The second sketch reads the signal it receives - ie  "data", and if "data" is "H", it sends the LedPin "HIGH" and the Piezo buzzer plays, or else if "data" is "L", then it sets the LedPin "LOW" ie it turns it off.  The Serial.write(data); (line 41) command sends "L" or "H" to the Serial Monitor like this:









So the signals I see on the DSO Nano oscilloscope are as follows:


Remember that this serial data comes in from left to right on the oscilloscope, so the right-hand side came in first.  Going from right to left, the first dip is the first bit - 0. then comes 1,0,0,1,1,0,0 - making 01001100
Going from right to left, the first dip is the first bit - 0. then comes 1,0,0,1,0,0,0 - making 01001000

If you look up the ASCII Alphanumeric Code (http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/ascii.html), you will find that the 7-bit ASCII - 1001100 represents the character "L", and the 7-bit ASCII - 1001000 represents the character "H"

The eagle-eyed will have spotted that there is an extra zero bit at the end (leftmost dip) of the 8-bit character.


No comments:

Post a Comment