Sei sulla pagina 1di 98

WIRELESS HOME SECURITY SYSTEM

ABSTRACT

In India burglary cases are increasing dramatically. Therefore this project is designed to
reduce this crime since this wireless alarm system is low in cost and able to be owned by everyone.
This system could check the condition of transmitters continuously to ensure that the entire system
is able to work without interruption. Furthermore, all zones transmitters can be armed and disarmed
individually. A remote control which require password is built in order to access the system. This
project is analysed and designed before beginning the hardware selection and implementation
stage. System is built after software simulation for the three main parts of the project namely
remote control, transmitter and receiver is done. Then, the hardware is tested and improved to
make it more reliable. The wireless system built at the end of this project has the required features
and met the objectives of this project. Furthermore, it can be applied in a double storey house as
expected since the transmission distance is reasonably long. Finally, the project is completed within
the low cost budget expected.
With the economic development and peoples living standards, it was the home of their
demands higher and higher. Now the people are only hope that has a warm and comfortable home,
in its security, intelligence also set a higher request. How to make use of modern advanced
communications and electronics technology to achieve accurate and reliable home security has
become a home security alarm system at this stage need to be solved.This paper analyzes
deficiencies of the existing home security alarm system, designed a user-friendly, reliable operation
of intelligent wireless home security alarm system. It collects anti-invasion, anti-fire, and other
functions. The front-end of Alarm system using hybrid wireless sensors to achieve a variety of
residential analog signal (the infrared signals issued by the human body, the invasion signals, the
concentration of smoke and so on) forautomatic monitoring. It can overcome the cable-alarm
system wiring difficulties, but also difficult to extend and affect the room artistic. The sensors
output the alarm signal through a wireless way to send the police to host when monitor disaster.
The host accords to dangerous category to send warning messages to mobile phone users and
security-related personnel by Siemens TC35i GSM module. Users can receive warning information
only have a cell phone, and also send text messages to restart the wireless sensors. It can achieve
the non-distance limit truly.The design of wireless home security alarm system is not only high-
quality transmission, anti-jamming ability, easy to expand, and brings at will in the actual
operations; the system integration, the performance perfect, the application leads widely. The
system is cost lower, practical, reliable, flexible and diverse functions, but also widely used in
banks, stores and other important places.
.
TABLE OF CONTENTS

CHAPTER TITLE PAGE


ABSTRACT
TABLE OF CONTENTS
LIST OF TABLES
LIST OF FIGURES
LIST OF ABBREVIATIONS
LIST OF APPENDICES

1 INTRODUCTION 1
1.1 Background 1
1.2 Problem Background 2
1.3 Objectives 2
1.4 Scope of the Project 3
1.5 Project Outcome 4
1.6 Thesis Organization 4
1.7 Project Duration 5

2 LITERATURE REVIEW 6
2.1 Chapter Overview 6
2.2 Previous Projects 7
viii

2.2.1 Home Security System by Zachary Seto,


Jackson Yu 7
2.2.2 Home Security System by Chun-Pai Jimmy
Hsieh, Yang Cao 8
2.2.3 A Smoke Detection System using Wireless
Network 9
2.3 Hardware and Theory 9
2.3.1 Voltage Regulator 9
2.3.2 Encoder and Decoder 11
2.3.3 Transmitter and Receiver 12
2.3.4 Liquid Crystal Display (LCD) 14
2.3.5 Keypad 15
2.3.6 Peripheral Interface Controller (PIC) 16
2.3.6.1 CPU/ Memory 17
2.3.6.2 Serial Port 18
2.3.6.3 Input or Output (I/O) 18
2.3.6.4 Timer 18
2.3.6.5 Interrupt 19
2.3.7 MAX232 and D-sub-9 20
2.4 Software 22
2.4.1 MikroC 8.2.0.0 22
2.4.2 Proteus 7 Professional 23

3 METHODOLOGY 24
3.1 Chapter Overview 24
3.2 Design Housing Zone 24
3.2.1 Ground Floor 25
3.2.2 First Floor 26
3.2.3 Roof 27
3.3 Project Flow 27
3.3.1 Understanding 28
3.3.2 Literature Review 28
3.3.3 Hardware and Software 28
ix

3.3.4 Implementation 29
3.3.5 Test and Improve 29

4 PROJECT IMPLEMENTATION 30
4.1 Chapter Overview 30
4.2 Remote Control 30
4.2.1 Hardware Implementation 30
4.2.2 Programming 32
4.2.3 Functions 33
4.2.4 Security 35
4.2.5 Arm and Disarm Zones Individually 36
4.2.6 Problem 38
4.3 Transmitter 39
4.3.1 Hardware Implementation 39
4.3.2 Programming 41
4.3.3 Data Bits of Encoder 42
4.3.4 Status Checking 42
4.3.5 Problem 43
4.3.5.1 Interrupt 43
4.3.5.2 Toggle Switch 44
4.4 Receiver 46
4.4.1 Hardware Implementation 46
4.4.2 Specify Encoder and Decoder 48
4.4.3 Programming 49
4.4.4 Interrupt 50
4.4.5 Arm and Disarm Zones Individually 52
4.4.6 Alarm 52
4.4.7 Status Checking 54

5 SIMULATION AND RESULTS 56


5.1 Chapter Overview 56
5.2 Simulation 56
5.2.1 Remote Control 57
x

5.2.2 Receiver 60
5.3 Results 62
5.3.1 Outcome of Project 63
5.3.1.1 Alarm Function 63
5.3.1.2 Status Checking Function 67
5.3.2 Project Cost 69
5.4 Limitations 70

6 CONCLUSION & RECOMMENDATION 71


6.1 Conclusion 71
6.2 Recommendation for Future Works 72

REFERENCES 73
APPENDICES A-C 75-95
xi

LIST OF TABLES

TABLE NO. TITLE PAGE


1.1 Gantt Chart for 2 Semesters 5
2.1 Transmission Distance 14
2.2 Pin Outs of D-sub-9 Connector 21
4.1 Options for Remote Control 34
4.2 Function of each Keypad Button 34
4.3 Data Bits for Status Checking and Alarm 42
4.4 Time Frame to Send Signals for Status Checking 43
5.1 Project Cost 69
xii

LIST OF FIGURES

FIGURE NO. TITLE PAGE


2.1 IC LM7805 10
2.2 Regulator Circuit 10
2.3 Encoder HT12E and Decoder HT12D 11
2.4 Pin Assignments of HT12E and HT12D 12
2.5 Transmitter Module TX-433 & TX-315 13
2.6 Receiver Module RX-433 & RX-315 13
2.7 16X2 LCD 14
2.8 Pin Description of LCD 15
2.9 4X4 Keypad 15
2.10 Construction of Keypad using SPST Switches 16
2.11 Pin Assignments of PIC16F877A 17
2.12 Microcontroller Interfaces with External Devices 19
2.13 Pin Assignments of MAX232 IC 20
2.14 D-sub-9 Male and Female 21
2.15 Circuit Diagram for Bootloader with DB9 22
3.1 Ground Floor 25
3.2 First Floor 26
3.3 Roof 27
3.4 Project Flow 27
4.1 PIC16F877A Wiring Connection at Remote Control 31
4.2 Encoder HT12E & Transmitter Wiring Connection 32
4.3 Block Diagram of Remote Control Program 33
4.4 PIC16F877A Wiring Connection at Transmitter 39
4.5 Encoder HT12E & Transmitter Wiring Connection 40
xiii

4.6 Block Diagram of Transmitter Program 41


4.7 Ideal Switching Versus Real Switching 45
4.8 PIC16F877A Wiring Connection at Receiver 46
4.9 Decoder HT12D (Remote Control) and Receiver
Module Circuit 47
4.10 Flow Chart of Decoder HT12D 47
4.11 Decoder HT12D (Transmitter) and Receiver Module
Circuit 48
4.12 Block Diagram for Interrupt at Receiver 49
4.13 Block Diagram for Receiver Program 50
5.1 Start Up Screen 57
5.2 Request Password 57
5.3 Password Rejected and Access Denied Screen 58
5.4 Password Accepted Screen 58
5.5 Action Screen 58
5.6 Arm and Disarm System 58
5.7 Zone 1 Off and Zone 2 On Screen 59
5.8 Status Checking Screen 59
5.9 Connections of Receiver for Simulation 60
5.10 LEDs Show the Data to Encoder 61
5.11 Simulation at Receiver when System Armed 62
5.12 Standby Mode of Remote Control 63
5.13 Password Request Screen 64
5.14 Password Accepted Display at LCD 64
5.15 Access Denied Display at LCD 64
5.16 Password Rejected Display at LCD 64
5.17 Action Display at LCD 64
5.18 Armed System Display at LCD 65
5.19 All Zones LEDs are Turned On 65
5.20 Zone 2 Off Display at LCD 65
5.21 Zone 2 is Turned Off 66
5.22 Zone 1 is Alarmed 66
5.23 Transmitter Zone 2 and the Output for Status Checking
xiv

at Receiver 67
5.24 Transmitter Zone 3 and the Output for Status Checking
at Receiver 68
5.25 Indicates Zone 4 Transmitter not Working 68
xv

LIST OF ABBREVIATIONS

PC - Personal Computer
GSM - Global System for Mobile Communications
SMS - Short Message Service
PIC - Peripheral Interface Controller
IC - Integrated Circuit
LCD - Liquid Crystal Display
HMI - Human Machine Interface
SPST - Single Pole Single Throw
CPU - Central Processing Unit
I/O - Input or Output
EEPROM - Electrically Erasable Programmable Read Only
Memory
ADC - Analogue to Digital Converter
TTL - TransistorTransistor Logic
RAM - Random Access Memory
ROM - Read-Only Memory
ISR ` - Interrupt Subroutine
xvi

LIST OF APPENDICES

APPENDIX TITLE PAGE


A Program Code for PIC at Remote Control 75
B Program Code for PIC at Transmitter 85
C Program Code for PIC at Receiver 88
CHAPTER 1

INTRODUCTION

1.1 Background

These days when the thefts are all time high, a comprehensive home security system is the need
of the hour to ensure peace of mind of any homeowner. Whenever youre away from your
house, there are good chances that an intruder may enter your house by breaking through the
window or even the main door, and take away all your hard earned money and valuables inside
house.

A robber could injure or even kill the victims. So by installing alarm system in home,
the chances to save the life of the victims may improve. The cost for the alarm system should
be cheap. Therefore residents can buy the system at an affordable price and install it as fast as
possible. In order to have such a system, we should look for wireless home security alarm
system where it could operate without wire for long distance.
2

Additionally, it is significant to have an alarm system which could automatically


check the status of the transmitters used in this system. In any kind of alarm system, the
most important part is the transmitters which are connected to the magnetic door locks
and sensors like smoke detectors and movement detectors. Thus in order to make sure
that the signal from the sensor is able to trigger the alarm, the transmitter should be in
working condition for all the time. Since the end user of the alarm system has no or less
knowledge on how to check the status of the transmitters, it is convenient for them if the
system itself could perform this particular task.

1.2 Problem Background

Today there are a lots of wireless home security alarm system available in the
market. Most of the alarm systems are very expensive and therefore not affordable by
poor or middle class families. Some systems which cost little do not provide reliable
features like status checking. In order to provide the public with a cost effective wireless
security system, it is important to design a low cost system with advanced feature which
ease the residents life and benefits the public and also will decrease the crime rate of
Malaysia.

1.3 Objectives

In this project, the main objective is to design a cost effective wireless alarm
system with 7 zones. Therefore the alarm system could be owned by everyone without
burdening them. Besides that the alarm system also should check the status of the
3

transmitter of the system regularly to ensure that the system could function without any
failure. The failure of the transmitter will be indicated at the receiver through LEDs and
the buzzer beeping sound.

Moreover, the system has a remote control which can arm and disarm the system
and can even switch off any zone of the system individually according to users demand.
The remote control also consists of a 16X2 LCD to display the status of the system and a
4X4 matrix keypad to control the system. Furthermore, the remote control has a default
password which needs to be keyed to operate the system and only the owner has the
password.

1.4 Scope of the Project

In order to realize this type of alarm system by considering time constraint and
budget, there are several scopes that need to be outlined. The project is intended to be
implemented in a double storey house with approximately 22 feet X 70 feet. This house
will be divided into 7 zones which are main door (parking area), living hall, 3 bedrooms,
kitchen and roof.

For this project, only one transmitter is built. This transmitter is flexible such that
it can be used at any zones by just changing its zone configuration. Besides that, the
system is designed to perform status checking of the transmitters only without
considering receiver status. The remote control can be switched off and on each zone
transmitters individually.
4

1.5 Project Outcome

This project targets to develop an alarm system for a house with 7 different
zones. Besides, the system will continuously check the status of the transmitters and
indicate the failure at the receiver which acts as the central processing unit of the
system. The system can be operated through a password secured remote control. This
remote control can arm and disarm the whole system or each individual zone.

1.6 Thesis Organization

Chapter 2 discusses the theory and the previous works related to this project.
Chapter 3 presents the methods and alternatives that have been used from the beginning
until the end of this project. The next chapter describes how this project is built and how
the components are implemented besides discuss the problem faced in this project.
Chapter 5 discusses the simulation and the results of this project. Furthermore, this
chapter also talks about the limitation in this project. The final chapter presents
summary for this and recommends possible future works.
5

1.7 Project Timeline

This project is completed according to the duration specified in table.

Table 1.1: Gantt Chart for Semester 1 and 2

MONTH/TASK JUL AUG SEP OCT NOV DEC JAN FEB MAR APR
Project title selection
Topic understanding
Literature Review
Objective and scope setting
Initial design planning
Hardware Selection
Design implementation
FYP 1 Presentation
Hardware testing and verification
Report Writing
FYP 2 Presentation
Documentation
CHAPTER 2

LITERATURE REVIEW

2.1 Chapter Overview

This chapter discusses projects and paper works related to this project. These
related works have been reviewed carefully in order to improve the quality and
reliability of this project. By analysing the projects did by other researchers, there is a
possibility to know what features are lacking in their projects. They also will
recommend some future works that could be done to improve the same project.
Moreover, there are some useful ideas that can be implemented in this project from other
similar projects.

Therefore, literature review process extended right from the start until the end of
the project. By reviewing the previous works, a proper plan on how this project can be
conducted and the features that have to be added in order to make this project reliable
and marketable are enlightened.
7

Besides that, there are some findings from internet and books which are very
contributive to this project. Throughout the analysis at the beginning of the project, the
special feature in this project is determined and the components used in this project are
decided. In addition, the function and the concept are well understood.

2.2 Previous Projects

2.2.1 Home Security System by Zachary Seto, Jackson Yu [2]

The goal of this project is to design a home security system with 3 detection
zones. Each zone is equipped with a magnetic sensor with connected to the door. When
the door is opened without permission from the owner, the magnetic switches attached
to the doors will trigger the alarm system. The system can only arm and disarm all the
zones together but not individually. Furthermore, the system could not indicate the zone
from where the sensor is triggered

Therefore by acknowledging the problems arise from the project, the design of
this project solved the problems. The alarm system has seven zones so that more areas
can be attached to the sensors. In addition, the design of the system has seven LEDs to
indicate the armed zones and they also inform the owner exactly which zone is alarmed.
Hence, the owner can immediately take action towards that particular zone. This design
has considered adding on a feature that could arm and disarm any zones individually.
Thus, the owner can arm certain zones depending on the need. For example, the house
owner can disarm certain zones in ground floor of the house in the morning to begin his
works while other zones are still secure.
8

2.2.2 Home Security System by Chun-Pai Jimmy Hsieh, Yang Cao [3]

This project built a wired home security system using different type of sensors.
Besides the magnetic switch used at the doors and windows, this project also
implemented temperature sensor, smoke detectors, and motion sensor. Thus, the security
system will sound the siren for two purposes namely when there is intruders or when
there is a smoke or fire. This product equipped with a voice playback chip which will
speak when there is alarm to indicate which sensor contribute to the alarm.

This project is built without considering how the owner of the system could
switch off the system when he enters the armed house from outside. This is because the
main control unit of the system is attached inside the house. This central processing unit
of the system will input all the sensors and keypad while the outputs indicate zones and
voice alarm. Furthermore, a wired system like this project could not provide portability
to operate the system. Thus in wired system, the project designer will probably set a
delay of around 15 seconds in triggering the alarm at the front door in order to provide
some time for the owner to disarm the system. The siren will sound if the owner is
unable to turn off the system within the given time frame and this will be inconvenient.

In designing this alarm system, a wireless system which will be convenient to the
owner is considered. Hence the system is built with a wireless remote control which has
high portability and will ease the owner to bring it along when he is out of the house.
This is because the owner can disarm the system before entering the house and no need
to rush into the house to disarm the system.
9

2.2.3 A Smoke Detection System Using Wireless Network [4]

This smoke detector project is mainly designed for the hearing impaired. Besides
that, this project can be implemented when there is nobody in particular place while the
alarm for the smoke detector is sound. In this paper, the smoke detector will connect to
personal computer (PC) in order to control the GSM (Global System for Mobile
Communications) to send SMS (short message Service) from the detection place and
receive SMS from the victim.

This project is conducted using a laptop which has to be in online status all the
time for the monitoring purpose. Although the laptop can be easily available, it is not
practical to keep the laptop online all the time. This is because it could contribute to the
hang up of the operating system whereby it cannot send signal to the GSM. Thus, it is
recommended to use microcontroller like Peripheral Interface Controller (PIC) instead
of PC as the control unit. By considering this, this project is designed by using a PIC
microcontroller as main device to control the inputs and outputs. Therefore, it is very
convenient from using a laptop which is consumes a lot of power compared with the
PIC.

2.3 Hardware and Theory

2.3.1 Voltage Regulator

In this project, all the components using +5 volts (V) direct current. Therefore in
order to supply this voltage to the components, we need a regulator circuit to step down
10

the voltage source like +9V alkaline battery to +5V. Since the regulator Integrated
Circuit (IC) is cheap and easily available, the regulator IC 7805 is used in this project
[7].

Figure 2.1: IC LM7805

There will be noise occurred when regulating the voltage. Therefore capacitors
need to be added to get an accurate +5V. [5]

Figure 2.2: Regulator Circuit


11

2.3.2 Encoder and Decoder

An encoder is a circuit where the data can be changed from one format to
another format which suits the circuitry it interfaces with. On the other hand, decoder is
a circuit as encoder which change a specifically coded signal received from receiver to a
format suitable with the interfacing circuit.

In this project by considering the selection criteria, HOLTEK HT-12E is chosen


as the encoder while HOLTEK HT-12D is chosen as the decoder. The two ICs are
chosen for safety purpose. The encoder encodes information which in this case contains
8 address bits and 4 data bits once transmit enable pin is grounded. The bits can be set to
two different states which are 0 and 1.These 12 parallel bits will be changed to a serial
format so that it becomes compatible with the transmitter modules input. The 8 address
bits will precede the coded serial data and followed by the 4 data bits. [6]

When the preceding bits are matched with decoders address bits, the decoder will
decodes the 4 data bits. The VT pin also goes high to indicate that the transmission is
valid. The data will be very safe and correctly decoded to parallel in order to match the
interfacing circuitry. Besides this, the address pins at the encoder and decoder can be set
accordingly to communicate smoothly between both ICs. [7]

Figure 2.3: Encoder HT12E and Decoder HT12D


12

Figure 2.4: Pin Assignments of HT12E and HT12D

2.3.3 Transmitter and Receiver

Transmitter circuit is used to transmit data signal through air at a specific


frequency. The encoded serial data signal from the encoder is modulated at certain
carrier frequency and transmitted to the receiver. It means that, the input data of the
encoder is represented as electromagnetic waves at the output of the transmitter.

On the other hand, receiver circuit will receive and process the electromagnetic
waves from the transmitter using the same carrier frequency. In this project, the
transmitter and receiver module used are those which are easily available at market at
low cost. The modules used in this project are using 433 MHz and 315 MHz as their
carrier frequencies. In this case, receiver used to receive the signal sent from transmitter.
The information from the signal is extracted using decoder. [8][9]
13

Figure 2.5: Transmitter Module TX-433 & TX-315

Furthermore, the antenna is needed to transmit data over a long distance. Hence,
in this project a 10cm long single core wire is used as antenna. This length of antenna
could provide transmission over the specified distance

Figure 2.6: Receiver Module RX-433 & RX-315

The main concern for the transmitter and receiver is the working range for the
wireless system. Although the range is provided by the manufacturer, it is a must to test
the range in order to verify how far the system could work. The transmitter and the
receiver are tested by looking at the valid transmission LED light at the receiver and the
transmit enable pin is enabled throughout the test.
14

Effective distance of communication bet the transmitter and the receiver is tested
at different location and the result obtained is shown at table 2.1. The results are the
average values collected from different conditions for three times.

Table 2.1: Transmission distance


Condition Average Distance (meter)

Open Field 65
Apartment Building 28
Single Family Home 33

2.3.4 Liquid Crystal Display (LCD)

In this project, LCD is used for display purpose. A 16X2 LCD is chosen as it is
suitable with the number of character needed in this case. 16X2 display means there are
16 column and 2 rows to display alphanumeric. It is a parallel display with LED
backlight. This LCD with 2 controllers has 16 pins whereby two of the pins are used for
backlight connection if compare with normal LCD. Pin description is shown in the table
below. [10]

Figure 2.7: 16X2 LCD


15

Figure 2.8 Pin description of LCD

2.3.5 Keypad

The keypad is a part of Human Machine Interface (HMI) needed to input data
into the system. This project required a 4X4 matrix keypad to configure the alarm
system. It consists of 16 buttons. This keypad can be constructed using 16 Single Pole
Single Throw (SPST) switches. [11]

Figure 2.9: 4X4 keypad


16

Figure 2.10: Construction of Keypad using SPST Switches [12]

2.3.6 PIC

In this project, PIC16F877A microcontroller is used as the brain of this alarm


system. There are two brains that available in market and used in projects which can be
named as microcontroller and microprocessor. There is a significant difference between
both devices. A microprocessor is a unit which require other components to interface
with to perform its task. On the other hand, a microcontroller is designed so that no
external components are needed to run the application because all required peripherals
were built in a single chip. A microcontroller is normally used for a specific purpose
while a microprocessor can perform multi tasks as those microprocessors in PC. In this
project, the microcontroller is used to control the output of the system according to the
inputs.
17

So basically some peripherals and features are readily built into the PIC
microcontroller namely Central Processing Unit (CPU), memory, serial port, Input or
Output (I/O), timer and interrupt. [13]

Figure 2.11 Pin Assignments of PIC16F877A

2.3.6.1 CPU/ Memory

The CPU in microcontroller is a complex sequential circuit whose main function


is to execute programs that are kept in its flash Electrically Erasable Programmable
Read Only Memory (EEPROM). Program is a series of instructions to perform a task
and the program is designated by the user. [14]
18

2.3.6.2 Serial Port

Serial port is use to communicate with other devices like PC. Therefore in this
example PC could read the microcontrollers program or even its model. The PC can
write the program into the microcontroller by interfacing them. Three pins are used by
the microcontroller in transferring the data, namely sending data pin TX, receiving data
pin RX and a reference for the input and output. [15]

2.3.6.3 Input or Output (I/O)

Input and output of the microcontroller are significant component to interact with
outside world. By inputting certain signals, the microcontroller can react to the input as
programmed to produce useful outputs. There are 33 I/O pins in this PIC16F877A which
can be used as input or output. This microcontroller can only read digital signals and
therefore it is necessary to convert the analogue signal to digital signal using Analogue
to Digital Converter (ADC). With this feature, the PIC microcontroller is suited for any
type of signals. [15]

2.3.6.4 Timer

Timer in microcontroller can be called as counter. Timer function is to deal with


the time events and it is driven either through the external clock pulse or using internal
19

oscillator. For instance in order to control a programs output at certain delay of time,
the timer is in charge to inform the CPU on when to give that particular output. [16]

2.3.6.5 Interrupt

Microcontroller PIC16F877A has fifteen interrupts. The reset vector is at 0000h


and the interrupt vector is at 0004h in the memory. Thus when an interrupt occur, the
CPU will jump into Interrupt Subroutine mode at vector 0004h in the program and
execute the program. There are certain registers that need to be configured in the
program so that the interrupt feature can be used. For example register OPTION_REG
sixth bit need to be set to detect either rising edge or the falling edge. [15]

Figure 2.12: Microcontroller Interfaces with External Devices [17]


20

2.3.7 MAX232 and D-sub-9

In is crucial to have a boot loader circuit and D-sub-9 to interface with PC. By
using this circuit, it is possible to read the PIC and write the program in hex file into the
PIC microcontroller by ourselves without buying expensive programmer.

MAX232 is an IC which is used to change signals from a RS-232 serial to match


the circuit it interfaces with. In this case, the signal will be converted to a signal which
suits the use in transistortransistor logic (TTL) compatible digital logic circuits. [18]

Figure 2.13: Pin Assignments of MAX232 IC

The D-subminiature-9 or D-sub-9 is an electrical connector which is commonly


used in computers. The RS-232 serial port is using D-sub-9 to connect with PC. In this
case, the D-sub-9 female is used to connect with male D-sub-9 connector at PC.
21

Figure 2.14: D-sub-9 Male and Female [19]

Only certain pins from the total of 9 pins are used in this project to detect and
burn the programming into to PIC microcontroller. Those are pin 2, 3, and 5. The pins
assignments of the D-sub-9 are as below.

Table 2.2: Pin outs of D-sub-9 connector


D-sub-9 Signal Direction Signal Name
3 DTE-to-DCE Transmitted Data
2 DCE-to-DTE Received Data
7 DTE-to-DCE Request To Send
8 DCE-to-DTE Clear To Send
6 DCE-to-DTE Data Set Ready
5 x Signal Ground
1 DCE-to-DTE Received Line Signal
Detector (Carrier Detect)
4 DTE-to-DCE Data Terminal Ready
9 DCE-to-DTE Ring Indicator
22

Figure 2.16 below shows how the bootloader circuit is connected to detect PIC
through pin TX and RX. [20]

Figure 2.15: Circuit diagram for bootloader with DB9

2.4 Software

2.4.1 MikroC 8.2.0.0

This MikroC software is a rich development tool for PIC microcontroller. Its
purpose is to provide the developer or programmer with the easiest ways to develop
applications for embedded systems by providing the same performance or outcomes.
The writing language of this software is C language. There are many libraries in this
23

software that can be used for various applications and to easily interface with the
external hardware like LCD and Keypad. Besides that, it also provides some examples
for reference purpose with its software.

Furthermore, there is another feature namely mikrobootloader in this MikroC


software. It provides convenience to user to burn the program in hex format directly to
the PIC microcontroller by connecting it through bootloader circuit.

2.4.2 Proteus 7 Professional

For this project, ISIS professional is used. It is an interactive system level


simulator. This software provides micro-processor models which can import program
code for that microcontroller by connecting with interactive component models to do
simulation for a complete microcontroller based designs.

ISIS starts from a design to a real time interactive simulation by associate with
the source code. Moreover, some graph objects and signal generator can be placed on
the schematic to perform frequency and swept variable simulation.
CHAPTER 3

METHODOLOGY

3.1 Chapter Overview

This chapter will discuss the methods and alternatives that have been used from
the beginning until the end of this project. Besides this, the design of the house at which
this system is going to be applied is discussed.

3.2 Design Housing Zone

As mentioned in subtopic scope of the project 1.4, this system is applied to a


house which is divided into 7 zones. Therefore, the house is divided into 3 parts which
can be stated as ground floor, first floor and roof.
25

3.2.1 Ground Floor

Ground floor was allocated two zones, namely the front part and the back part of
the house as shown in figure 3.1. At the front part of the house two sensors can be used
at window and main door by using one transmitter. This is because in this project, the
scope was narrowed down to only one transmitter per zone. While at back door and
bathroom window can be placed two sensors also.

Figure 3.1: Ground Floor


26

3.2.2 First Floor

There are three zones reserved for this floor as shown in figure 3.2. The third
zone will be at the front facing balcony and the fourth will be at the middle of the house.
The fourth zone can be placed motion sensor which could detect any motion when the
house is in armed condition. This is because there might be intruders who came down
from the roof. On the other hand, the fifth zone is located at the room number 4 and
bathroom.

Figure 3.2: First Floor


27

3.2.3 Roof

The roof is divi ded into 2 z ones as in figure 3.3. I nside the ro of motion
sensors can be placed.

Figure 3.3: Roof

3.3 Proje ct Flow

There are certain steps follo wed in order to conduct this project as shown below.

Understanding

Literature Review

Hardware & S oftware

Implementation

Tes t & Improve System

Figu re 3.4: Project Flow


28

3.3.1 Understanding

In this step, it is determined how the wireless communication works. Therefore,


the concept and theory regarding this wireless system through radio frequency
transmission are understood. Besides that, the security of the data sent is considered and
thus the encoder and decoder are analyzed.

3.3.2 Literature Review

The previous works related to this project are studied and analyzed in order to
determine the disadvantages in their researches or projects. Then, the lacking features in
their works are improved and implemented in this project.

3.3.3 Hardware and Software

In this section, the hardware and the software are determined to conduct this
project according to the features needed. Besides this, the availability of the hardware
and its cost are considered in choosing the components. Cost is important in this project
since this system is targeted on a low cost product. Then, the hardware is studied based
on the theories and its interfacing with other components. The software is used for
simulation and programming purposes. Besides that, software is required to program the
microcontroller.
29

3.3.4 Implementation

In this stage, the ways on how this hardware and software implemented are
discussed. The project is divided into three parts. Each part will deal with the data
transmission to operate the system besides to trigger the alarm and check the status of
transmitter. Therefore, different data bits for each function are considered.

Furthermore, simulation is important to test the wiring connection of the


components and to test the programming code written for the microcontroller.
Moreover, the system has to fit the requirement of this system which has to be
implemented in a 22 X 70 feet house. Therefore, this wireless systems transmission
range has to work for this houses dimension.

3.3.5 Test and Improve

In this final step, the system hardware is tested to improve the system. Besides
that, this system is imagined as a real system to figure out the problems that could face
when implemented in a house.
CHAPTER 4

PROJECT IMPLEMENTATION

4.1 Chapter Overview

This chapter describes how this project is built and how the components are
implemented. Moreover, the problem faced in this project is discussed.

4.2 Remote Control

4.2.1 Hardware Implementation

Components used in remote control are PIC16F877A, encoder HT12E, LCD,


4X4 keypad, and transmitter module. The remote control is used by the user to operate
the alarm system. Therefore, the remote control is input through keypad. While the
31

outputs of this remote are LCD and serial encoded data signals which transmitted to
receiver.

Figure 4.1: PIC16F877A wiring connection at remote control

The Port B of PIC is connected to keypad while the LCD is connected to Port
Ds pin 4, 5, 6 and 7. Port C is connected to encoder data lines and transmit enable pin.

While the encoder data out pin is connected with transmitter module data pin in
order to transmit the data from PIC to receiver.
32

Figure 4.2: Encoder HT12E & Transmitter Wiring Connection

4.2.2 Programming

C programming is used to program the PIC microcontroller. Programming in this


remote control is to initialize keypad and LCD and make these two components work
accordingly. Besides this, the output at Port C of PIC is programmed in order to enable
data transmission from encoder to receiver through transmitter module.

Figure 4.3 shows the block diagram for the programming code to handle this
remote control.
33

Figure 4.3: Block Diagram of remote control program

4.2.3 Functions

There are many options or functions that can be performed through remote
control.
34

Table 4.1: Options for remote control

Options for Remote Control


1. Set password
2. Arm the all zones
3. Disarm the all zones
4. On and off seven zones individually
5. Off the alarm when trigger
6. Activate and deactivate zone for status checking
7. Return to start-up

Table 4.2: Function of each keypad button

ZONE 1 ZONE 2 ZONE 3 ARMED


1 2 3 A
ZONE 4 ZONE 5 ZONE 6 DISARMED
4 5 6 B
ZONE 7
7 8 9 C
RETURN STATUS CHECKING CONFIGURE ALARM OFF
CONFIGURED STATUS CHECKING
* 0 # D

The remote control can control the zones that wish to undergo status checking
process. By pressing # button, the user can then choose the zones that would not be
included for status checking. Once configured, button 0 has to be pressed to indicate
that status checking zones are chosen. This option is important because sometimes the
voltage of battery may be low and need to be changed. Therefore that particular zone
can be turned off for status checking process.
35

4.2.4 Security

Since security is very important in alarm system, password needs to be keyed in


to operate the system. In lieu of this, the system cannot operate by intruders. In this
project, the default password is set to 123A. In real system the manufacturer will set
the password for the user. This is because sometimes the user may forget the password.
Therefore with an agreement signed by the manufacturer of the alarm system and the
user, the password will be confidential.

Declaration Code for the default password:

unsigned short va1=1, va2=2, va3=3, va4=4;

Subroutine function to request user for password (first digit only):

void password(){
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
strConstCpy(text,please_enter);
Lcd_Custom_Out(1,1,text); // print please enter at LCD
Delay_ms(1000);
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,password1);
Lcd_Custom_Out(1,1,text);
Lcd_Custom_Cmd(LCD_BLINK_CURSOR_ON);

kp =0; // scan for 4 digits password (1st)


do {
kp = Keypad_Released();
pass1 = kp;
}while (!kp);
Lcd_Custom_Cmd(LCD_BLINK_CURSOR_ON);
Lcd_Custom_Out_Cp("X");
Delay_ms(200);
36

Subroutine function to compare password:

void compare_password(){
if ( va1==pass1 && va2==pass2 && va3==pass3 &&
va4==pass4){ Lcd_Custom_Cmd(Lcd_CLEAR);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is set
Lcd_Custom_Out(2, 5, "ACCEPTED");
Delay_ms(1000);}

else{ Lcd_Custom_Cmd(Lcd_CLEAR);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is wrong
Lcd_Custom_Out(2, 5, "REJECTED");
Delay_ms(1000);}}

The password will be requested for three times if previous password entered is
wrong. If the password does not match with the default password for three times, the
LCD will display access denied and thus the alarm system cannot be operated.

Code when the password not matches for three times:

if ((x==3) && !( va1==pass1 && va2==pass2 && va3==pass3 &&


va4==pass4)) { while(1) {
Lcd_Custom_Cmd(Lcd_CLEAR);
Lcd_Custom_Out(1, 3, "ACCESS DENIED");
Delay_ms(1000);}} // keep looping

4.2.5 Arm and Disarm zones individually

One of the objectives of this project is to arm and disarm the system zones
individually. Therefore, the system can arm specifically the place which is important and
37

is not used by the residents of the house at certain time. The signals sent from the
transmitter are set accordingly with the receiver program to perform this function.

Scan keypad code:


Unsigned short k in the program indicates the value for the buttons.
do { // scan keypad
kp = 0;
do {
kp = Keypad_Released();
k = kp;
} while (!kp);
action();
} while (k!=13); // function repeat until press *

Code to arm and disarm zone one:

if (k==1) // button one pressed


{ i++;
if(i==1) // arm zone one
{portc = 0x00;
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_1_off);
Lcd_Custom_Out(1,1,text);
Delay_ms(700);
portd.f0=0;
delay_ms(500);
portc.f0=1;}

if(i==2) // disarm zone 1


{portc = 0x00;
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_1_on);
Lcd_Custom_Out(1,1,text);
i=0;}

The code to arm and disarm the other zones is similar but only need to change
the variables and the output data.
38

4.2.6 Problem

When using MikroC software to write the program for the LCD, a problem
occurred due to the strings. Since many strings are used in this program, there is a
warning when compiling the code. It is caused by the RAM usage which exceeds fifty
percent. Thus, it is necessary to determine on how the strings would not increase the
RAM (Random Access Memory) usage.

Therefore, the solution is declaring strings as constant which will be stored in


ROM (Read-Only Memory). Besides that, the constant need to convert back to strings
when using it to display at LCD.

Declaration code strings as constant:

const char arm system[ ]= "ARMED SYSTEM";

Subroutine to shift from ROM to RAM:


This subroutine function needs to be placed before the main function code.

void strConstCpy(char *dest, const char *source)


{ while(*source)
*dest++ = *source++ ;
*dest = 0 ;}

Example of Usage:

strConstCpy(text,arm_system);
Lcd_Custom_Out(1,1, text);
39

4.3 Transmitter

4.3.1 Hardware Implementation

Components used in transmitter are PIC16F877A, encoder HT12E, and


transmitter module. The function of this transmitter is to trigger the alarm of the system.
On the other hand, the transmitter also will continuously send signals to receiver to
indicate the status of all zones transmitters.

Figure 4.4: PIC16F877A wiring connection at transmitter


40

In this project, no attention is given to the type of the sensors used. A sensor can
generally be considered as a toggle switch. Besides that, there is jumper to assign zone
for the transmitters.

Port C and Port D 3 pins connected with jumper which is grounded. So the zone
can be set using this jumper. While pin RB0 from port B is connected with a toggle
switch which acts as a sensor. Port B also connects with encoder HT12E to transmit data
to receiver.

Figure 4.5: Encoder HT12E & Transmitter Wiring Connection

The data lines connected directly with PICs Port B while the data out pin is
connected with the transmitter module.
41

4.3.2 Programming

C programming in this transmitter is programmed as a common program for all


transmitters. Therefore, the program can be burnt into all transmitters PIC without
changing it for every transmitter. Programming in this transmitter aims at sending
signals continuously to the receiver besides sending signal for triggering the alarm. In
addition, the signals in transmitters have to work depending on the zone select jumper.

Figure 4.5 shows the block diagram for the programming code to handle this
transmitter.

Figure 4.6: Block diagram of transmitter program


42

4.3.3 Data bits of encoder

In order to implement status checking and trigger alarm, two different data bits
required to differentiate these two functions. So in this project, the data bits are set as in
the table below.

Table 4.3: Data bits for Status Checking and Alarm


ZONE DATA BITS : STATUS CHECKNIG ALARM
1 1001 0001
2 1010 0010
3 1011 0011
4 1100 0100
5 1101 0101
6 1110 0110
7 1111 0111

The difference in this type of data bits is the first bit. The first bit of the status
checking is 1 while the first bit of the alarm triggering data is 0. Therefore when the
data signals are transmitted to receiver, it can be differentiated.

4.3.4 Status Checking

Since the status checking is a continuous process, all zones transmitters need to
be synchronized. Besides that, the receiver can only process one data at one time.
Therefore, the transmitter has to follow a sequence for those seven zones. In this project,
43

the seven transmitters are programmed to send continuous signals according to the time
frame in table 4.4.

Table 4.4: Time frame to send signals for status checking


ZONES TIME FRAME (mins)
1 30
2 60
3 90
4 120
5 150
6 180
7 210

For example zone 1 will send data for status checking in 30 minutes after its
transmitter is switched on. After sending the signals, zone 1 transmitter will wait for
another 240 mins before sending the signal again. Similarly, zone 2 will also send
signals in 60 mins then wait for 240 mins before sending the signal again like zone 1.
Similar actions are applied to all zone transmitters.

4.3.5 Problem

4.3.5.1 Interrupt

In this part of the project interrupt in PIC is used. There are two main functions
in transmitters namely trigger alarm and status checking. The signal for status checking
will be sent continuously according to the program. Since the signals for alarm
44

triggering is very important, the priority should be given to this signals. Therefore when
the transmitter is running according to the program in PIC, it should be able to send the
trigger signal once sensor like smoke detector is activated.

Besides that in a real alarm system when the alarm is triggered, the signal is only
sent for a small instant of time like a pulse. When the alarm signal is sent, the buzzer at
the receiver will sound. Then, the program of the receiver has to looking for other
inputs, like instruction by a user to stop the alarm. Therefore, if the status checking
signal from a transmitter is sent continuously, the receiver may not ignore the alarm
triggering signal and unable to take subsequent action.

As a solution for this problem, the interrupt is implemented in the program. Thus,
the program at the transmitter PIC will jump to interrupt subroutine (ISR) when an alarm
is triggered which immediately send signals to the receiver.The interrupt will only detect
the positive edge of the signals of the toggle switch. Although the switch is still on, the
program will only jump to the ISR once.

4.3.5.2 Toggle Switch

There is another problem caused by the toggle switch. This is a common problem
that will occur when using mechanical switches. It is call contact bounce. When the
toggle switch is on, the springy metals in the switch will be forced to contact by actuator.
The bounce is caused when the momentum and elasticity of the contact acted together.
Therefore, rapidly pulsed electrical current is resulted instead of a steady transition from
zero to full current. [21]
45

Figure 4.7: Ideal Switching versus Real Switching [22]

From the above graph it can be interpreted that in order to get a smooth and
steady transition from zero to five volts, a delay of few milliseconds need to be inserted
in the program. Thus when the toggle switch is on, the program will enter the ISR and
wait for 20ms. This is required because the interrupt is configured for positive edge. So
if there is contact bounce, the interrupt function will not execute since it assumes that
the voltage is from 5v to 0v (negative edge).

Interrupt declaration code in main function:

trisb= 0b00000001; // Configure port B


INTCON.f7=1; // Inform PIC that interrupt is used
INTCON.f4=1; // RB0 will be used as interrupt

ISR code for transmitter:

void interrupt(){
Delay_ms(50); // delay to avoid contact bounce
if(portb.f0==1){
zone_checker();
portb.f4=0;
portb.f3=0;
delay_ms(1000);
portb.f3=1;}
INTCON.f1 = 0;} // clear the int flag
4.4 Receive
46

4.4 Receiver

4.4.1 Hardware Implementation

In the receiver, the components used are PIC16F877A, two decoder HT12E,
receiver module 433MHz and 315 MHz, LEDs and buzzer. The function of the receiver
is to indicate which zones are armed using LEDs. The zone which triggered the alarm
will be indicated by the LED too. The receiver will indicate processed zone for status
checking at another three LEDs. Moreover, status checking LED will shows the faulty
transmitter.

Figure 4.8: PIC16F877A wiring connection at receiver


47

The Port Bs pin RB0 is connected to the VT pin of transmitter while the other
pins in Port B connect with LEDs. The data output from the decoder for remote control
is connected with the Port A of PIC. Port C connected with data lines from the decoder
for transmitter. The pin RD0 of Port D is connected with the buzzer.

Figure 4.9: Decoder HT12D (remote control) and receiver module circuit

Figure 4.10: Decoder HT12D (transmitter) and receiver module circuit


48

4.4.2 Specify Encoder and Decoder

In this project, two decoders and two encoders are used. It is required to specify
the encoder that being used so that data is decoded at its decoder only. This can be done
by using encoder HT12E and decoder HT12D. For this purpose, the eight address bits of
the encoder and decoder for remote control is set as 0000 0000. On the other hand, the
address bits for transmitters encoder and decoder is set as 1000 0000.

Figure 4.11: Flow chart of decoder HT12D


49

According to the above flow chart when there is a code entering the data input
pin, the decoder will compare its address bits with the data address bits. If the address
bits are same for three times, then the data is decoded.

4.4.3 Programming

The programming in the receiver part is to output at the LEDs and buzzer
according the inputs from the decoder. Figure 4.11 shows the block diagram for the
programming code to handle this receiver.

Figure 4.12: Block diagram for interrupt at receiver


50

Figure 4.13: Block diagram for receiver Program

4.4.4 Interrupt

In the receiver, interrupt is used as well since it is required to execute program


for trigger alarm once the sensor like smoke detector at transmitter is energized. In this
51

case, external interrupt at pin RB0 of PIC is used. The RB0 pin is connected with the
Valid Transmission (VT) pin of decoder for transmitter.

VT pin will go high when the data input at decoder from the receiver module
matched its address bits with the decoder address bits. Therefore if the RB0 pin is
connected with VT pin, the program will jump to ISR when the data is decoded. There
are data bits for status checking and trigger alarm from the transmitter. In lieu of this,
the ISR will check whether the data is for the alarm trigger or status checking.

ISR code for receiver:


void interrupt(){
Delay_ms(1000);
alarm(); // check for alarm
if(x==0){
zone_check();
x++;}
status_checking(); // status checking
INTCON.f1 = 0;}

Alarm subroutine code for zone one:


if( portc.f0==0 && portc.f1==0 && portc.f2==0 && portc.f3==1 && portb.f7==1)
{portb=0x80; // zone one LED blink
portd.f0=1;} // buzzer is sound

Status checking subroutine code for zone one:


if(portc.f0==1 && portc.f1==0 && portc.f2==0 && portc.f3==1)
{portd=0x10;} // LED will indicate zone one status checked
else{
portd=0x10; // LED will indicate zone one is faulty
while(1){
portd.f0=1; // Buzzer will beep
delay_ms(2000);
portd.f0=0;}
52

4.4.5 Arm and disarm zones individually

As explained in section 4.2.4, the programming for receiver is according to the


received data signals from the remote control. When the button at keypad is pressed, the
PIC at receiver need to accordingly turn on or turn off the LEDs which indicate the
zones.

Arm and disarm code for zone 1:

if(porta==0b001000) // when zone 1 button pressed at remote control


{y++;
if(y==1){ // zone 1 light will off
portb.f7=0;
delay_ms(1500);}

if(y==2){
portb.f7=1; // zone 1 light will on
y=0;
delay_ms(1500);}}

4.4.6 Alarm

When the alarm is triggered, the LED will indicate which zone transmitter is
triggered and subsequently sound the buzzer. There are two situations where the alarm
will be off. One is when the buzzer is sounded, the alarm can be turned off through
remote control. By pressing D, the buzzer will turn off.

The main program of the receiver will keep checking for alarm off input signal
from the remote control once the alarm is triggered.
53

Turn off buzzer code at remote control:

if (k==16){ // when button D pressed


portc = 0x0A;
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,alarm_OFF);
Lcd_Custom_Out(1,1, text); // display alarm off at LCD
Delay_ms(1500);
portc.f0=1;}}

Turn off buzzer code at receiver:

if(porta==0b001101) // when button D pressed


{portd.f0=0;} // system alarm off

Besides that, the alarm is set to automatically shut off within 20 minutes. This is
important when the system alarm is triggered and the house owner is not at home. Thus,
the system has to be set off automatically after a certain delay of time.

Automatic turn off code:

if(portd.f0==1) // if alarm is high


{kp=0;
do{ // alarm stop automatically in 20mins
Delay_ms(10000);
kp=kp++;}
while(kp!=20)
54

4.4.7 Status Checking

As discussed in section 4.3.4, the status checking process is following sequence


of the zone and the delayed time at transmitter. In order to follow the flow at the
transmitter for status check, receiver should have a program that could check all zones
status and indicate the faulty transmitter. Besides that to get the attention of the owner,
the buzzer will beep.

Therefore in this case, the receiver is programmed to sequentially check the


status of each zone transmitter. To implement it, the receiver will check for the zone
from the first status checking signal received. If the signal is from zone 2, the LED for
zone 2 status checking will blink. The next signal should come from zone 3. In case
zone 4 for status checking signal is received, zone 3 LED will blink and the buzzer will
start to beep.

Zone checking code for the first signal:

void zone_check(){ // find the first signal from which zone


if( portc.f0==1 && portc.f1==0 && portc.f2==0 &&
portc.f3==1) {k=0;}
if( portc.f0==1 && portc.f1==0 && portc.f2==1 &&
portc.f3==0) {k=1;}
if( portc.f0==1 && portc.f1==0 && portc.f2==1 &&
portc.f3==1) {k=2;}
if( portc.f0==1 && portc.f1==1 && portc.f2==0 &&
portc.f3==0) {k=3;}
if( portc.f0==1 && portc.f1==1 && portc.f2==0 &&
portc.f3==1) {k=4;}
if( portc.f0==1 && portc.f1==1 && portc.f2==1 &&
portc.f3==0) {k=5;}
if( portc.f0==1 && portc.f1==1 && portc.f2==1 &&
portc.f3==1) {k=6;}
55

Status checking code for zone 1:

k++; // each time enter this subroutine, it will go to next zone


if(k==1){ // zone 1 status checking
if(qq==1) // if this zone turn off for status checking through remote
{k=2;} // will jump to next zone
else
{if(portc.f0==1 && portc.f1==0 && portc.f2==0 && portc.f3==1)
{portd=0x10;} // LED will indicate zone one status checked
else{
portd=0x10; // LED will indicate zone one is faulty
while(1){
portd.f0=1; // Buzzer will beep continuously
delay_ms(2000);
portd.f0=0;
delay_ms(2000);
}}}}

According to this program, the status checking can be zoned sequentially.


CHAPTER 5

SIMULATION AND RESULTS

5.1 Chapter Overview

This chapter includes the simulation of this project using Proteus 7 Professional.
The results of this project are explained. In addition, the limitations in this project are
discussed. The total cost to build this hardware is presented.

5.2 Simulation

The simulation part is done before the hardware is assembled. This is important
because if the simulation is working as expected, then the circuit can be used to build up
the hardware. Furthermore in the simulation, programming code has to be inserted into
the PIC microcontroller. The programming code is ensured correct if the simulation is
functioning properly.
57

For this simulation purpose the remote control and the receiver are used since the
transmitter component is also similar with remote control. The basic circuit of the PIC
microcontroller is similar for all PIC used in this project. Therefore if the LCD has
display, then the circuit is correct and can be implemented in other parts like transmitter
and receiver of this project.

5.2.1 Remote Control

In the remote control, the LCD display can be simulated. Besides that, the data
send to encoder can simulate through LEDs.

Step one: Start up screen when the remote control

Figure 5.1: Start Up Screen

Step two: Enter password to operate the system

Figure 5.2: Request Password


58

Step three: If the password does not match, the display will show password rejected
message. After three trials and failed to key in the correct password, then it will show
access denied message.

Figure 5.3: Password Rejected and Access Denied Screen

If the password is matched, then the display will show password accepted message.

Figure 5.4: Password Accepted Screen

Step four: Configure the system to function according the user.

Figure 5.5: Action Screen

The system is armed and disarmed by pressing A and B respectively and the message
will be displayed accordingly.

Figure 5.6: Arm and Disarm System


59

The armed zones can be turned off or turned on individually through remote control. It
will show message like zone 1 off and zone 1 on.

Figure 5.7: Zone 1 off and zone 1 on screen

Besides that, the status checking can be configured by pressing # to start


configuration. Then choose the zone that need to be turned off. After that, press 0 to
configure the status checking.

Figure 5.8: Status checking screen

The output of the remote control microcontroller will be connected with the
encoder to transmit the signals to receiver. Since encoder has only one data output, it is
quite difficult to interpret the sending data. For simulation purpose, the data sent to
encoder are connected with LEDs. If the LEDs are blinking, it will indicate that the pin
is high.
60

Figure 5.9: LEDs show the data to encoder

5.2.2 Receiver

In the receiver part, the decoder is assumed as a push button switch which is
connected to PIC through resistor. Therefore according to the program when there is any
input at port A, the output LEDs which indicate zones will be blink.

Figure 5.10 shows the connections for this simulation purpose.


61

Figure 5.10: Connections of receiver for simulation

When push button is pressed, according to the program for receiver, all zones
LEDs will blink to indicate that all zones are armed.

Programming code for arm the system at receiver:

If (porta==0x02) // when arm button press, all light will on


{portb=0xFE;}
62

Figure 5.11: Simulation at receiver when system armed

5.3 Results

In this section, the outcome of the project will be discussed by using the
hardware built. Besides that, it will show how the three parts of the system will
communicate in detail. Furthermore, the distance of transmission for this wireless
system is determined. Moreover, the total cost of this project is described in detail.
63

5.3.1 Outcome of Project

In this part, the hardware of the project is used to describe how the entire system
works. Moreover, it includes the features of this wireless security system. First of all the
system is focused on the remote control. After that, the remote control will used to show
how it could communicate with the receiver and transmitter.

The display on the LCD will be discussed sequentially after the remote control is
switch on. Besides that, the receiver is turned on at the same time in order to show the
effect at receiver when operating using remote control.

5.3.1.1 Alarm Function

In this division, the hardware is used to show how to arm the system and how the
system is triggered.

Step 1: Standby mode of remote control.

Figure 5.12: Standby Mode of Remote Control

Step 2: When any keypad key is pressed, password will be requested.


64

Figure 5.13: Password Request Screen

Step 3: If the password entered matched the default password, then the password
accepted screen will appear.

Figure 5.14: Password Accepted Display at LCD

If the password did not match, then password rejected screen will appear. If the
password mismatched for three times, access denied screen will appear. Therefore, user
has to contact the manufacturer of this alarm system.

Figure 5.15: Password Rejected Display at LCD

Figure 5.16: Access Denied Display at LCD

Step 4: When the password is accepted, the screen asking for the subsequent action will
appear. The options for these actions are stated in section 4.2.3.

Figure 5.17: Action Display at LCD


65

For example when key A which function to arm the system is pressed, the text
armed system is displayed and it will turn on all the LEDs at receiver to indicate all
zones are armed.

Figure 5.18: Armed System Display at LCD

Figure 5.19: All Zones LEDs are Turned On

If zone 2 is disarmed by pressing 2 button, the LED indicating zone 2 will turn
off at receiver. Therefore if the alarm is triggered at zone 2 while zone 2 is disarmed, the
alarm would not activate.

Figure 5.20: Zone 2 Off Display at LCD


66

Figure 5.21: Zone 2 is turned off

When the transmitter at zone 1 is triggered by using the toggle switch, only the
zone 1 LED will turn on at receiver in order to indicate that zone 1 alarm is triggered
beside the buzzer sound.

Figure 5.22: Zone 1 is alarmed


67

When the alarm is triggered, it will off automatically within 20 minutes or it can
be turned off through remote control D button.

5.3.1.2 Status checking function

When the transmitter is on, it will start to send the status checking signals
automatically according to the time frame as discussed in section 4.3.4. Therefore when
the transmitter is from zone 2, the status checking LED at receiver will indicate zone 2.
This is because for the first time, the PIC programming at the receiver will check for the
zone where the signal is from.

Figure 5.23: Transmitter zone 2 and the output for status checking at receiver
68

After checking the status of the second zone, the receiver will expect the signal
from zone 3. If the zone 3 signal is received, it will indicate zone 3 at status checking
LEDs as shown below.

Figure 5.24: Transmitter zone 3 and the output for status checking at receiver

Then, receiver will expect to receive signals from zone 4. If the zone 4
transmitter is in fault condition, the signal from zone 5 will reached the receiver. At this
time, the receiver will indicate that zone 4 transmitter is not working through the LED as
shown below. Besides that, the buzzer will beep repeatedly to get the attention of the
user.

Figure 5.25: Indicates Zone 4 Transmitter not Working


69

If zone 4 transmitter is faulty and the transmitter cannot be repair in that


moment, that transmitter can be turned off for status checking through remote control as
explained in subtopic 5.2.1.

5.3.2 Project Cost

The completed hardware of this project is targeted to be within low cost so that it
is marketable to everyone.

The table 5.1 shows the cost consumed for the whole project.

Table 5.1: Project Cost


Components Cost per unit (RM) Unit Total cost (RM)

PIC16F877A 25 3 75
LCD 16X2 35 1 35
4X4 keypad 30 1 30
HT12E 4.50 2 9
HT12D 4.50 2 9
TX-433 25 1 25
TX-315 25 1 25
RX-433 35 1 35
RX-315 35 1 35
Crystal 20Mhz 3.50 3 10.50
Other 30 1 30
TOTAL 318.50
70

Since the project cost is within RM500, it can be concluded that the project is
still under low cost category.

5.4 Limitations

There are some limitations in this project. Firstly, only one transmitter is built for
this project due to limited budget. Although this problem is solved through the zone
select at transmitter, the flow of status checking cannot be done efficiently with only one
transmitter.

The communication between the transmitter and the receiver is only one way
communication. Therefore, the system cannot perform bi-directional communication
which allowed the receiver to send signals to transmitter to request the status of the
transmitter.

For status checking purpose each transmitter needs to be switched on


sequentially. It means that after zone 2 transmitter turned on, the next zone that needs to
be turn on is zone 3. If other zone is turned on, then there will be conflict in status
checking signals.
CHAPTER 6

CONCLUSION & RECOMMENDATION

6.1 Conclusion

In a nutshell, this alarm system is built within low cost. Moreover, the system
can be implemented in a double storey house due to long transmission distance. In
addition, this wireless system zones can be armed or disarmed individually.

This system is highly secure since password is needed to operate the system.
Furthermore, all transmitter status can be checked and the faulty transmitter zone is
indicated at receiver. The triggered zone will be indicated through LED at receiver.

It can be concluded that the system functions as intended and meet the objectives
of this project.
72

6.2 Recommendations for future works

Since this project is important to reduce the burglary cases in Malaysia by


providing advanced feature at low cost, some recommendations to improve this project
are hereby proposed. Some of the suggestions are listed as below:

Transmitters and receivers use two way communication


- Transceiver can be implemented at receivers and transmitters for bi-
directional communication. By using this communication, the transmitters
do not need to be sequentially turned on for status checking.

Provide backup power for receiver


- The receiver part is important and acts as the controller of the entire system.
Therefore if the primary power supply used is 240AC and when suddenly
no electricity, a backup power supply could maintain the receiver function
without make the system fails.

The receiver should be put in a box which triggers alarm when it is opened.
- If the intruder tries to cut off the power supply for the receiver, he needs to
open the box. Thus, the siren will sound to indicate that somebody has
entered the house.
73

REFERENCES

1. http://rmp.gov.my (Malaysian Royal Police)

2. Zachary Seto, Jackson Yu. Home Security System. Cornell University EE476 Final
Project, May 3,1999.
3. Chun-Pai Jimmy Hsieh, Yang Cao. Home Security System. Cornell University EE476
Final Project, May 5, 2004.
4. Dr. Hussein Abdulkadir , Eng. Nada Al-Khatib ,Eng. Osama AlShamma and Eng.
Mahmood Saleh (2006). A Smoke Detection System Using Wireless Network.
Communications and Electronics Department /Faculty of Engineering, Philadelphia
University Amman, Jordan.
5. Holtek Semiconductor Inc. HT12A/HT12E 212 Series of Encoders. April 11, 2000.
6. Holtek Semiconductor Inc. HT12D/HT12F 212 Series of Decoders. November 18, 2002.
7. Cytron Technologies. RF Transmitter Module Datasheet. June 2008.
8. Cytron Technologies. RF Receiver Module Datasheet. June 2008.
10. http://www.8051projects.net/keypad-interfacing
11. http://www.8051projects.net/keypad-interfacing/introduction.php
12. http://www.hvwtech.com/products_view.asp?ProductID=339
13. Lawrence A. Duarte. The Microcontroller Beginners Handbook. 2nd Edition. United
States of America: Prompt Publication. 3-5; 1998.
14. Steven F. Barrett, Daniel J. Pack .Microcontrollers Fundamentals for Engineers and
Scientists. Morgan & Claypool Publishers, 2006.
15. Microchip. PIC16F87XA datasheet. 2003.
16. Dogan Ibrahim. PIC BASIC Projects: 30 Projects Using PIC BASIC and PIC BASIC
PRO. Newnes, 2006.
17. Dhananjay V. Gadre . Programming and Customizing the AVR Microcontroller
Published by McGraw-Hill Professional, 2000.
18. http://en.wikipedia.org/wiki/MAX232
19. http://www.zytrax.com/tech/layer_1/cables/tech_rs232.htm#pins
20. http://mdubuc.freeshell.org/Colt/
21. http://en.wikipedia.org/wiki/Switch
22. http://www.geocities.com/thetonegod/debounce/debounce.html
APPENDIX A

Program Code for PIC at Remote Control


============================================================
; File name: remote.c
; Project: Wireless Home Security System
; ;============================================================
;======================= Define Variables ========================
unsigned short va1=1, va2=2, va3=3, va4=4,pass1, pass2, pass3, pass4; int
i=0,j=0,l=0,m=0,n=0,b=0,v=0, x, key11, num1;
unsigned short kp,k,read1; char text[17];

;======================= Subroutines ============================


void infinite_loop(); void new_password(); void password();
void compare_password(); void action();
void action1(); void sub();

;=================== declare & shift strings storage to ROM =============

const char stat[]= "STATUS CHECKING"; const char configure[]= "CONFIGURE";


const char configured[]= "CONFIGURED"; const char please_enter[]= "PLEASE
ENTER";
const char welcome_home[]= "WELCOME HOME"; const char new_password1[]=
"NEW PASSWORD:"; const char confirm[]= "CONFIRM";
const char password1[]= "PASSWORD:"; const char zone_1_on[]= "ZONE 1 ON"; const
char zone_1_off[]= "ZONE 1 OFF"; const char zone_2_on[]= "ZONE 2 ON"; const char
zone_2_off[]= "ZONE 2 OFF"; const char zone_3_on[]= "ZONE 3 ON"; const char
zone_3_off[]= "ZONE 3 OFF"; const char zone_4_on[]= "ZONE 4 ON"; const char
zone_4_off[]= "ZONE 4 OFF"; const char zone_5_on[]= "ZONE 5 ON"; const char
zone_5_off[]= "ZONE 5 OFF";
const char zone_6_on[]= "ZONE 6 ON"; const char zone_6_off[]= "ZONE 6 OFF";
const char zone_7_on[]= "ZONE 7 ON"; const char zone_7_off[]= "ZONE 7 OFF";
const char arm_system[]= "ARMED SYSTEM";
const char disarm_system[]= "DISARMED SYSTEM"; const char alarm_ON[]=
"ALARM ON";
const char alarm_OFF[]= "ALARM OFF";

;=================== convert strings from ROM to RAM ===============


void strConstCpy(char *dest, const char
*source) { while(*source) compare_password(); //
*dest++ = *source++; *dest = 0 ;} compare password
} while (!( va1==pass1 && va2==pass2
Main Function && va3==pass3 && va4==pass4) &&
=========================== (x!=3));

void main(){ if ((x==3) && !( va1==pass1 &&


TRISD = 0; // va2==pass2 && va3==pass3 &&
Configure port D as output va4==pass4)) {infinite_loop();} // infinite
TRISC = 0; // loop if compare indicate not
Configure port C as output // match 3 times password
PORTC = 0; //
Initialize port C as 0 Lcd_Custom_Cmd(Lcd_CLEAR);
Keypad_Init(&PORTB); // Lcd_Custom_Out(1,1, "ACTION:"); //
Initialize keypad Print Action: at LCD
do { //
/*Initialize LCD connected to scan keypad for action
PORTB*/ kp = 0; //
Lcd_Custom_Config(&PORTD,7,6,5,4,&PO scan keypad
RTD,2,0,3);
do {
kp = Keypad_Released();
do{
k = kp;
portc=0b00000001; //
} while (!kp);
initialize port c
action();
portd.f0=0; //
} while (k!=13); //
initialize port d pin no RD0 as 0
function repeat until press *
Delay_ms(1000);
}while (1);} //
Lcd_Custom_Cmd(LCD_CURSOR_OFF);
function will keep repeating
Lcd_Custom_Cmd(Lcd_CLEAR); //
Clear display
Password Subroutine
strConstCpy(text,welcome_home);
======================
Lcd_Custom_Out(1,3,text); //
Print welcome home at LCD
void password(){
Lcd_Custom_Cmd(Lcd_CLEAR); //
kp = 0; //
Clear display
scan keypad
strConstCpy(text,please_enter); //
do {
convert storage from ROM to RAM
kp = Keypad_Read();
Lcd_Custom_Out(1,1,text); //
} while (!kp);
print please enter at LCD
Delay_ms(1000);
x=0; //
Lcd_Custom_Cmd(Lcd_CLEAR);
ask for password to operate
strConstCpy(text,password1);
do { //
Lcd_Custom_Out(1,1,text);
the system by scanning keypad
Lcd_Custom_Cmd(LCD_BLINK_CURSO
x++;
R_ON);
password();
Delay_ms(500);
kp =0; // Lcd_Custom_Out(1, 3, "ACCESS
scan for 4 digits password (1st) DENIED"); Delay_ms(1000);}}
do {
kp = Keypad_Released(); Action Subroutine
pass1 = kp; ========================
}while (!kp);
Lcd_Custom_Cmd(LCD_BLINK_CURSO void action(){
R_ON); if (k==1) // ZONE 1 {i++;
Lcd_Custom_Out_Cp("X");
Delay_ms(200); if(i==1) {portc = 0x00; portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
kp =0; // strConstCpy(text,zone_1_off);
scan for 4 digits password (2nd) Lcd_Custom_Out(1,1,text); Delay_ms(700);
do { portd.f0=0; delay_ms(500); portc.f0=1;}
kp = Keypad_Released();
pass2 = kp;
if(i==2) {portc = 0x00; portd.f0=1;
} while (!kp);
Lcd_Custom_Out_Cp("X"); Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_1_on);
Delay_ms(200); Lcd_Custom_Out(1,1,text);
i=0;
kp =0; // Delay_ms(700);
scan for 4 digits password (3rd) portd.f0=0;
do { delay_ms(500);
kp = Keypad_Released(); portc.f0=1;}}
pass3 = kp; if (k==2) //
} while (!kp); ZONE 2
Lcd_Custom_Out_Cp("X"); {j++;
Delay_ms(200); if(j==1){
portc = 0x08;
kp =0; // portd.f0=0;
scan for 4 digits password (4th)
Lcd_Custom_Cmd(Lcd_CLEAR);
do { strConstCpy(text,zone_2_off);
kp = Keypad_Released(); Lcd_Custom_Out(1,1,text);
pass4 = kp; Delay_ms(700);
} while (!kp); portc=0;
Lcd_Custom_Out_Cp("X"); delay_ms(500);
Lcd_Custom_Cmd(LCD_CURSOR_OFF);} portc.f0=1;}

if(j==2){
;======================= Infinite portc = 0x08;
Loop Subroutine portd.f0=0;
=================== Lcd_Custom_Cmd(Lcd_CLEAR);
void infinite_loop(){ strConstCpy(text,zone_2_on);
while(1) { // keep looping Lcd_Custom_Out(1,1,text);
Lcd_Custom_Cmd(Lcd_CLEAR); j=0;
Delay_ms(700); { if (k==5) //
portc=0; ZONE 4
delay_ms(500); {m++;
portc.f0=1;}} if(m==1){
portc = 0x04;
if (k==3) // portd.f0=1;
ZONE 3 Lcd_Custom_Cmd(Lcd_CLEAR);
{l++; strConstCpy(text,zone_4_off);
if(l==1){ Lcd_Custom_Out(1,1, text);
portc = 0x08; Delay_ms(700);
portd.f0=1; portd.f0=0;
Lcd_Custom_Cmd(Lcd_CLEAR); portc=0;
strConstCpy(text,zone_3_off); delay_ms(500);
Lcd_Custom_Out(1,1, text); portc.f0=1;}
Delay_ms(700);
portd.f0=0; if(m==2){
portc=0; portc = 0x04;
delay_ms(500); portd.f0=1;
portc.f0=1;} Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_4_on);
if(l==2){ Lcd_Custom_Out(1,1, text);
portc = 0x08; m=0;
Delay_ms(700); portd.f0=0; portc=0;
portd.f0=1; delay_ms(500); portc.f0=1;}}
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_3_on); if (k==6) //
Lcd_Custom_Out(1,1, text); ZONE 5
l=0; Delay_ms(700); portd.f0=0; portc=0; {n++;
delay_ms(500); portc.f0=1;}} if(n==1){
portc = 0x0C;
if (k==4){ // portd.f0=0;
ARM WHOLE SYSTEM Lcd_Custom_Cmd(Lcd_CLEAR);
portc = 0x04; strConstCpy(text,zone_5_off);
portd.f0=0; Lcd_Custom_Out(1,1, text);
Lcd_Custom_Cmd(Lcd_CLEAR); Delay_ms(700);
strConstCpy(text,arm_system); portc=0;
Lcd_Custom_Out(1,1, text); delay_ms(500);
i=0,j=0,l=0,m=0,n=0,b=0,v=0; portc.f0=1;}
Delay_ms(700);
portd.f0=0; if(n==2){
portc=0; portc = 0x0C;
delay_ms(500); portd.f0=0;
portc.f0=1;} Lcd_Custom_Cmd(Lcd_CLEAR);
sub();} strConstCpy(text,zone_5_on);
Lcd_Custom_Out(1,1, text);
void sub() n=0;
Delay_ms(700);
portc=0; portc = 0x02;
delay_ms(500); portd.f0=1;
portc.f0=1;}} Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_7_off);
if (k==7) // Lcd_Custom_Out(1,1, text);
ZONE 6 Delay_ms(700);
{b++; portd.f0=0;
if(b==1){ portc=0;
portc = 0x0C; delay_ms(500);
portd.f0=1; portc.f0=1;}
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_6_off); if(v==2){
Lcd_Custom_Out(1,1, text); portc = 0x02;
Delay_ms(700); portd.f0=1;
portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR);
portc=0; strConstCpy(text,zone_7_on);
delay_ms(500); Lcd_Custom_Out(1,1, text);
portc.f0=1;} v=0;
Delay_ms(700);
if(b==2){ portd.f0=0;
portc = 0x0C;
portc=0; delay_ms(500); portc.f0=1;}}
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_6_on);
Lcd_Custom_Out(1,1, text); if (k==14) //
b=0; Delay_ms(700); portd.f0=0; portc=0; Configured Status Checking
delay_ms(500); portc.f0=1;}} {portc = 0x0E;
portd.f0=0;
if (k==8) // Lcd_Custom_Cmd(Lcd_CLEAR);
DISARM WHOLE SYSTEM strConstCpy(text,stat);
{portc = 0x02; Lcd_Custom_Out(1,1, text);
portd.f0=0; strConstCpy(text,configured);
Lcd_Custom_Cmd(Lcd_CLEAR); Lcd_Custom_Out(2,1, text);
strConstCpy(text,disarm_system); Delay_ms(700);
Lcd_Custom_Out(1,1, text); portc=0;
i=1,j=1,l=1,m=1,n=1,b=1,v=1; delay_ms(500);
Delay_ms(700); portc.f0=1;}
portd.f0=0;
portc=0; if (k==15){ //
delay_ms(500); Configure status checking
portc.f0=1;} portc = 0x0A;
portd.f0=0;
if (k==9) // Lcd_Custom_Cmd(Lcd_CLEAR);
ZONE 7 strConstCpy(text,configure);
{v++; Lcd_Custom_Out(1,1, text);
if(v==1){ strConstCpy(text,stat);
Lcd_Custom_Out(2,1, text);
Delay_ms(700);
portd.f0=0;
portc=0;
delay_ms(500);
portc.f0=1;}

if (k==16){ // off
alarm
portc = 0x0A;
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,alarm_OFF);
Lcd_Custom_Out(1,1, text);
Delay_ms(700);
portd.f0=0;
portc=0;
delay_ms(500);
portc.f0=1;}}

Compare Password
===================
void compare_password(){
if ( va1==pass1 && va2==pass2 &&
va3==pass3 && va4==pass4){
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is set
Lcd_Custom_Out(2, 5, "ACCEPTED");
Delay_ms(1000);}

else{
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is wrong
Lcd_Custom_Out(2, 5, "REJECTED");
Delay_ms(1000);}}

END OF PROGRAM
====================
while(1){
APPENDIX B status_checking();}}

Zone Checker Subroutine


Program Code for PIC at Transmitter ==================
void zone_checker(){
=============================== if(portc.f4==0 && portd.f3==0 &&
============================= portd.f2==1 ) // zone 1 {portb.f5=0;
; File name: transmitter.c portb.f6=0;
; Project: Wireless Home Security System portb.f7=1;}
; ;===============================
=============================
if(portc.f4==0 && portd.f3==1 &&
;======================= Define portd.f2==0 )// zone 2
Variables ======================== {portb.f5=0;
int i,k,k1; portb.f6=1;
void zone_checker(); void status_checking(); portb.f7=0;}
if(portc.f4==0 && portd.f3==1 &&
;========================= portd.f2==1 )// zone 3
Interrupt {portb.f5=0;
=========================== portb.f6=1;
void interrupt(){ portb.f7=1;}
Delay_ms(50); if(portc.f4==1 && portd.f3==0 &&
if(portb.f0==1){ portd.f2==0 )// zone 4
zone_checker(); {portb.f5=1;
portb.f4=0; portb.f6=0;
portb.f3=0; portb.f7=0;}
delay_ms(1000); if(portc.f4==1 && portd.f3==0 &&
portb.f3=1;} portd.f2==1 )// zone 5
INTCON.f1 = 0;} // clear the int {portb.f5=1;
flag portb.f6=0;
portb.f7=1;}
Main Function if(portc.f4==1 && portd.f3==1 &&
========================== portd.f2==0 )// zone 6
void main () { {portb.f5=1;
portb.f6=1;
trisb= 0b00000001; portb.f7=0;}
portb= 0b00001000; if(portc.f4==1 && portd.f3==1 &&
INTCON.f7=1; //going to use an portd.f2==1 )// zone 7
interrupt {portb.f5=1;
INTCON.f4=1; //RB0 will be an portb.f6=1;
interrupt portb.f7=1;}}
;======================Status
trisc= 0b11110000; Checking
portc= 0; Subroutine===================
trisd= 0b00001100; void status_checking(){
portd= 0; portb.f4=1;
if( portc.f4==0 && portd.f3==0 && portb.f3=1;}
portd.f2==1 //zone 1 if( portc.f4==1 && portd.f3==1 &&
{for(i=0;i<10;i++){ portd.f2==1) //zone
Delay_ms(1000);} {for(i=0;i<70;i++){
zone_checker(); Delay_ms(1000);}
portb.f3=0; zone_checker();
delay_ms(1000); portb.f3=0;
portb.f3=1;} delay_ms(1000);
if( portc.f4==0 && portd.f3==1 && portb.f3=1;}}
portd.f2==0)//zone 2 END PROGRAM
==========================
{for(i=0;i<20;i++){ Delay_ms(1000);}
zone_checker(); portb.f3=0; delay_ms(1000);
portb.f3=1;}

if( portc.f4==0 && portd.f3==1 &&


portd.f2==1)//zone 3
{for(i=0;i<30;i++){
Delay_ms(1000);}
zone_checker();
portb.f3=0;
delay_ms(1000);
portb.f3=1;}
if( portc.f4==1 && portd.f3==0 &&
portd.f2==0)//zone 4
{for(i=0;i<40;i++){
Delay_ms(1000);}
zone_checker();
portb.f3=0;
delay_ms(1000);
portb.f3=1;}
if( portc.f4==1 && portd.f3==0 &&
portd.f2==1)//zone 5
{for(i=0;i<50;i++){
Delay_ms(1000);}
zone_checker();
portb.f3=0;
delay_ms(1000);
portb.f3=1;}
if( portc.f4==1 && portd.f3==1 &&
portd.f2==0)//zone 6
{for(i=0;i<60;i++){
Delay_ms(1000);}
zone_checker();
portb.f3=0;
delay_ms(1000);
88 ;======================= Main
Function
===========================
APPENDIX C
void main(){
trisb = 0b00000001; //
Configure port B
Program Code for PIC at Receiver
portb = 0; //
Initialize port B as 0
INTCON.f7=1; // going
===============================
to use an interrupt
=============================
INTCON.f4=1; // RB0
; File name: receiver.c
will be an interrupt
; Project: Wireless Home Security System
; ================================
ADCON1 = 0x06 ; //
============================ Changes PORTA to digital
CMCON = 0x07 ; //
;======================= Define Disable analog comparators
Variables ======================== TRISA = 0x0F ; //
unsigned short kp; Configure port A
int
i,m=1,k,n=0,a,x=0,y=0,q=0,o=0,e=0,l=0,t=0,u
=0,h=0; int
qq=0,oo=0,ee=0,ll=0,tt=0,uu=0,hh=0;
int
qqq=0,ooo=0,eee=0,lll=0,ttt=0,uuu=0,hhh=0
;

;=======================
Subroutines
============================
void alarm(); void remote(); void remote1();
void status_checking(); void zone_check();
void status_configure();

;======================= Interrupt
Subroutine ======================
void interrupt(){
Delay_ms(1100);
alarm();
if(x==0){
zone_check();
x++;}
status_checking();
INTCON.f1 = 0;} //clear
the int flag
89 if(porta==0b001101) // alarm off
press, system alarm off
{portd.f0=0;}
PORTA = 0; //
Initialize port A as 0
if(porta==0b001000) // when zone
TRISC = 0x0F; //
Configure port C as input
1 button press,
PORTC = 0; // {y++;
Initialize port C as 0 if(y==1){ // zone 1
TRISD = 0x00; // disarmed
Configure port D as output portb.f7=0;
PORTD = 0; // Initialize delay_ms(1500);}
port D as 0
if(y==2){
while(1) { portb.f7=1; // zone 1
remote(); armed
if(portd.f0==1) y=0;
{kp=0; delay_ms(1500);}}
do{ // alarm
will stop automatically in 15s if(porta==0b000100) // when zone
Delay_ms(1000); // if not 2 button press,
turn off {q++;
kp=kp++; if(q==1){ // zone 2
remote1();} disarmed
while(kp!=15); portb.f6=0;
do delay_ms(1500);}
{portd.f0=0;} // turn off
alarm and keep looping if(q==2){ // zone 2
while(1);}}} armed
portb.f6=1;
Remote Subroutine q=0;
======================== delay_ms(1500);}}
void remote(){ if(n!=2){
if(porta==0b001100) // when zone
if(porta==0x02) // when arm button press,
3 button press,
all light will on {portb=0xFE;
{o++;
y=0,q=0,o=0,e=0,l=0,t=0,u=0;} if(o==1){ // zone 3
disarmed
if(porta==0b000001) // when portb.f5=0;
disarm button, all light will off delay_ms(1500);}
{portb=0b00000000;
portd.f0=0; if(o==2){
y=1,q=1,o=1,e=1,l=1,t=1,u=1;} portb.f5=1; // zone 3
armed
if(porta==0b000101) // configure o=0;
status checking delay_ms(1500);}}
{status_configure();}
if(porta==0b001010) // when zone 4
button press,
{e++;
if(e==1){ // zone 4 if(u==2){ // zone 7
disarmed armed
portb.f4=0; portb.f1=1;
delay_ms(1500);} u=0;
delay_ms(1500);}}}
if(e==2){ // zone 4
armed Remote1 Subroutine
portb.f4=1; =======================
{portb.f4=0;} void remote1(){
e=0; if(porta==0b000001) // when disarm button,
delay_ms(1500);}} all light will off {portb=0b00000000;
portd.f0=0;
if(porta==0b000110) // when zone 5 kp=15;}
button press,
{l++; if(porta==0b001101) // alarm off
if(l==1){ // zone 5 press, system alarm off
disarmed {portd.f0=0;
portb.f3=0; kp=15;}}
delay_ms(1500);}
Status Configure
if(l==2){ // zone 5 =========================
armed void status_configure(){
portb.f3=1; do{
l=0; if(porta==0b001000) // deactivate
delay_ms(1500);}} zone 1
{qq=1;}
if(porta==0b001110) // when zone if(porta==0b000100) // deactivate
6 button press, zone 2
{t++; {oo=1;}
if(t==1){ // zone 6 if(porta==0b001100) // deactivate
disarmed zone 3
portb.f2=0; {ee=1;}
delay_ms(1500);} if(porta==0b001010) // deactivate
zone 4
if(t==2){ // zone 6 {ll=1;}
armed if(porta==0b000110) // deactivate
portb.f2=1; zone 5
t=0; {tt=1;}
delay_ms(1500);}}
if(porta==0b001110) // deactivate
if(porta==0b001001) // when zone 7 zone 6
button press, {uu=1;}
{u++; if(porta==0b001001) // deactivate
if(u==1){ // zone 7 zone 7
disarmed {hh=1;}
portb.f1=0; }while(porta!=0b000111);}
delay_ms(1500);}
Status Checking
=========================
void status_checking(){ k++; else
if(k==1){ // zone 1 status checking {if(portc.f0==1 && portc.f1==1 &&
if(qq==1) portc.f2==0 && portc.f3==0)
{portd=0x40;}
{k=2;} else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x40;
portc.f2==0 && portc.f3==1) while(1){
{portd=0x10;} portd.f0=1; delay_ms(2000); portd.f0=0;
else{ delay_ms(2000);
portd=0x10; }}}}
while(1){
portd.f0=1; delay_ms(2000); portd.f0=0; if(k==5){ // zone 5 status
delay_ms(2000); checking
}}}} if(tt==1)
{k=6;}
if(k==2){ // zone 2 status else
checking {if(portc.f0==1 && portc.f1==1 &&
if(oo==1) portc.f2==0 && portc.f3==1)
{k=3;} {portd=0x50;}
else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x50;
portc.f2==1 && portc.f3==0) while(1){
{portd=0x20;} portd.f0=1; delay_ms(2000); portd.f0=0;
else{ delay_ms(2000);
portd=0x20; }}}}
while(1){
portd.f0=1; delay_ms(2000); portd.f0=0; if(k==6){ // zone 6 status
delay_ms(2000); checking
}}}} if(uu==1)
{k=7;}
if(k==3){ // zone 3 status else
checking {if(portc.f0==1 && portc.f1==1 &&
if(ee==1) portc.f2==1 && portc.f3==0)
{k=4;} {portd=0x60;}
else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x60;
portc.f2==1 && portc.f3==1) while(1){
{portd=0x30;} portd.f0=1;
else{
portd=0x30; delay_ms(2000); portd.f0=0; delay_ms(2000);
while(1){ }}}}
portd.f0=1; delay_ms(2000); portd.f0=0;
delay_ms(2000); if(k==7){ // zone 7 status
}}}} checking
if(hh==1)
if(k==4){ // zone 4 status {k=0;}
checking else
if(ll==1) {if(portc.f0==1 && portc.f1==1 &&
{k=5;} portc.f2==1 && portc.f3==1) {portd=0x70;
k=0;} portd.f0=1;
else{ x=0;
portd=0x70; n=2;}
while(1){ if( portc.f0==0 && portc.f1==0 &&
portd.f0=1; delay_ms(2000); portd.f0=0; portc.f2==1 && portc.f3==0 &&
delay_ms(2000); portb.f6==1)
}}}} {portb=0x40; // zone 2 alarmed
portd.f0=1;
if(k==8) x=0;
{x=0;}} n=2;}
if( portc.f0==0 && portc.f1==0 &&
Zone Check portc.f2==1 && portc.f3==1 &&
========================== portb.f5==1)
void zone_check(){ {portb=0x20; // zone 3 alarmed
if( portc.f0==1 && portc.f1==0 && portd.f0=1;
portc.f2==0 && portc.f3==1) //zone 1 status x=0;
{k=0;} n=2;}
if( portc.f0==1 && portc.f1==0 && if( portc.f0==0 && portc.f1==1 &&
portc.f2==1 && portc.f3==0) //zone 2 status portc.f2==0 && portc.f3==0 &&
{k=1;} portb.f4==1)
if( portc.f0==1 && portc.f1==0 && {portb=0x10; // zone 4 alarmed
portc.f2==1 && portc.f3==1) //zone 3 status portd.f0=1;
{k=2;} x=0;
if( portc.f0==1 && portc.f1==1 && n=2;}
portc.f2==0 && portc.f3==0) //zone 4 status if( portc.f0==0 && portc.f1==1 &&
{k=3;} portc.f2==0 && portc.f3==1 &&
if( portc.f0==1 && portc.f1==1 && portb.f3==1)
portc.f2==0 && portc.f3==1) //zone 5 status {portb=0x08; // zone 5 alarmed
{k=4;} portd.f0=1;
if( portc.f0==1 && portc.f1==1 && x=0;
portc.f2==1 && portc.f3==0) //zone 6 status n=2;}
{k=5;}
if( portc.f0==0 && portc.f1==1 &&
if( portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==0 &&
portc.f2==1 && portc.f3==1) //zone 7 status
{k=6;} portb.f2==1)
{portb=0x04; // zone 6 alarmed
if(portd.f0==1) // when alarm is ring {k=7; portd.f0=1;
x=0;} x=0;
n=2;}
if( portc.f0==0 && portc.f1==1 &&
if(portd.f0==0&& portc.f0==0) {k=7;
portc.f2==1 && portc.f3==1 &&
x=0;}}
portb.f1==1)
{portb=0x02; // zone 7 alarmed
Alarm Subroutine portd.f0=1;
======================== x=0;
void alarm(){ n=2;}
if( portc.f0==0 && portc.f1==0 && if( portc.f0==0)
portc.f2==0 && portc.f3==1 && {x=0;}}
portb.f7==1) END OF PROGRAM
{portb=0x80; // zone 1 alarmed ====================

Potrebbero piacerti anche