You are on page 1of 114

WIRELESS HOME SECURITY SYSTEM

LOGESWARAN A/L ARUMUGAM

UNIVERSITI TEKNOLOGI MALAYSIA

PSZ 19:16 (Pind. 1/07)

UNIVERSITI TEKNOLOGI MALAYSIA


DECLARATION OF THESIS / UNDERGRADUATE PROJECT PAPER AND COPYRIGHT

Authors full name : Date of birth Title : :

LOGESWARAN A/L ARUMUGAM 15 NOVEMBER1986 WIRELESS HOME SECURITY SYSTEM

Academic Session:

2008/2009

I declare that this thesis is classified as :

CONFIDENTIAL RESTRICTED

(Contains confidential information under the Official Secret Act 1972)* (Contains restricted information as specified by the organisation where research was done)* I agree that my thesis to be published as online open access (full text)

OPEN ACCESS

I acknowledged that Universiti Teknologi Malaysia reserves the right as follows : 1. The thesis is the property of Universiti Teknologi Malaysia. 2. The Library of Universiti Teknologi Malaysia has the right to make copies for the purpose of research only. 3. The Library has the right to make copies of the thesis for academic exchange.

Certified by :

SIGNATURE

SIGNATURE OF SUPERVISOR

861115-59-5601
(NEW IC NO. /PASSPORT NO.)

Professor Madya Zamani bin Md Zain


NAME OF SUPERVISOR

4TH MAY 2009

4TH MAY 2009

NOTES :

If the thesis is CONFIDENTIAL or RESTRICTED, please attach with the letter from the organization with period and reasons for confidentiality or restriction.

I acknowledge that I have studied this piece of work and in my opinion it is in accordance with the scope requirement and quality for the purpose of awarding the degree of Bachelor of Engineering (Electrical -Control & Instrumentation)

Signature

: .. : 4th MAY 2009

Name of Supervisor : Professor Madya Zamani bin Md Zain Date

WIRELESS HOME SECURITY SYSTEM

LOGESWARAN A/L ARUMUGAM

A report submitted in partial fulfilment of the requirements for the award of the degree of Bachelor of Engineering (Electrical - Control & Instrumentation)

Faculty of Electrical Engineering Universiti Teknologi Malaysia

MAY 2009

ii

I declare that this thesis entitled Wireless Home Security System is the result of my own research except as cited in the references. The thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree.

Signature Name Date

: ..................................... : LOGESWARAN A/L ARUMUGAM : 4th MAY 2009

iii

Dedicated, in thankful appreciation for support, encouragement and understandings to my beloved mother, father, brother and sister

iv

ACKNOWLEDGEMENT

First and foremost, I would like to express my heartily gratitude to my supervisor, Professor Madya Zamani Bin Md Zain for the guidance, enthusiasm and motivation given throughout the progress of this project. With his full support, this project is accomplished as expected.

My sincere appreciation also goes to my family who has been so tolerant and supports me all these years. Thanks for their encouragement, love and emotional supports that they had given to me.

I would also like to thank all my friends who have directly or indirectly give me a favour at various occasions to complete my project and their support is such an encouragement for me throughout the project. Their views and tips are useful

indeed. Unfortunately, it is not possible to list all of them in this limited space.

ABSTRACT

In Malaysia 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. .

vi

ABSTRAK

Kes-kes kecurian semakin meningkat di Malaysia. Sebagai tindakan untuk mengurangkan kes-kes ini, sistem penggera keselamatan rumah tanpa wayar ini dilaksanakan. Sistem ini adalah sistem kos murah yang dapat dimiliki oleh semua warga Malaysia. Tambahan pula, sistem ini berkebolehan untuk memeriksa keadaan pemancar secara berterusan untuk memastikan sistem ini berjalan dengan lancar tanpa gangguan. Pemancar dari setiap kawasan di dalam rumah boleh diaktifkan dan dinyahaktifkan secara berasingan. Di samping itu, alat kawalan jauh yang memerlukan perkataan rahsia untuk mengoperasikan sistem ini juga dibina. Projek ini telah dianalisis dan direkabentuk dengan teliti sebelum pemilihan dan pembinaan perkakasan. Sistem ini disimulasikan dengan menggunakan perisian sebelum membina tiga bahagian penting untuk projek ini iaitu alat kawalan jauh, pemancar dan penerima dibina. Perkakasan yang dibina itu diuji dan diperbaiki supaya sistem ini dapat dipercayai oleh pengguna. Sistem penggera tanpa wayar yang dibinakan di penghujung projek ini telah mencapai kehendak projek ini dengan memiliki ciri-ciri yang diperlukan. Sistem ini sesuai digunakan di dalam sebuah rumah dua tingkat disebabkan jarak permancaran isyarat yang jauh. Akhirnya, sistem ini disiapkan dengan kos yang murah.

vii

TABLE OF CONTENTS

CHAPTER

TITLE

PAGE

DECLARATION DEDICATION ACKNOWLEDGEMENT ABSTRACT ABSTRAK TABLE OF CONTENTS LIST OF TABLES LIST OF FIGURES LIST OF ABBREVIATIONS LIST OF APPENDICES

ii iii iv v vi vii xi xii xv xvi

INTRODUCTION 1.1 1.2 1.3 1.4 1.5 1.6 1.7 Background Problem Background Objectives Scope of the Project Project Outcome Thesis Organization Project Duration

1 1 2 2 3 4 4 5

LITERATURE REVIEW 2.1 2.2 Chapter Overview Previous Projects

6 6 7

viii

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

METHODOLOGY 3.1 3.2 Chapter Overview Design Housing Zone 3.2.1 Ground Floor 3.2.2 First Floor 3.2.3 Roof 3.3 Project Flow 3.3.1 Understanding 3.3.2 Literature Review 3.3.3 Hardware and Software

24 24 24 25 26 27 27 28 28 28

ix

3.3.4 Implementation 3.3.5 Test and Improve

29 29 30 30 30 30 32 33 35 36 38 39 39 41 42 42 43 43 44 46 46 48 49 50 52 52 54

PROJECT IMPLEMENTATION 4.1 4.2 Chapter Overview Remote Control 4.2.1 Hardware Implementation 4.2.2 Programming 4.2.3 Functions 4.2.4 Security 4.2.5 Arm and Disarm Zones Individually 4.2.6 Problem 4.3 Transmitter 4.3.1 Hardware Implementation 4.3.2 Programming 4.3.3 Data Bits of Encoder 4.3.4 Status Checking 4.3.5 Problem 4.3.5.1 Interrupt 4.3.5.2 Toggle Switch 4.4 Receiver 4.4.1 Hardware Implementation 4.4.2 Specify Encoder and Decoder 4.4.3 Programming 4.4.4 Interrupt 4.4.5 Arm and Disarm Zones Individually 4.4.6 Alarm 4.4.7 Status Checking

SIMULATION AND RESULTS 5.1 5.2 Chapter Overview Simulation 5.2.1 Remote Control

56 56 56 57

5.2.2 5.3 Results 5.3.1

Receiver

60 62

Outcome of Project 5.3.1.1 Alarm Function 5.3.1.2 Status Checking Function

63 63 67 69 70

5.3.2 5.4

Project Cost

Limitations

CONCLUSION & RECOMMENDATION 6.1 6.2 Conclusion Recommendation for Future Works

71 71 72

REFERENCES APPENDICES A-C

73 75-95

xi

LIST OF TABLES

TABLE NO. 1.1 2.1 2.2 4.1 4.2 4.3 4.4 5.1

TITLE Gantt Chart for 2 Semesters Transmission Distance Pin Outs of D-sub-9 Connector Options for Remote Control Function of each Keypad Button Data Bits for Status Checking and Alarm Time Frame to Send Signals for Status Checking Project Cost

PAGE 5 14 21 34 34 42 43 69

xii

LIST OF FIGURES

FIGURE NO. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 3.1 3.2 3.3 3.4 4.1 4.2 4.3 4.4 4.5 IC LM7805 Regulator Circuit

TITLE

PAGE 10 10 11 12 13 13 14 15 15 16 17 19 20 21 22 25 26 27 27 31 32 33 39 40

Encoder HT12E and Decoder HT12D Pin Assignments of HT12E and HT12D Transmitter Module TX-433 & TX-315 Receiver Module RX-433 & RX-315 16X2 LCD Pin Description of LCD 4X4 Keypad Construction of Keypad using SPST Switches Pin Assignments of PIC16F877A Microcontroller Interfaces with External Devices Pin Assignments of MAX232 IC D-sub-9 Male and Female Circuit Diagram for Bootloader with DB9 Ground Floor First Floor Roof Project Flow PIC16F877A Wiring Connection at Remote Control Encoder HT12E & Transmitter Wiring Connection Block Diagram of Remote Control Program PIC16F877A Wiring Connection at Transmitter Encoder HT12E & Transmitter Wiring Connection

xiii

4.6 4.7 4.8 4.9

Block Diagram of Transmitter Program Ideal Switching Versus Real Switching PIC16F877A Wiring Connection at Receiver Decoder HT12D (Remote Control) and Receiver Module Circuit

41 45 46

47 47

4.10 4.11

Flow Chart of Decoder HT12D Decoder HT12D (Transmitter) and Receiver Module Circuit

48 49 50 57 57 58 58 58 58 59 59 60 61 62 63 64 64 64 64 64 65 65 65 66 66

4.12 4.13 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 5.23

Block Diagram for Interrupt at Receiver Block Diagram for Receiver Program Start Up Screen Request Password Password Rejected and Access Denied Screen Password Accepted Screen Action Screen Arm and Disarm System Zone 1 Off and Zone 2 On Screen Status Checking Screen Connections of Receiver for Simulation LEDs Show the Data to Encoder Simulation at Receiver when System Armed Standby Mode of Remote Control Password Request Screen Password Accepted Display at LCD Access Denied Display at LCD Password Rejected Display at LCD Action Display at LCD Armed System Display at LCD All Zones LEDs are Turned On Zone 2 Off Display at LCD Zone 2 is Turned Off Zone 1 is Alarmed Transmitter Zone 2 and the Output for Status Checking

xiv

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

67

68 68

xv

LIST OF ABBREVIATIONS

PC GSM SMS PIC IC LCD HMI SPST CPU I/O EEPROM

Personal Computer Global System for Mobile Communications Short Message Service Peripheral Interface Controller Integrated Circuit Liquid Crystal Display Human Machine Interface Single Pole Single Throw Central Processing Unit Input or Output Electrically Erasable Programmable Read Only Memory

ADC TTL RAM ROM ISR `

Analogue to Digital Converter TransistorTransistor Logic Random Access Memory Read-Only Memory Interrupt Subroutine

xvi

LIST OF APPENDICES

APPENDIX A B C

TITLE Program Code for PIC at Remote Control Program Code for PIC at Transmitter Program Code for PIC at Receiver

PAGE 75 85 88

CHAPTER 1

INTRODUCTION

1.1

Background

From the Royal Malaysian Polices [1] statistic for robbery cases reported, it showed that the robbery cases are increasing dramatically from year 2000 to year 2006. These cases increased from 12 000 cases to 18 000 cases which is approximately 1000 cases increased per year. This statistic indicates the importance of implementing security alarm system in residential area. Furthermore, it is crucial to has advanced alarm system which could secure the premises.

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 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

JUL AUG SEP OCT NOV DEC JAN FEB MAR APR

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 Open Field Apartment Building Single Family Home Average Distance (meter) 65 28 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 3 2 7 8 6 5 1 Signal Direction DTE-to-DCE DCE-to-DTE DTE-to-DCE DCE-to-DTE DCE-to-DTE x DCE-to-DTE Signal Name Transmitted Data Received Data Request To Send Clear To Send Data Set Ready Signal Ground Received Line Signal Detector (Carrier Detect) 4 9 DTE-to-DCE DCE-to-DTE Data Terminal Ready 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 3 Roof f

The roof is divid into 2 zo ded ones as in fi igure 3.3. In nside the roo motion se of ensors can c be place ed.

Figure 3.3: Roof

3.3 3

Proje Flow ect

Ther are certain steps follow in order to conduct this project as shown be re n wed r elow. Understanding Literature R L Review Ha ardware & S Software Implementation Tes & Improve System st e Figu 3.4: Proj Flow ure ject

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 1 ZONE 4 4 ZONE 7 7 RETURN * ZONE 2 2 ZONE 5 5 ZONE 3 3 ZONE 6 6 ARMED A DISARMED B

8 9 C ALARM OFF CONFIGURE STATUS CHECKING STATUS CHECKING CONFIGURED # D 0

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"); Lcd_Custom_Out(2, 5, "REJECTED"); Delay_ms(1000);}}

// indicate password is wrong

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 { kp = 0; do { kp = Keypad_Released(); k = kp; } while (!kp); action(); } while (k!=13); // scan keypad

// function repeat until press *

Code to arm and disarm zone one: if (k==1) { i++; if(i==1) {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) {portc = 0x00; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_1_on); Lcd_Custom_Out(1,1,text); i=0;} // button one pressed // arm zone one

// disarm zone 1

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 1 2 3 4 5 6 7 DATA BITS : STATUS CHECKNIG 1001 1010 1011 1100 1101 1110 1111 ALARM 0001 0010 0011 0100 0101 0110 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 1 2 3 4 5 6 7 TIME FRAME (mins) 30 60 90 120 150 180 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; INTCON.f7=1; INTCON.f4=1; // Configure port B // Inform PIC that interrupt is used // RB0 will be used as interrupt

ISR code for transmitter: void interrupt(){ Delay_ms(50); if(portb.f0==1){ zone_checker(); portb.f4=0; portb.f3=0; delay_ms(1000); portb.f3=1;} INTCON.f1 = 0;} 4.4 Receive // delay to avoid contact bounce

// clear the int flag

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(); if(x==0){ zone_check(); x++;} status_checking(); INTCON.f1 = 0;}

// check for alarm

// status checking

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) {y++; if(y==1){ portb.f7=0; delay_ms(1500);} if(y==2){ portb.f7=1; y=0; delay_ms(1500);}} // when zone 1 button pressed at remote control // zone 1 light will off

// zone 1 light will on

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) {portd.f0=0;} // when button D pressed // 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) {kp=0; do{ Delay_ms(10000); kp=kp++;} while(kp!=20) // if alarm is high // alarm stop automatically in 20mins

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) {portb=0xFE;} // when arm button press, all light will on

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 PIC16F877A LCD 16X2 4X4 keypad HT12E HT12D TX-433 TX-315 RX-433 RX-315 Crystal 20Mhz Other Cost per unit (RM) 25 35 30 4.50 4.50 25 25 35 35 3.50 30 Unit 3 1 1 2 2 1 1 1 1 3 1 TOTAL Total cost (RM) 75 35 30 9 9 25 25 35 35 10.50 30 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 bidirectional 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.

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.

Johari bin Kasim, Camalil bin Omar, Abd. Hamid bin Ahmad. Sistem Elektronik Edisi 2. Universiti Teknologi Malaysia, 2006. Holtek Semiconductor Inc. HT12A/HT12E 212 Series of Encoders. April 11, 2000. Holtek Semiconductor Inc. HT12D/HT12F 212 Series of Decoders. November 18, 2002.

6.

7.

8.

Cytron Technologies. RF Transmitter Module Datasheet. June 2008.

9.

Cytron Technologies. RF Receiver Module Datasheet. June 2008.

74 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 Lawrence A. Duarte. The Microcontroller Beginners Handbook. 2nd Edition. United States of America: Prompt Publication. 3-5; 1998.

13.

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

75 APPENDIX A

Program Code for PIC at Remote Control ============================================================ ; File name: remote.c ; Project: Wireless Home Security System ; Programmer: Logeswaran A/L Arumugam ; Date: 2/2/2009 ; Supervisor: PM Zamani Md Zain ;============================================================ ;======================= 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";

76 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) *dest++ = *source++; *dest = 0 ;} ;======================= Main Function =========================== void main(){ TRISD = 0; TRISC = 0; PORTC = 0; Keypad_Init(&PORTB);

// Configure port D as output // Configure port C as output // Initialize port C as 0 // Initialize keypad

/*Initialize LCD connected to PORTB*/ Lcd_Custom_Config(&PORTD,7,6,5,4,&PORTD,2,0,3); do{ portc=0b00000001; // initialize port c portd.f0=0; // initialize port d pin no RD0 as 0 Delay_ms(1000); Lcd_Custom_Cmd(LCD_CURSOR_OFF); Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display strConstCpy(text,welcome_home); Lcd_Custom_Out(1,3,text); // Print welcome home at LCD kp = 0; do { kp = Keypad_Read(); } while (!kp); x=0; do { x++; password(); Delay_ms(500); // scan keypad

// ask for password to operate // the system by scanning keypad

77 compare_password(); // compare password } while (!( va1==pass1 && va2==pass2 && va3==pass3 && va4==pass4) && (x!=3)); if ((x==3) && !( va1==pass1 && va2==pass2 && va3==pass3 && va4==pass4)) {infinite_loop();} // infinite loop if compare indicate not // match 3 times password Lcd_Custom_Cmd(Lcd_CLEAR); Lcd_Custom_Out(1,1, "ACTION:"); do { kp = 0; do { kp = Keypad_Released(); k = kp; } while (!kp); action(); } while (k!=13); }while (1);}

// Print Action: at LCD // scan keypad for action // scan keypad

// function repeat until press * // function will keep repeating

;======================= Password Subroutine ====================== void password(){ Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display strConstCpy(text,please_enter); // convert storage from ROM to RAM 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); kp =0; do { kp = Keypad_Released(); pass2 = kp; } while (!kp); Lcd_Custom_Out_Cp("X"); // scan for 4 digits password (2nd)

78 Delay_ms(200); kp =0; do { kp = Keypad_Released(); pass3 = kp; } while (!kp); Lcd_Custom_Out_Cp("X"); Delay_ms(200); // scan for 4 digits password (3rd)

kp =0; // scan for 4 digits password (4th) do { kp = Keypad_Released(); pass4 = kp; } while (!kp); Lcd_Custom_Out_Cp("X"); Lcd_Custom_Cmd(LCD_CURSOR_OFF);}

;======================= Infinite Loop Subroutine =================== void infinite_loop(){ while(1) { // keep looping Lcd_Custom_Cmd(Lcd_CLEAR); Lcd_Custom_Out(1, 3, "ACCESS DENIED"); Delay_ms(1000);}} ;======================= Action Subroutine ======================== void action(){ if (k==1) {i++; if(i==1) {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) {portc = 0x00; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_1_on);

// ZONE 1

79 Lcd_Custom_Out(1,1,text); i=0; Delay_ms(700); portd.f0=0; delay_ms(500); portc.f0=1;}} if (k==2) {j++; if(j==1){ portc = 0x08; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_2_off); Lcd_Custom_Out(1,1,text); Delay_ms(700); portc=0; delay_ms(500); portc.f0=1;} if(j==2){ portc = 0x08; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_2_on); Lcd_Custom_Out(1,1,text); j=0; Delay_ms(700); portc=0; delay_ms(500); portc.f0=1;}} if (k==3) {l++; if(l==1){ portc = 0x08; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_3_off); Lcd_Custom_Out(1,1, text); Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} if(l==2){ portc = 0x08; // ZONE 3

// ZONE 2

80 portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_3_on); Lcd_Custom_Out(1,1, text); l=0; Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;}} if (k==4){ portc = 0x04; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,arm_system); Lcd_Custom_Out(1,1, text); i=0,j=0,l=0,m=0,n=0,b=0,v=0; Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} sub();} void sub() { if (k==5) {m++; if(m==1){ portc = 0x04; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_4_off); Lcd_Custom_Out(1,1, text); Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} if(m==2){ portc = 0x04; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_4_on); Lcd_Custom_Out(1,1, text); m=0; // ARM WHOLE SYSTEM

// ZONE 4

81 Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;}} if (k==6) {n++; if(n==1){ portc = 0x0C; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_5_off); Lcd_Custom_Out(1,1, text); Delay_ms(700); portc=0; delay_ms(500); portc.f0=1;} if(n==2){ portc = 0x0C; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_5_on); Lcd_Custom_Out(1,1, text); n=0; Delay_ms(700); portc=0; delay_ms(500); portc.f0=1;}} if (k==7) {b++; if(b==1){ portc = 0x0C; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_6_off); Lcd_Custom_Out(1,1, text); Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} if(b==2){ portc = 0x0C; // ZONE 6 // ZONE 5

82 portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_6_on); Lcd_Custom_Out(1,1, text); b=0; Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;}} if (k==8) {portc = 0x02; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,disarm_system); Lcd_Custom_Out(1,1, text); i=1,j=1,l=1,m=1,n=1,b=1,v=1; Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} if (k==9) {v++; if(v==1){ portc = 0x02; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_7_off); Lcd_Custom_Out(1,1, text); Delay_ms(700); portd.f0=0; portc=0; delay_ms(500); portc.f0=1;} if(v==2){ portc = 0x02; portd.f0=1; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,zone_7_on); Lcd_Custom_Out(1,1, text); v=0; Delay_ms(700); portd.f0=0; // DISARM WHOLE SYSTEM

// ZONE 7

83 portc=0; delay_ms(500); portc.f0=1;}}

if (k==14) {portc = 0x0E; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,stat); Lcd_Custom_Out(1,1, text); strConstCpy(text,configured); Lcd_Custom_Out(2,1, text); Delay_ms(700); portc=0; delay_ms(500); portc.f0=1;} if (k==15){ portc = 0x0A; portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR); strConstCpy(text,configure); Lcd_Custom_Out(1,1, text); 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){ 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;}}

// Configured Status Checking

// Configure status checking

// off alarm

84

;======================= 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); Lcd_Custom_Cmd(Lcd_CURSOR_OFF); Lcd_Custom_Out(1, 1, "PASSWORD"); Lcd_Custom_Out(2, 5, "REJECTED"); Delay_ms(1000);}}

// Clear display // Turn cursor off // indicate password is wrong

;=======================END OF PROGRAM====================

85 APPENDIX B

Program Code for PIC at Transmitter ============================================================ ; File name: transmitter.c ; Project: Wireless Home Security System ; Programmer: Logeswaran A/L Arumugam ; Date: 2/2/2009 ; Supervisor: PM Zamani Md Zain ;============================================================ ;======================= Define Variables ======================== int i,k,k1; void zone_checker(); void status_checking(); ;========================= Interrupt =========================== void interrupt(){ Delay_ms(50); 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 ;======================= Main Function ========================== void main () { trisb= 0b00000001; portb= 0b00001000; INTCON.f7=1; INTCON.f4=1; trisc= 0b11110000; portc= 0; trisd= 0b00001100; portd= 0; while(1){ status_checking();}}

//going to use an interrupt //RB0 will be an interrupt

86 ;======================= Zone Checker Subroutine ================== void zone_checker(){ if(portc.f4==0 && portd.f3==0 && portd.f2==1 ) // zone 1 {portb.f5=0; portb.f6=0; portb.f7=1;} if(portc.f4==0 && portd.f3==1 && portd.f2==0 ) {portb.f5=0; portb.f6=1; portb.f7=0;} if(portc.f4==0 && portd.f3==1 && portd.f2==1 ) {portb.f5=0; portb.f6=1; portb.f7=1;} if(portc.f4==1 && portd.f3==0 && portd.f2==0 ) {portb.f5=1; portb.f6=0; portb.f7=0;} if(portc.f4==1 && portd.f3==0 && portd.f2==1 ) {portb.f5=1; portb.f6=0; portb.f7=1;} if(portc.f4==1 && portd.f3==1 && portd.f2==0 ) {portb.f5=1; portb.f6=1; portb.f7=0;} // zone 2

// zone 3

// zone 4

// zone 5

// zone 6

if(portc.f4==1 && portd.f3==1 && portd.f2==1 ) // zone 7 {portb.f5=1; portb.f6=1; portb.f7=1;}} ;======================Status Checking Subroutine=================== void status_checking(){ portb.f4=1; if( portc.f4==0 && portd.f3==0 && portd.f2==1 ) //zone 1 {for(i=0;i<10;i++){ Delay_ms(1000);} zone_checker(); portb.f3=0; delay_ms(1000); portb.f3=1;} if( portc.f4==0 && portd.f3==1 && portd.f2==0) //zone 2

87 {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) {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) {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) {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) {for(i=0;i<60;i++){ Delay_ms(1000);} zone_checker(); portb.f3=0; delay_ms(1000); portb.f3=1;} //zone 3

//zone 4

//zone 5

//zone 6

if( portc.f4==1 && portd.f3==1 && portd.f2==1) //zone 7 {for(i=0;i<70;i++){ Delay_ms(1000);} zone_checker(); portb.f3=0; delay_ms(1000); portb.f3=1;}} ;===================== END PROGRAM ==========================

88 APPENDIX C

Program Code for PIC at Receiver

============================================================ ; File name: receiver.c ; Project: Wireless Home Security System ; Programmer: Logeswaran A/L Arumugam ; Date: 2/2/2009 ; Supervisor: PM Zamani Md Zain ;============================================================ ;======================= Define Variables ======================== unsigned short kp; 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 ;======================= Main Function =========================== void main(){ trisb = 0b00000001; // Configure port B portb = 0; // Initialize port B as 0 INTCON.f7=1; // going to use an interrupt INTCON.f4=1; // RB0 will be an interrupt ADCON1 = 0x06 ; // Changes PORTA to digital CMCON = 0x07 ; // Disable analog comparators TRISA = 0x0F ; // Configure port A

89 PORTA = 0; TRISC = 0x0F; PORTC = 0; TRISD = 0x00; PORTD = 0; while(1) { remote(); if(portd.f0==1) {kp=0; do{ Delay_ms(1000); kp=kp++; remote1();} while(kp!=15); do {portd.f0=0;} while(1);}}} // Initialize port A as 0 // Configure port C as input // Initialize port C as 0 // Configure port D as output // Initialize port D as 0

// alarm will stop automatically in 15s // if not turn off

// turn off alarm and keep looping

;======================= Remote Subroutine ======================== void remote(){ if(n!=2){ if(porta==0x02) // when arm button press, all light will on {portb=0xFE; y=0,q=0,o=0,e=0,l=0,t=0,u=0;} if(porta==0b000001) // when disarm button, all light will off {portb=0b00000000; portd.f0=0; y=1,q=1,o=1,e=1,l=1,t=1,u=1;} if(porta==0b000101) {status_configure();} if(porta==0b001101) {portd.f0=0;} if(porta==0b001000) {y++; if(y==1){ portb.f7=0; delay_ms(1500);} if(y==2){ portb.f7=1; y=0; delay_ms(1500);}} // configure status checking

// alarm off press, system alarm off

// when zone 1 button press, // zone 1 disarmed

// zone 1 armed

90 if(porta==0b000100) {q++; if(q==1){ portb.f6=0; delay_ms(1500);} if(q==2){ portb.f6=1; q=0; delay_ms(1500);}} if(porta==0b001100) {o++; if(o==1){ portb.f5=0; delay_ms(1500);} if(o==2){ portb.f5=1; o=0; delay_ms(1500);}} if(porta==0b001010) {e++; if(e==1){ portb.f4=0; delay_ms(1500);} if(e==2){ portb.f4=1; {portb.f4=0;} e=0; delay_ms(1500);}} if(porta==0b000110) {l++; if(l==1){ portb.f3=0; delay_ms(1500);} if(l==2){ portb.f3=1; l=0; delay_ms(1500);}} // when zone 2 button press, // zone 2 disarmed

// zone 2 armed

// when zone 3 button press, // zone 3 disarmed

// zone 3 armed

// when zone 4 button press, // zone 4 disarmed

// zone 4 armed

// when zone 5 button press, // zone 5 disarmed

// zone 5 armed

91 if(porta==0b001110) {t++; if(t==1){ portb.f2=0; delay_ms(1500);} if(t==2){ portb.f2=1; t=0; delay_ms(1500);}} if(porta==0b001001) {u++; if(u==1){ portb.f1=0; delay_ms(1500);} if(u==2){ portb.f1=1; u=0; delay_ms(1500);}}} // when zone 6 button press, // zone 6 disarmed

// zone 6 armed

// when zone 7 button press, // zone 7 disarmed

// zone 7 armed

;======================= Remote1 Subroutine ======================= void remote1(){ if(porta==0b000001) // when disarm button, all light will off {portb=0b00000000; portd.f0=0; kp=15;} if(porta==0b001101) {portd.f0=0; kp=15;}} // alarm off press, system alarm off

;======================= Status Configure ========================= void status_configure(){ do{ if(porta==0b001000) // deactivate zone 1 {qq=1;} if(porta==0b000100) // deactivate zone 2 {oo=1;} if(porta==0b001100) // deactivate zone 3 {ee=1;} if(porta==0b001010) // deactivate zone 4 {ll=1;} if(porta==0b000110) // deactivate zone 5 {tt=1;}

92 if(porta==0b001110) // deactivate zone 6 {uu=1;} if(porta==0b001001) // deactivate zone 7 {hh=1;} }while(porta!=0b000111);} ;======================= Status Checking ========================= void status_checking(){ k++; if(k==1){ // zone 1 status checking if(qq==1) {k=2;} else {if(portc.f0==1 && portc.f1==0 && portc.f2==0 && portc.f3==1) {portd=0x10;} else{ portd=0x10; while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==2){ // zone 2 status checking if(oo==1) {k=3;} else {if(portc.f0==1 && portc.f1==0 && portc.f2==1 && portc.f3==0) {portd=0x20;} else{ portd=0x20; while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==3){ // zone 3 status checking if(ee==1) {k=4;} else {if(portc.f0==1 && portc.f1==0 && portc.f2==1 && portc.f3==1) {portd=0x30;} else{ portd=0x30;

93 while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==4){ // zone 4 status checking if(ll==1) {k=5;} else {if(portc.f0==1 && portc.f1==1 && portc.f2==0 && portc.f3==0) {portd=0x40;} else{ portd=0x40; while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==5){ // zone 5 status checking if(tt==1) {k=6;} else {if(portc.f0==1 && portc.f1==1 && portc.f2==0 && portc.f3==1) {portd=0x50;} else{ portd=0x50; while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==6){ // zone 6 status checking if(uu==1) {k=7;} else {if(portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==0) {portd=0x60;} else{ portd=0x60; while(1){ portd.f0=1;

94 delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==7){ // zone 7 status checking if(hh==1) {k=0;} else {if(portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==1) {portd=0x70; k=0;} else{ portd=0x70; while(1){ portd.f0=1; delay_ms(2000); portd.f0=0; delay_ms(2000); }}}} if(k==8) {x=0;}} ;======================= Zone Check ========================== void zone_check(){ if( portc.f0==1 && portc.f1==0 && portc.f2==0 && portc.f3==1) //zone 1 status {k=0;} if( portc.f0==1 && portc.f1==0 && portc.f2==1 && portc.f3==0) //zone 2 status {k=1;} if( portc.f0==1 && portc.f1==0 && portc.f2==1 && portc.f3==1) //zone 3 status {k=2;} if( portc.f0==1 && portc.f1==1 && portc.f2==0 && portc.f3==0) //zone 4 status {k=3;} if( portc.f0==1 && portc.f1==1 && portc.f2==0 && portc.f3==1) //zone 5 status {k=4;} if( portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==0) //zone 6 status {k=5;} if( portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==1) //zone 7 status {k=6;} if(portd.f0==1) // when alarm is ring {k=7; x=0;} if(portd.f0==0&& portc.f0==0) {k=7; x=0;}}

95 ;======================= Alarm Subroutine ======================== void alarm(){ if( portc.f0==0 && portc.f1==0 && portc.f2==0 && portc.f3==1 && portb.f7==1) {portb=0x80; // zone 1 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==0 && portc.f2==1 && portc.f3==0 && portb.f6==1) {portb=0x40; // zone 2 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==0 && portc.f2==1 && portc.f3==1 && portb.f5==1) {portb=0x20; // zone 3 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==1 && portc.f2==0 && portc.f3==0 && portb.f4==1) {portb=0x10; // zone 4 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==1 && portc.f2==0 && portc.f3==1 && portb.f3==1) {portb=0x08; // zone 5 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==1 && portc.f2==1 && portc.f3==0 && portb.f2==1) {portb=0x04; // zone 6 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0 && portc.f1==1 && portc.f2==1 && portc.f3==1 && portb.f1==1) {portb=0x02; // zone 7 alarmed portd.f0=1; x=0; n=2;} if( portc.f0==0) {x=0;}} ;=======================END OF PROGRAM====================

You might also like