You are on page 1of 8

PR14

Alarm System: Motion Detector

Version 1.2
Aug 2008
Cytron Technologies Sdn. Bhd.
Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed by Cytron Technologies Incorporated with respect to the accuracy or use of such information or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Cytron Technologiess products as critical components in life support systems is not authorized except with express written approval by Cytron Technologies. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights.

OVERVIEW
This document describes the development of Cytron Technologies DIY (Do It Yourself) Project No.14 (PR14). This project will use PIC16F876A (microcontroller) to control the alarm system (buzzer & LED) with a PIR Sensor (Motion Detector). Circuit schematic and PIC source code will be provided.

FEATURES
PIC16F876A - 8-bit microcontroller with 22 I/O - operate with 5V supply - operating speed 20MHz Motion Detector (PIR Sensor) - The unit output is high whenever humans motion is detected

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

SYSTEM OVERVIEW

PIR Sensor

LED Microcontroller (PIC16F876A) Buzzer

GENERAL DESCRIPTION
Several models of PIR (Passive InfraRed) sensors are available in Cytron Technologies. There have two type of PIR sensor; one is wireless PIR sensor while another is using wire to PIC microcontroller. For this project, PIR sensor with wire is selected and buzzer represented the siren because it is cheaper.

PIC16F876A (Microcontroller)
This powerful (200 nanosecond instruction execution) yet easy-to-program (only 35 single word instructions) CMOS FLASH-based 8-bit microcontroller packs Microchip's powerful PIC architecture into an 28-pin package and is upwards compatible with the PIC16C5X, PIC12CXXX and PIC16C7X devices. The PIC16F876A features: 256 bytes of EEPROM data memory Self programming In ICD 2 Comparators 5 channels of 10-bit Analog-to-Digital (A/D) converter 2 capture/compare/PWM functions The synchronous serial port can be configured as either 3-wire Serial Peripheral Interface (SPI) or the 2-wire Inter-Integrated Circuit (IC) bus A Universal Asynchronous Receiver Transmitter (UART)

Buzzer (DC 6V)


Since the I/O pin from PIC has limited current to drive this buzzer, a transistor 2N2222 is used to drive it.

PIR (Passive Infrared) Sensor

Output Vcc GND

Figure 1 PIR stands for Passive InfraRed. In simple terms, it is a motion detector. This sensors measure infrared radiation emanating from objects in the field of view. It only has one output pin and another two pins is connected to 5V and GND separately. Apparent motion is detected when an infrared emitting source with one temperature, such as human body, passes in front of source with another temperature, such as wall. The unit output is high whenever there is motion detected. If the motion is continuous, the output remains high. After motion stops, the output remains high for a few seconds (depend on the variable resistor adjusted). It will remain high for longer if H from the jumper is selected. For this project, the resistant of variable resistor is adjusted to as low as possible so that the output of the sensor would not remain high for long time after motion stops.

Figure 2 Figure 2 shows the pin diagram for PIC16F876A. For more detail, please download the datasheet from microchip web site at: http://www.microchip.com

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

HARDWARE
This project will require following hardware: a. b. c. d. e. 1 x PIC16F876A 1 x PR14 Printed Circuit Board (PCB) 1 x PIR Sensor 1 x Buzzer (DC 6V) Other related electronic components

ICSP for Microcontroller

Programming

PIC

Please refer to the schematic diagram of PR14. The schematic is provided free therefore Cytron Technologies will not be responsible for any further modification or improvement.

Figure 4 In Circuit Serial Programming (ICSP) is used for loading program in this project. ICSP offers a convenience way to load program into PIC microcontroller without removing the PIC from the circuit board. So pin 1 (Vpp), pin 27 (PGC) and pin 28 (PGD) from PIC should be connected to Cytron USB In Circuit Programmer (UIC00A) through the external cable. Besides, GND from the circuit board also should be connected with GND from UIC00A and pin 24 (PGM) should be pulled to GND through a 10K resistor as shown in Figure 4. The programmer (UIC00A) is not included in DIY project set since it can be used several times for different project set. User can also choose other type of PIC programmer to load the program. Since the ICSP is used, three I/O pins (RB3, RB6 and RB7) should not be used as input, anyway it still can be used for output.

Interface PIC16F876A with PIR Sensor


Output pin from PIR sensor can be connected to any I/O pin from PIC16F876A while the Vcc pin and GND pin should be connect to 5V and GND respectively. The PCB of this project provides 2 connectors for PIR sensor (labeled as Sensor1 and Sensor2). Output of Sensor1 and Sensor2 was connected to pin 23 (RB2) and pin 22 (RB1) respectively.

Interface PIC16F876A with Buzzer


The base of 2N2222 (transistor) can be connected to any I/O pin through a 1K Ohm resistor and the emitter should be connected to GND. Negative terminal (black wire) of buzzer should be connected with collector (2N2222) and positive terminal (red wire) should be connected to Vcc as shown in schematic diagram.

Power Supply for Circuit

Push Button microcontroller

as

Input

for

PIC

Figure 3 For this project, the voltage range of power source could be given for this circuit board is between 7V and 15V. Higher input voltage will produce more heat at LM7805 voltage regulator. Typical voltage is 12V. Anyhow, LM7805 will still generate some heat at 12V. There are two types of power connector on the circuit board, DC plug Adaptor is for AC-DC adaptor and 2510-02 Power is for battery source. Normally AC to DC adaptor can be plugged to Adaptor type connector. LM7805 (1A maximum) will regulate the given voltage to 5V (VCC) to supply to the PIC16F876A and pull-up the push button (input). The purpose of using diode (D1) is for circuit protection in case the polarity of the power source is incorrect. Capacitor (C5) and capacitor (C1) is use to stabilize the voltage input and output of the LM7805. DS1 is a green LED (small) as power indicator.

Figure 5 One I/O pin is needed for one push button as input of PIC microcontroller. The connection of the push button to the I/O pin is shown in Figure 5. The I/O pin is pull up to 5V using a resistor (with value range 1K-10K) and this configuration will result an active-low input. When the button is being pressed, reading of I/O pin will be in logic 0, while when the button is not pressed, reading of that I/O pin will be logic 1.

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

LED as Output for PIC microcontroller

Program
Please download the sample program from Cytron website (same directory as this DIY project) The source code is provided free and Cytron Technologies will not be responsible for any further modification or improvement. PR 14 is just a simple alarm system by using motion detector. The PCB provides two PIR sensor connectors, 3 LEDs and 3 push buttons. But only one PIR sensor (Sensor1), one LED (LED1) and one push button (SW1) are used if this sample program is being loaded. User can modify the program for more modes and patterns with the extra LEDs, push buttons and sensor connector. Please refer to the schematic diagram for these pins connection.

Figure 6 One I/O pin is needed for one LED as output of PIC microcontroller. The connection for a LED to I/O pin is shown in Figure 6. The function of R8 is to protect the LED from over current that will burn the LED. When the output is in logic 1, the LED will ON, while when the output is in logic 0, the LED will OFF.

SOFTWARE
Flow Chart:
Start

SW1 button pressed?

No

Yes Delay 15 seconds

Figure 7
Alarm set (LED blink in low frequency)

The value inside the red circle in Figure 7 can be changed for desired permitted period duration.

PIR sensor set?

No

Figure 8
Yes Alarm (Buzzer and LED) activated

After permitted period, status = 2 (Scanning Mode start running). Refer to the program shown in Figure 8, LED will blinks in low frequency for Scanning Mode indicating.

Reset button pressed?

No

Yes

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector


Motion Detected Scanning Mode

Step for soldering 2510 connector:


1 2

Figure 9 Refer to the Figure 9, status = 3 if sensor = 1 and status = 2. Thats mean Detected Mode only can activated when the motion detected during the Scanning Mode.

GETTING START
User can obtain the hardware set for this project (PR14) either by online purchasing (www.cytron.com.my) or purchase it in Cytron Technologies Shop. 1. Once user has the hardware set, soldering process can be started now. Please solder the electronic components one by one according the symbols or overlays on the Printed Circuit Board (PCB). Make sure the component value and polarity is correctly soldered. Please refer to PCB Layout in Appendix A.

Figure 10 2. After soldering process is finished, please plug in the PIC16F876A to the 28 pins IC socket in proper side. Please download the necessary files and document from Cytron Technologies website, www.cytron.com.my. These included documentation, sample source code, schematic, component list and software. The next step is to install MPLAB IDE and HI-TECC C PRO into a computer. The MPLAB IDE and HI-TECC C PRO can be downloaded from www.cytron.com.my . Please refer MPLAB IDE installation step document to install the software. The documents can be used to any version of MPLAB IDE software. After the installation complete, open the project file provided using MPLAB IDE. Please refer MPLAB Open Project document to open the sample program. Plug in power supply for the circuit. User can choose to use battery or AD to DC adaptor.

3.

Notice: Only one PIR sensor is given for this project set. User can purchase another PIR sensor for scanning 2 different protection area at the same time. Caution: Make sure all the connectors (2510) are soldered in proper side. Those electronic components have polarity such as capacitor, diode, PIC, PIR sensor, buzzer and LED should be soldered in right polarity or it may cause the circuit board fail to work. Warning:Before the battery (Power) is plugged in, make sure the polarity is correct to prevent the explosion. Wrong polarity of capacitor also may cause explosion. 4.

5.

6.

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

AC to DC adaptor:

program (without modification) is being used. The SW1 button is a switch for setting the alarm system. When it is pressed, the sound Beep will be heard and the permitted period (15 seconds) is start running. The red LED would be turn ON at this period. The purpose of this permitted period is allowing the occupant move freely in the protection area without triggering a false alarm. After 15 seconds, scanning mode is started and the LED will blinks at this time. 10. Once the motion is detected, the buzzer would be activated and the LED would blink more frequent. Just press the Reset button on the PCB to reset the system.

12V Polarity Figure 11 (not included in DIY project set)

9V battery connector:

TEST METHOD
1. 2. Figure 12 (not included in DIY project set) Switch ON the power Power Led (green) will turn ON Press SW1 button Buzzer will beep once and LED 1 (red) will turn ON After 15 seconds, it will enter scanning mode and LED 1,2 and 3 will blink Put your hand near the detector LED 1 will blink and Buzzer will beep If all steps mention above can be executed, your project is done successfully. Congratulations!!

Connection to the PCB board:


3. 4.

WARRANTY
Figure 13 No warranty will be provided as this is DIY project. Please check the polarity of each electronic component before soldering it to board.

7.

Build the project and load the hex file into the PIC microcontroller using the USB In Circuit Programmer (UIC00A). When user build the project, MPLAB IDE will generate hex file. The hex file generated from MPLAB IDE will be named according to project name, not C file name. Cytron Technologies also provide hex file for user. Do not forget to switch ON the power. The programmer is not included in the hardware set but it can be found at Cytron website. (User manual is provided at website). User can modify this program. After modification, build the project once again and load the hex file into the PIC microcontroller using Cytron USB In Circuit Programmer (UIC00A). When the power is provided, the green LED (small) will turn ON. Let say the sample

8.

9.

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

Appendix A PCB Layout:

PIR Sensor

Box Header 2510-03 2510-03 Connector Connector 4K7 Buzzer 1N4148 Diode 4K7 LED 5mm C-cap 30pF 4K7 LM7805 LED 3mm

PIC16F876A

220R

4K7

LED 5mm

20MHz Crystal

E-cap 10uF 16V C-cap C-cap 104 1N4007 104 Diode 2N2222

Adaptor socket Slide Switch

LED 5mm 220R

2510-02 2510-02 1K Connector Connector

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE PR14 Alarm System: Motion Detector

lkjkjkjlhiouihdfhgdshgahg

Prepared by Cytron Technologies Sdn. Bhd. 19, Jalan Kebudayaan 1A, Taman Universiti, 81300 Skudai, Johor, Malaysia. Tel: Fax: +607-521 3178 +607-521 1861

URL: www.cytron.com.my Email: support@cytron.com.my sales@cytron.com.my

Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

You might also like