Introduction
This project describes a motion sensor alarm based on a Passive Infra-Red (PIR) sensor module. There are many vendors that manufacture the PIR sensor modules and almost all of them are pretty much the same in function. They have a single output that goes high (or low, based on specification) when the motion is detected. In this project, a PIC12F635 microcontroller continuously monitors the output from the sensor module and turns a buzzer on when it goes active.
Theory
Certain crystalline materials have the property to generate a surface electric charge when exposed to thermal infrared radiation. This phenomenon is known as pyroelectricity. The Passive Infra-Red (PIR) sensor module works on the same principle. The human body radiates heat in the form of infrared radiation which is maximum at about 9.4 um. The presence of human body creates a sudden change in the IR profile of the surrounding that is sensed by the pyroelectric sensor. The PIR sensor module has an instrumentation circuit on board that amplifies this signal to appropriate voltage level to indicate the detection of motion.
The PIR sensor requires an initial stabilization time of about 10 to 60 seconds in order to function properly. During this time, the sensor gets familiar with the surrounding environment, and any motion in its field of view should be avoided. The PIR sensor has a typical range of 20 feet, and is designed to adjust to slowly changing conditions such as the gradual change in the thermal profile of the surrounding as the day passes. However, any sudden change in the profile (e.g. human body motion) is responded by the sensor. That’s why the PIR sensor module should not be placed near a heater, AC outlet or anything that could create a rapid change in the surrounding environment.
PIR sensor modules usually have a 3-pin connection: Vcc, Output, and Ground. The pinout may vary, so I recommend to check the manufacturer’s datasheet to confirm the pins. Sometime, they do have labels on the board next to the pins. The one I have got does so, and it can be powered through 5-12 V supply as it has its own voltage regulator on board. The output goes high when the motion is sensed.
Besides it also has a 3-pin jumper selection for single or continuous trigger output mode. The two positions have labels H and L. When the jumper is at H position, the output remains high when the sensor is re-triggered repeatedly. In position L, the output goes high and low every time the sensor is triggered. So a continuous motion will give repeated high/low pulses in this mode. The front part of the sensor module has a Fresnel lens to focus the infrared light on to the sensor element.
Circuit Design and Construction
The circuit diagram is quite simple. I have powered my circuit with 4 AA batteries that gives 6 V supply. A diode is used in series to drop the voltage down to 5.4 V as the operating voltage for the PIC microcontroller should be below 5.5 V. Besides, the diode also provides the protection to the circuit in case of reverse polarity of the power supply. I have tested the circuit with NI-MH rechargeable batteries (that gives 4.8 V) and it worked, but I recommend to use the alkaline batteries (1.5 V each) for better performance. You can also use a 9 V battery but then you need a LM7805 regulator IC in your circuit.
The output of the PIR sensor module is monitored through GP5 (pin 2) of PIC12F635. When the motion is sensed, this output is high at about 3.3 V (my sensor module has a 3.3V regulator IC on board). You could still use this voltage as a valid logic high for PIC12F635, but I preferred to use this voltage to drive the base of an NPN transistor (BC547) so that at the collector we will have the full swing of the logic voltages. Now, the microcontroller monitors the voltage at the collector of the transistor. During the normal condition, the transistor is cut off, and the collector output is at logic high (+5 V). When the motion is sensed, the high output from the sensor module saturates the transistor and the voltage at the collector drops down to logic low. The jumper selection for trigger is at H position, so the sensor output will remain active as long as the motion exists. Note that the PIC12F635 microcontroller uses the internal clock oscillator at 4.0 MHz. The MCLR function is disabled and WDT is OFF in this project.
An LED is connected to port GP4 with a current limiting resistor in series. The LED blinks 3 times when the power is turned on. This is to indicate that the system has been powered up. Port pin GP2 drives a piezoelectric buzzer. A piezoelectric buzzer gives the maximum output sound pressure at its resonant frequency. The piezo buzzer I have used is EFM-290ED that has the resonant frequency of 3.4 ±0.5 KHz. After playing with it a little bit, I found the maximum output sound at about 3725 Hz. Although the specification says the operating voltage is from 7-12 V, it creates fairly loud sound when powered with just 5 V.
Software
The firmware is written in C and compiled with MikroC Pro for PIC. When the power is first turned on, the LED blinks 3 times, indicating the system has been powered on. Then the microcontroller waits for 60 sec before it starts monitoring the PIR sensor output. This wait time is required for the PIR sensor to stabilize when first powered on. When the microcontroller detects the sensor is triggered, it drives the piezo buzzer with a 3725 Hz square wave. MikroC has built-in library for generating sound (Sound_Play()). One design question could be how long you want to turn the siren on when the motion is sensed. It depends on how you program the microcontroller. What I have done is this. Since the sensor is in retriggering mode, the buzzer remains on as long as the motion is continuously sensed. If the motion disappears, and the sensor output changes to logic low, the buzzer will not stop immediately, but still be on for about 10 more seconds but with a slightly different frequency (3570 Hz). And if it detects the motion again, it will drive the piezobuzzer at its peak resonant frequency (3725 Hz). In MikroC, you can select the configuration bits through a Edit Project window (Project -> Edit Project). This project uses internal clock source at 4.0 MHz, MCLR disabled, and WDT OFF.
/*
Project: PIR Motion Sensor Alarm (PIC12F635)
Piezo: EFM-290ED, 3.7 KHz connected at GP2
PIR sensor module in retriggering mode
Internal Clock @ 4.0 MHz, MCLR Disabled, WDT OFF
*/
sbit Sensor_IP at GP5_bit; // sensor I/P
sbit LED at GP4_bit; // LED O/P
unsigned short trigger, counter;
void Get_Delay(){
Delay_ms(300);
}
void main() {
CMCON0 = 7;
TRISIO = 0b00101000; // GP5, 5 I/P's, Rest O/P's
GPIO = 0;
Sound_Init(&GPIO,2);
// Blink LED at Startup
LED = 1;
Get_Delay();
LED = 0;
Get_Delay();
LED = 1;
Get_Delay();
LED = 0;
Get_Delay();
LED = 1;
Get_Delay();
LED = 0;
Delay_ms(60000); // 45 Sec delay for PIR module stabilization
counter = 0;
trigger = 0;
do {
while (!Sensor_IP) { // Sensor I/P Low
Sound_Play(3725, 600);
Delay_ms(500);
trigger = 1;
counter = 0;
}
if (trigger) {
Sound_Play(3570, 600);
Delay_ms(500);
counter = counter+1;
if(counter == 10) trigger=0;
}
}while(1);
} // End main()
Output
The finished project is shown below.
i want same pjt using arm
ReplyDeletei want same pjt using arm
ReplyDelete