Crime in general is still on the rise, and having a security alarm installed is no longer a perquisite of the wealthy! Here is a simple and compact security alarm system to protect your home/shop and valuables. The circuit is built around a tiny microcontroller chip PIC12F675. Besides, a ready-made Passive Infrared (PIR) module is integrated with the alarm system for reliable human-motion detection.
The built-in passive infrared sensor detects human movement by sensing temperature changes over the scene, and works even in the total darkness. Human body heat moving across the scene will trigger the PIR sensor, and the trigger signal will be sent to the control circuit instantly. As the output of the alarm system can be connected to external lamps or alarm sirens, these devices will be instantly activated upon the detected motion. As a result, the intruder who entered the guarded area, even in total darkness, will instantly be exposed.
Note that PIR sensor can be used not only for detecting motion in the darkness, but it can even be used effectively in daytime where it may produce much less false alarms compared to other motion detection mechanisms. Here, the PIC12F675 works as a logic interface between the detection device and the alarm actuator.
Security Alarm Circuit Description
As stated, this project describes a home security alarm based on a Passive Infra-Red sensor module (PIR1). 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 (3.3V) when the motion is detected. Hera, a PIC12F675 (IC1) microcontroller continuously monitors the output from the PIR sensor module and turns an electro-magnetic relay (RL1) on when it goes active.
The circuit can be powered from four AA/AAA cells that gives 6 VDC supply. A 1N4007 (D1) diode is used in series to drop the voltage down to near 5.3 V as the operating voltage for the PIC microcontroller should be below 5.5 V. As well, this diode provides the protection to the whole electronics in case of reverse polarity of the power supply. PIR sensor modules usually have a 3-pin connection (Vcc, Output, and round). The pinout may vary, so it is recommend to check the manufacturers datasheet to confirm the pins. Sometime, they do have labels on the PCB next to the pins. Most PIR sensor modules can be powered through 5 to 12 VDC supply as it has its own low-drop voltage regulator chip, on board.
The output of the PIR sensor module (PIR1) is monitored through GP5 (pin 2) of PIC12F675. PIC12F675 is an 8-Pin Flash-Based 8-Bit CMOS Microcontroller. Note that,here the PIC12F675 microcontroller uses the internal clock oscillator at 4.0 MHz. When the motion is sensed, this output is high at about 3.3 V . You could still use this voltage as a valid logic high for IC1 by changing the code , but It is preferred to use this voltage to drive the base of a BC547 transistor (T1) so that at the collector we will have the full swing of the logic voltages.
When power supply is turned on by the on/off switch (S1), IC1 monitors the voltage at the collector of the transistor after a delay of about 60 seconds. This initial delay is introduced deliberately to avoid false triggerings, because the PIR sensor requires an initial stabilization time of about 10 to 60 seconds in order to function properly. A red LED (LED1) is connected to port GP0 of IC1 (pin7) with a current limiting resistor (R3) in series. The LED blinks at a slow rate during this delay time.
After this delay, IC1 starts monitoring the voltage at the collector of T1. The LED blinking pattern is now changed to indicate the standby mode. In standby mode, T1 is cut off, and the collector output is at logic high (+5 V). When a valid motion is sensed, the high output from the PIR sensor module saturates the transistor and the voltage at the collector drops down to logic low. Consequently, of port GP1 (pin 6) of IC1 goes high to switch on the 5V DPDT relay (RL1) through transistor T2. This output will remain High, as long as the motion exists, and this active condition is indicated by a steady-glow of LED1. DPDT Switching contacts of RL1 can be connected to powerful external lamps and/or alarms.
PIC12F675 Security Alarm Circuit Schematic
Security Alarm PCB Layout
PIC12F675 Software
The firmware is written in C and compiled with MikroC Pro for PIC. When the power is first turned on, the microcontroller waits for 60 seconds 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 PIR sensor is triggered, it drives the relay switch. Multi-mode control of the visual indicator (Red LED) is also managed by the PIC microcontroller.
////////////////////////////////////////////////////////////////////////////////
// Microcontroller = PIC12F675
// Operates on Internal 4MHz Clock
// Compiler Used is MikroC Pro for PIC by Mikroelektronica
// Demo version can be downloded from MikroElektronika - Development tools, Compilers, Books
// In Demo version, the programcode limit is 4 Kb
// Program Developed By Vineesh Viswam,Emkor Technologies
// Tested by TechNode Engineering Electronics
//
////////////////////////////////////////////////////////////////////////////////
#define LO_IN GPIO.F5
#define LED GPIO.F0
#define BUZ GPIO.F1
#define LOW 0
#define ON 1
#define OFF 0
////////////////////////////////////////////////////////////////////////////////
int i,j=0;
////////////////////////////////////////////////////////////////////////////////
void interrupt()
{
INTCON.GIE = 0;
if (INTCON.T0IF)
{
j++;
if(j == 80)
{
LED = ON;
Delay_Ms(80);
LED = OFF;
j = 0;
}
}
INTCON.T0IF = 0;
INTCON.GIE = 1;
}
////////////////////////////////////////////////////////////////////////////////
void main() {
TRISIO = 0b00100000; //GPIO.F5 configured as input and all others are output
GPIO = 0b00000000;
CMCON = 0b00000111; // Turn OFF All Comparators
OPTION_REG = 0b10000111;
INTCON = 0b00100000; // Enable Timer0 Interrupt
TMR0 = 0b00000000;
OSCCAL = 0b11111100; // Internal 4MHz Oscillator Configured to operate at Maximum frequency
ANSEL = 0b00000000;
LED = OFF;
BUZ = OFF;
INTCON.GIE = 0;
for(i=0; i<60; i++)
{
LED = ON;
Delay_Ms(500); // LED Flashing
LED = OFF;
Delay_Ms(500);
}
LED = OFF;
BUZ = OFF;
INTCON.GIE = 1;
while(1)
{
if (LO_IN == LOW)
{
INTCON.GIE = 0;
LED = ON;
BUZ = ON;
while(LO_IN == 0);
}
else
{
LED = OFF;
BUZ = OFF;
INTCON.GIE = 1;
}
}
}
////////////////////////////////////////////////////////////////////////////////
About Co-author
PIC coding for this circuit was handled by Vineesh Viswam (vineeshtviswam@gmail.com) design assistant at Emkor Technologies, Kottayam, Kerala. Vineesh Viswam is also a freelance coder of TechNode Engineering Electronics, Pallimukku, Kadakkal, Kollam, Kerala an independent electronics R&D lab, founded by me. At present, I am the copyright owner of this work.
The built-in passive infrared sensor detects human movement by sensing temperature changes over the scene, and works even in the total darkness. Human body heat moving across the scene will trigger the PIR sensor, and the trigger signal will be sent to the control circuit instantly. As the output of the alarm system can be connected to external lamps or alarm sirens, these devices will be instantly activated upon the detected motion. As a result, the intruder who entered the guarded area, even in total darkness, will instantly be exposed.
Note that PIR sensor can be used not only for detecting motion in the darkness, but it can even be used effectively in daytime where it may produce much less false alarms compared to other motion detection mechanisms. Here, the PIC12F675 works as a logic interface between the detection device and the alarm actuator.
Security Alarm Circuit Description
As stated, this project describes a home security alarm based on a Passive Infra-Red sensor module (PIR1). 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 (3.3V) when the motion is detected. Hera, a PIC12F675 (IC1) microcontroller continuously monitors the output from the PIR sensor module and turns an electro-magnetic relay (RL1) on when it goes active.
The circuit can be powered from four AA/AAA cells that gives 6 VDC supply. A 1N4007 (D1) diode is used in series to drop the voltage down to near 5.3 V as the operating voltage for the PIC microcontroller should be below 5.5 V. As well, this diode provides the protection to the whole electronics in case of reverse polarity of the power supply. PIR sensor modules usually have a 3-pin connection (Vcc, Output, and round). The pinout may vary, so it is recommend to check the manufacturers datasheet to confirm the pins. Sometime, they do have labels on the PCB next to the pins. Most PIR sensor modules can be powered through 5 to 12 VDC supply as it has its own low-drop voltage regulator chip, on board.
The output of the PIR sensor module (PIR1) is monitored through GP5 (pin 2) of PIC12F675. PIC12F675 is an 8-Pin Flash-Based 8-Bit CMOS Microcontroller. Note that,here the PIC12F675 microcontroller uses the internal clock oscillator at 4.0 MHz. When the motion is sensed, this output is high at about 3.3 V . You could still use this voltage as a valid logic high for IC1 by changing the code , but It is preferred to use this voltage to drive the base of a BC547 transistor (T1) so that at the collector we will have the full swing of the logic voltages.
When power supply is turned on by the on/off switch (S1), IC1 monitors the voltage at the collector of the transistor after a delay of about 60 seconds. This initial delay is introduced deliberately to avoid false triggerings, because the PIR sensor requires an initial stabilization time of about 10 to 60 seconds in order to function properly. A red LED (LED1) is connected to port GP0 of IC1 (pin7) with a current limiting resistor (R3) in series. The LED blinks at a slow rate during this delay time.
After this delay, IC1 starts monitoring the voltage at the collector of T1. The LED blinking pattern is now changed to indicate the standby mode. In standby mode, T1 is cut off, and the collector output is at logic high (+5 V). When a valid motion is sensed, the high output from the PIR sensor module saturates the transistor and the voltage at the collector drops down to logic low. Consequently, of port GP1 (pin 6) of IC1 goes high to switch on the 5V DPDT relay (RL1) through transistor T2. This output will remain High, as long as the motion exists, and this active condition is indicated by a steady-glow of LED1. DPDT Switching contacts of RL1 can be connected to powerful external lamps and/or alarms.
PIC12F675 Security Alarm Circuit Schematic
Security Alarm PCB Layout
PIC12F675 Software
The firmware is written in C and compiled with MikroC Pro for PIC. When the power is first turned on, the microcontroller waits for 60 seconds 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 PIR sensor is triggered, it drives the relay switch. Multi-mode control of the visual indicator (Red LED) is also managed by the PIC microcontroller.
////////////////////////////////////////////////////////////////////////////////
// Microcontroller = PIC12F675
// Operates on Internal 4MHz Clock
// Compiler Used is MikroC Pro for PIC by Mikroelektronica
// Demo version can be downloded from MikroElektronika - Development tools, Compilers, Books
// In Demo version, the programcode limit is 4 Kb
// Program Developed By Vineesh Viswam,Emkor Technologies
// Tested by TechNode Engineering Electronics
//
////////////////////////////////////////////////////////////////////////////////
#define LO_IN GPIO.F5
#define LED GPIO.F0
#define BUZ GPIO.F1
#define LOW 0
#define ON 1
#define OFF 0
////////////////////////////////////////////////////////////////////////////////
int i,j=0;
////////////////////////////////////////////////////////////////////////////////
void interrupt()
{
INTCON.GIE = 0;
if (INTCON.T0IF)
{
j++;
if(j == 80)
{
LED = ON;
Delay_Ms(80);
LED = OFF;
j = 0;
}
}
INTCON.T0IF = 0;
INTCON.GIE = 1;
}
////////////////////////////////////////////////////////////////////////////////
void main() {
TRISIO = 0b00100000; //GPIO.F5 configured as input and all others are output
GPIO = 0b00000000;
CMCON = 0b00000111; // Turn OFF All Comparators
OPTION_REG = 0b10000111;
INTCON = 0b00100000; // Enable Timer0 Interrupt
TMR0 = 0b00000000;
OSCCAL = 0b11111100; // Internal 4MHz Oscillator Configured to operate at Maximum frequency
ANSEL = 0b00000000;
LED = OFF;
BUZ = OFF;
INTCON.GIE = 0;
for(i=0; i<60; i++)
{
LED = ON;
Delay_Ms(500); // LED Flashing
LED = OFF;
Delay_Ms(500);
}
LED = OFF;
BUZ = OFF;
INTCON.GIE = 1;
while(1)
{
if (LO_IN == LOW)
{
INTCON.GIE = 0;
LED = ON;
BUZ = ON;
while(LO_IN == 0);
}
else
{
LED = OFF;
BUZ = OFF;
INTCON.GIE = 1;
}
}
}
////////////////////////////////////////////////////////////////////////////////
About Co-author
PIC coding for this circuit was handled by Vineesh Viswam (vineeshtviswam@gmail.com) design assistant at Emkor Technologies, Kottayam, Kerala. Vineesh Viswam is also a freelance coder of TechNode Engineering Electronics, Pallimukku, Kadakkal, Kollam, Kerala an independent electronics R&D lab, founded by me. At present, I am the copyright owner of this work.