A report submitted in partial fulfillment of the requirement for the award of the degree of Bachelor of Engineering (Electrical – Mechatronic)

Faculty of Electrical Engineering Universiti Teknologi Malaysia

APRIL 2010


in thankful appreciation for support.iii Dedicated. encouragement and understandings to my beloved mother and father. and as well as my supportive friends . brother and sister.

His remarkable ideas and suggestions will be much appreciated in the long run of my career. . My sincere appreciation also goes to my family especially my father Nordin Bin Sani and my beloved mothers Salmiah Binti kamal who has been so tolerant and supportive in all these years either morally or financially. I would like to express my warmest gratitude to my supportive supervisor. I would like to take this opportunity to express my grateful to ALLAH because give me a good health and destiny to me finish this project. I thank you from the bottom of my heart.iv ACKNOWLEDGEMENT First and foremost. Mohd Ariffanan Bin Mohd Basri who has provided immeasurable support and guidance toward the completion of my research project. I also would like thank to all my friends who had given me helps technically and mentally throughout my journey in completing my project. I wish you all the best in life and hope that our friendship will last forever. love and emotional supports that they had given to me all this while. Secondly. En. Thanks for their continuous encouragement.

this project is developed to control a home appliance.v ABSTRACT In Malaysia. the project can be developing to make our home secure and safe. almost every day house theft cases reported in local newspapers. today many people are facing difficulties to control home appliances. These cases have been one of the most serious problems that happen in our country. including killing. Based on the events above. theft and robbery when the home owners are not in the house. various methods can be used to overcome this problem. . So the purpose of project is to design and develop a home security system that can provide security against intrusion and other emergency situation using a wireless technology. Many people use criminal methods to sufficient their need of life. the thieves use a variety of ways. Not like other previous cases. The two detectors of motion sensor and magnetic contact sensors are used as the input of PIC and two home appliances are a fan and a lamp as home appliances to be controlled using a mobile phone. especially for the elderly and disabled. Therefore. This is because today. In addition to the house theft cases. Therefore. thieves nowadays are too aggressive and brutal. The main component to develop the project is using PIC 16F877A. Malaysia.

Kes kecurian rumah juga sering berlaku jika seseorang tiada di rumah. Peningkatan kes ini amat membimbangkan kerana ia boleh mendatangkan bahaya kepada orang ramai. pada zaman sekarang banyak kesulitan dihadapi untuk mengawal peralatan rumah terutama sekali bagi golongan tua dan cacat anggota. Antaranya adalah dengan menghasilkan satu sistem yang boleh menjaga dan mengawasi rumah walaupun ia ditinggalkan. Ini adalah kerana pada zaman sekarang pencuri menggunakan pelbagai cara termasuklah dengan cara membunuh asalkan ia dapat memenuhi kemahuan mereka. Dengan ini. Disamping itu pencuri pada zaman sekarang sering bertindak secara agresif dan brutal. Projek ini adalah untuk menghasilkan satu sistem keselamatan rumah menggunakan teknologi tanpa wayar.Projek ini dihasilkan dengan menggunakan PIC 16F877A sebagai peranti ABSTRAK Di Malaysia. tujuan utama projek ini dihasilkan adalah untuk mengatasi masalah tersebut. projek ini juga dihasilkan untuk memudahkan mengawal peralatan rumah. hampir setiap hari kes kecurian rumah dilapor dalam akhbarakhbar tempatan. . Dua pengesan iaitu “motion sensor” dan “magnetic contact sensor” digunakan sebagai masukan PIC dan dua jenis alat rumah iaitu kipas dan lampu dijadikan sebagai alat untuk dikawal dengan menggunakan telefon. Oleh itu. Selain kes kecurian rumah. pelbagai cara boleh digunakan bagi mengatasi masalah ini.Oleh yang demikian.

4 Objective 1.2 Background 1.vii TABLE OF CONTENTS CHAPTER DECLARATION DEDICATION TITLE PAGE ii iii iv v vi vii xi xii xiv xvi ACKNOWLEDGEMENT ABSTRACT ABSTRAK TABLE OF CONTENTS LIST OF TABLES LIST OF FIGURES LIST OF ABBREVIATIONS LIST OF APPENDICES 1 INTRODUCTION 1.1 Chapter Overview 1.3 Problem Statement 1.5 Scope of Project 1.6 Thesis Outline 1 1 1 2 3 4 4 .

1.2 Monitoring and Controlling of Device Using GSM by PRIYANKA from India 2.1 Similar Research Done by UTM Student 2.2.Previous Project Sensor 2.2 Software Review 10 10 10 11 11 12 13 14 15 16 9 9 9 .2.3 Reviews The Software and Hardware 2.1 Home Security System by CHUN-PAI JIMMY HSIEH AND YANG CAO from Cornell University 2.2 Others Related Projects 2.3 Mobile Phone Wireless Alarm System Using Microcontroller by MOHD ARIF BIN MD KURDI 2.4 MAX232 and D9 PIC 16F877A Microcontroller 2.3 “Sistem Rumah Penggera Kediaman Keselamatan Mudah Dan 8 7 5 5 6 6 6 Pintar” by MOHD ROSLI BIN MAMAT 2.1 Wireless Home Security System by LOGESWARAN A/L ARUMUGAM 2.3.2 Motion Sensor 2.2.5 RS-232 Serial Port Magnetic Contact Sensor Chapter Overview 2 LITERATURE REVIEW 2.1 Hardware Review 2.1.

1 Programming the hardware using MicroC 21 21 21 22 22 24 27 27 28 29 30 31 31 32 32 35 36 .3 The Work Flow For The Whole Project 3.2.ix 2.2.8 Serial Communication Interface Circuit 3.3.5 Interface PIC16F877A With Fan and Lamp AT COMMAND 16 17 17 18 18 19 3 METHODOLOGY Hardware Implementation Planning 3.4 Interface PIC16F877A With Magnetic Contact Sensor 3.1 MikroC 2.3.3 Overview of GSM Technology 2.3.1 Chapter Overview 3.3.6 Interface PIC16F877A With Buzzer 3.3.4 Advantages of GSM Microsoft Visual Basic 2008 2.2.7 In Circuit Serial Programming (ICSP) for Programming PIC Microcontroller 3.1 Make a Research and Study 3.2 Reset (MCLR) 3.4 Software Implementation 3.2 Stage of Methodology and Approach Voltage Regulator 3.5 GSM Modem Interface PIC16F877A With Motion Sensor 3.4.

1 For The Security System 4.3 To Exit The System 47 47 47 48 49 49 54 57 5 CONCLUSION AND SUGGESTION Graphic User Interface 3.2 For The Wireless Home Appliances Control 4.1 Chapter Overview 4.2 The Block Diagram for This Project 4.1 Conclusion 5.4.5 Analysis and Testing 3.2 Motion sensor programming 3.3 How Does it Work? 4.2 Limitations 5.4 The Result for This Project 4.5.3 Magnetic Contact Sensor Programming .4.4 Home Appliances (Fan and Lamp) Programming 3.4.x 3.3.1 Testing the AT COMMAND 43 44 44 38 40 42 4 RESULTS AND DISCUSSIONS 4.3 Suggestion and Future Development 58 58 59 59 REFERENCES Appendices A – D 60 61.

1 TITLE Example of AT COMMAND Baud Rate Formula PAGE 20 34 .1 3. 2.xi LIST OF TABLES TABLE NO.

8 3.4 The Overall System TITLE PAGE 7 8 11 12 Overall Wireless Home Security System Pin Out of PIC 16F877A The Picture Shows the Magnetic Sensor with Magnet 2.5 Motion Sensor Pin Assignments of MAX232 IC D-9 Connecter Configuration RS-232 PC Connector Flow of Methodology The Grant Chart for FYP 1 The Grant Chart for FYP 2 The Circuit of Voltage Regulator The Placement of Motion Sensor in a Hardware Prototype 13 14 14 15 21 26 26 27 29 3.1 2.8 3.1 3.xii LIST OF FIGURES FIGURE NO.3 2.5 This Picture Shows the Installation of Sensor and Magnet on the Door 12 2.5 2.11 The Circuit of Fan and Lamp to PIC The Connected of USB Programmer 31 32 .7 2.2 3.6 2.3 3.7 The Circuit of Motion Sensor to PIC The Placement of Magnetic Contact Sensor in a Hardware Prototype 29 30 3.10 3.9 The Circuit of Magnetic Contact Sensor to PIC The Placement of Fan and Lamp in a Hardware Prototype 30 31 3. 2.2 2.6 3.4 3.

11 4.16 3.4 4.xiii 3.15 3.12 4.7 4.9 The System Show When the Motion Sensor is Active 4.12 3.20 3.14 4.22 3.14 3.16 The Hardware Prototype Show a Lamp is Light The System Show a Lamp is Light The System Show a lamp is non active The Hardware Prototype Show a fan is Active The System Show a fan is Active The System Show a Fan is Non Active The System Show When the Exit Button Pressed 54 54 55 55 56 56 57 53 33 34 37 37 39 41 42 43 43 44 45 45 46 46 47 48 49 50 50 51 52 52 .10 4.21 3.1 4.6 4.13 3.23 3.24 3.25 4.8 The Serial Communication Interface Circuit The Hardware Prototype PICkit 2 Software Interface USB ICSP Programmer Device Flow Chart for Motion Sensor Programming Flow Chart for Magnetic Sensor Programming Flow Chart for ON/OFF Lamp Flow Chart for ON/OFF Fan Main of Graphic User Interface Output of Graphic User Interface The Hyper Terminal Connection Setup Hyper Terminal Com Port Setup The Interface for write AT command Testing The AT Command The Block Diagram for Security System The Block Diagram for Home Appliances Control The Main System The Login This System The Output Graphical User Interface The System Show User Chosen the Com Port The Hardware Prototype The System Show When the Magnetic Contact Sensor is Active 4.3 4.13 4.17 3.2 4.19 3.5 4.18 3.15 4.

xiv LIST OF ABBREVIATIONS BOR BRG CTS DCD DSR DTE DTR EEPROM Brownout Reset Baud Rate Generator Clear To Send Data Carrier Detect Data Set Ready Data Terminal Equipment Data Terminal Ready Electrically Erasable Programmable Read Only Memory Fosc GUI GSM IC ICSP LCD LED NC PDU PIC Oscillator’s Frequency Graphical User Interface Global System For Mobile Communications Integrated Circuit In-Circuit Serial Programming Liquid Crystal Light Emitter Diode Normally Closed Protocol Data Unit Peripheral Interface Controller .

xv PIR POR RAM RF RI ROM RSCR RTS RXD SIM SCI SMS TDMA TXD USART Passive Infrared Power-On Reset Random Access Memory Receiver Frequency Ring Indicator Read-Only Memory Receive Status And Control Register Request to Send Received Data Subscriber Identity Module Serial Communication Interface Short Message Service Time Division Multiple access Transmitted Data Universal Synchronous Asynchronous Receiver Transmitter UTM Universiti Teknologi Malaysia .

xvi LIST OF APPENDICES APPENDIX A B C D TITLE Main Board Circuit Schematic Programming For Hardware Programming For Interfacing Project Prototype PAGE 61 62 65 69 .

easy to install. occupy lesser space.CHAPTER 1 INTRODUCTION 1. The price depends on how advance the system is. This chapter also discusses the problem statement. the scope of the project and the thesis outline.2 Background Home wireless security systems are becoming increasingly popular and it is being a necessary nowadays. There are many products of Wireless Home Security Systems in the market. . Normally today home security system is in wireless form rather than wired form. There are many benefits to using these compared to conventional systems. easy for maintenance and more reliable. the objective of this project. The reasons are wireless can saves cost of wiring.1 Chapter Overview This chapter will briefly discuss on the project background. 1.

It is because it's the GSM is better than others wireless. television. The Multidimensional crisis like theft and robbery is one of the most serious problems that happen in this country. the project can be developing to make our home secure and safe. 1. It also can monitor the signal strength and more adaptable. Therefore in this project the GSM is the type of wireless that chooses. their house is empty and unguarded. . So this project is to design and develop a home security system that can provide security against intrusion and other emergency situation by alarm via short message service (SMS). The home appliances like fan. The capability of controlling home appliances in a wireless and remote fashion has provided a great convenience to many people in life. When they are away. most couples leave for work early in the morning and get back only in the evening. the wireless also capability become as an appliances control in the home.3 Problem Statement Nowadays. Through a wireless remote controller. Therefore case like theft and robbery is easy to occur because the home owners are not in the house. It is suitable to install the systems that need a wide range. Based on the events above. Most people also have to travel to other cities for their work. lamp. So it is suitable to become a controller for home appliances and for security system. We never anxious and worried anymore even we leave the house. washing machines and others. people can do remote operation without directly accessing the host of a home appliance. The based solution is to develop home security system using a wireless to keeps your house safe from intruders and enables you to work in peace.2 Besides that.

. The primary objective of this project is to design and develop a system that can control home appliances remotely with hand phone through SMS. Some are designed for very high security level protection and some are basic type. Another objective of this project is to produce the system that an inexpensive. Besides that. It is can be easy to simplify the daily works.4 Objective The main objective of this project is to design and develop a home security system that can provide security against intrusion and other emergency situation by alarm via short message service (SMS). 1. Most of the alarm systems are very expensive and therefore not affordable by poor or middle class families.friendly.3 Today there are a many wireless home security alarm system available in the market. user. small of size and easy to install. Some systems which cheaper in cost do not provide reliable features like status checking. The system can control two numbers of home appliances are lamp and fan only. To provide the public with a cost effective wireless security system. to develop and the system that can control and monitor the device in our home is a good matter. It is important because the system can be help the disabled and elderly through the realization of a fully automated home. it is important to design a low cost system with advanced features which ease the residents' life and benefits the public and also will decrease the crime rate of Malaysia. So this project will develops and design the home appliances that can control and monitoring the lamp and fan in the house.

an introduction of project is presented along with the project objective. In chapter 2 is begin with the literature review the previous project or thesis that related with this project. And the last chapter are summarizes this project. Then in this chapter also provides a review on the research of the components and software that are used in this project. . design circuit to make a connection to computer interface and mobile phone device. to make a connection between computer and hardware to mobile phone that support GSM modem by using AT command and suitable software.6 Thesis Outline This thesis is divided into five chapters. In the hardware part is to design circuit for the overall systems include the component. scope of this project and the expected outcome for this project. 1. To make interface in computer by using visual basic 2008. The chapter 3 are discusses the methodology and approach that used to develop this project. The chapter 4 are discusses the result and discussion.5 Scope of Project The scope of this projects are divide by two part that hardware and software. And then. 16F877A microcontroller and sensor that used. In chapter 1. In software part are programming the PIC microcontroller using MicroC compiler.4 1. Lastly. discusses of the limitation of this project and suggests possible future works.

This project also will recommend some future works that could be done to improve the same project. when reviewing the previous works or project a proper expect how this project can be conducted and the features that have to be added to make this project reliable and marketable are enlightened. Besides that. So this chapter discusses the projects and theses related to this project.CHAPTER 2 LITERATURE REVIEW 2. So there are some useful ideas that can be implemented in this project from other similar projects. there is a possibility to know what features are lacking in their projects. Therefore. And the other sources are books. by analysis the project did by other researchers. The main sources for this project are the previous project and thesis that is related to this project. It is very important to improve and to develop a successful project. By reviewing the previous works or .1 Chapter Overview Literature review was carried out throughout the whole project to gain knowledge and skills needed to complete this project. This chapter also discusses a related researches conducted by previous UTM students. journals and articles obtained from internet.

journals and articles are the right source to get it. The project is to develop an alarm system for a house. LCD. Then.2 Previous Project 2.1.1 Wireless Home Security System by LOGESWARAN A/L ARUMUGAM The project is to design the home security by alarm system. The alarm system should check the status of the transmitter of the system regularly to ensure that the system could function without any failure. It has been acquired and implemented in achieving the objectives of this project. 4X4 keypad. The knowledge is very important as guideline to determine the component and what software that be used for this project. transmitter and receiver module.6 project also have been referred to carefully before kick start this project to produce a better and more relevant system to the targeted market. encoder HT12E. The components that the project used are PIC16F877A microcontroller. So the books. The failure of the transmitter will be indicated at the receiver through LEDs and the buzzer beeping sound. the theories and related knowledge are also important matter to develop this project. 2. The remote can arm and disarm the whole system or each individual zone.1 Similar Research Done by UTM Student 2. The system can be operated through a password secured remote control.2. .2.

2. So that the owner will know at which zone the theft is hiding. The project are using PIC 16F877A microcontroller as a main controller.1: The Overall System .1. The house will be divided to eight different zones and each zone will have its own signal frequency. If there happened to be a security breach in the house which trigger a sensor at any one of the eight zones.2 Wireless Alarm System Using Microcontroller by MOHD ARIF BIN MD KURDI The project is to build an alarm system that can cover all places in the house and alert home owner instantly. The figure below show the overall system conducted by Mohd Arif Bin Md Kurdi : Keypad Sensor from 8 zones Transmitter Receiver Remote control LCD LED PIC 16F877A Buzzer Figure 2. 2. The siren and the flashing LED can be disarmed by using either remote control button or onboard disarming button. the transmitter will send a signal to the receiver. The receiver is connected to the microcontrollers which will automatically triggers the output siren and flash a LED that will indicate the zone of the security breach.7 There are some limitations in this project is only one transmitter and one receiver is built for this project so the system cannot perform bi-directional communication which allowed the receiver to send signals to transmitter to request the status of the transmitter because the communication between the transmitter and the receiver is only one way communication.

2. The PIC micro-controller which can do more functions beside trigger alarm. Antenna. RF module.1. The project limitations are: 1. The figure below show the overall system conducted by Mohd Rosli in Mamat : Figure 2.3 ‘Sistem Penggera Keselamatan Rumah Kediaman Mudah dan Pintar’ by MOHD ROSLI BIN MAMAT The project used the RF transmission and the project cover 4 to 5 zones.2.2: Overall Wireless Home Security System . 15 data only used for 5 zones. 3. Difficult to control because the system can be activated and deactivated through switching the power supply only. Big in size. PIC 16F877A microcontroller and alarm. 4. decoder. Encoder-decoder not fully utilized. Expensive due to the voltage regulator is an end product purchased from the market. 5.8 2. voltage regulator. The components that this project used are encoder.

2.2 Monitoring and Controlling Of Device Using GSM by PRIYANKA from India The project is designed and developed a wireless communication link to monitor and control equipments that are far away from user and also develop a higher security system to keep a check on them. 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.2. And at the receiver the GSM modem receives the massage from the mobile phone and gives it to the microcontroller which act to control the devices.9 2.2. The project is a digital home security system with voice feature which can monitor room temperature. 2.2. the project also using the temperature sensor. windows and doors. smoke. . This project are using ATMEL 89S52 microcontroller as an IC microcontroller. smoke detectors. In this project the security system will sound an alert when there is an attempt of break-in or if there is possible smoke or fire. and motion sensor. This is because the main control unit of the system is attached inside the house. Besides that.2 Others Related Projects 2. The project using the traditional magnetic switch equipped on doors and windows. This project built a wired home security system using different type of sensors.1 Home Security System by CHUN-PAI JIMMY HSIEH AND YANG CAO from Cornell University. motion. In this project at the transmitter is a mobile phone which uses certain codes corresponding to a particular relay to which the device is connected.2.

a 20MHz crystal oscillator and 2 units of 22pF capacitors. and serial programming (and reprogramming with flash memory) capability. derived from the PIC1640 originally developed by General Instrument's Microelectronics Division. Program memory is provided by 8K words of flash Memory. and single 5V In-Circuit Serial Programming (ICSP) capability. One type of data memory is a 368-byte RAM (random access memory) and the other is 256-byte EEPROM (Electrically erasable programmable ROM). availability of low cost or free development tools. Power consumption is less than 2mA in 5V operating condition.3.3.3 Reviews the Software and Hardware 2.1 PIC 16F877A Microcontroller PIC is a family of Harvard architecture microcontrollers made by Microchip Technology. wide availability. PICs are popular with developers and hobbyists alike due to their low cost. large user base. and data memory has two sources. is high with 25mA. The additional components that you need to make this IC work are just a 5V power supply adapter. The sink/source current. This IC can be . Apart from that.10 2.1 Hardware Review 2. The core feature includes interrupt capability up to 14 sources.1. It has two types of internal memories. extensive collection of application notes. it is also very easy to be assembled. PIC16F877A is so popular because it is very cheap. which indicates a driving power from I/O port. power saving sleep mode. The name PIC initially referred to "Programmable Interface Controller. These memories are program memory and data memory.

000 times. the switch will close and vice versa. When the reed switch is in close proximity to the magnet.3. When the door is opened. Figure 2.1.3. . Below shows PIC 16F877A and its pin out.3: Pin Out of PIC 16F877A 2. the two parts are in close contact and hence the switch is closed. namely a magnet and a reed switch. Therefore it is very good for new product development phase.1.2 Sensor 2.1 Magnetic Contact Sensor Magnetic contacts are usually NC (Normally Closed) and are used on doors and windows. Usually the magnet is fitted to the door and the reed switch is fitted to the door frame in close proximity to one another such that when the door is closed.2.11 reprogrammed and erased up to 10. It is consists of two parts.

The sensor can fix near the door to .3.5: This picture shows the installation of Sensor and magnet on the door.2 Motion Sensor This Motion/ PIR Sensor Switch can detect the Infrared rays released by Human Body Motion within the Detection Area (6 Meters).4: The Picture Shows the Magnetic Sensor with Magnet Figure 2. The PIR (Passive Infrared) sensor can sense even at night time.2. 2. Figure 2.1.12 the magnet will be a distance away from the reed switch and hence the switch will open.

13 check the motion near to the door. This mobile phone is support with GSM. So this project used the mobile phone as a GSM Modem.3 Mobile Phone Today’s technology make the possessing of a mobile a basic commodity and the trends in wireless technology is changing from day to day. The mobile phone can be controlled and customized to various levels by using the standard AT Command. ready to use. So if someone enters into the detection area of the sensor.3. Today the emphasis is on how to develop remote devices operate without the presence of man in order to reduce the time factor and labor. It is a multi-functional. the microcontroller will read it and inform the mobile and you can hear a voice alarm "Motion Detected". For this project K770i Sony Ericson are chosen as a mobile phone. and thus making the controlling of any electronic devices through a touch cell phone with one SMS is possible. .1. Figure 2.6: Motion Sensor 2. rugged unit that can be embedded or plugged into any application.

4 MAX232 and D9 MAX232 was created for one purpose.9: D-9 Connecter Configuration . to interface between Data Terminal Equipment (DTE) and Data Communications Equipment (DCE) employing serial binary data interchange.3. The RS-232 serial port is using D-sub-9 to connect with PC. MAX232 is an IC which is used to change signals from a RS-232 serial to match the circuit it interfaces with.8: Pin Assignments of MAX232 IC The D-subminiature-9 or D-sub-9 is an electrical connector which is commonly used in computers. In this case. Figure 2. So as stated the DTE is the terminal or computer and the DCE is the modem or other communications device.14 2. the D-sub-9 female is used to connect with male D-sub-9 connector at PC. Figure 2.1.

Both synchronous and asynchronous transmissions are supported by the standard. A nine pin D plug has become the standard fitting for the serial ports of PC. Its hardware can be used for serial communication up to distances of 50 feet. Figure 2. signaling from a Data Terminal Equipment (DTE) to the attached Data Circuit-terminating Equipment (DCE) or the reverse.2.1. Ring Indicator (RI) . The connector on the PC has male pins. user data is sent as a time-series of bits. Data Set Ready (DSR) Pin7 = Output. which is. Transmitted Data (TXD) Pin4 = Output. The pin connection uses are shown in Table 2. Clear To Send (CTS) Pin9 = Input. Therefore the mating cable needs to terminate in a DB9/F (female pin) connector. RS-232 is limited to point-to-point connection between PC serial ports and devices.3. Data Terminal Ready (DTR) Pin5 = Signal Ground Pin6 = Input.15 2.5 RS-232 Serial Port RS-232 is a popular communication protocol for connecting modems and data acquisition devices to computer. Received Data (RXD) Pin3 = Output. In RS-232.10: RS-232 PC Connector Pin1 = Input. Data Carrier Detect (DCD) Pin2 = Input. Request to Send (RTS) Pin8 = Input. Each data or control circuit only operates in one direction.

MicroBootloader This is a function to burn the program in hex file into the PIC through the specified Boot loader to the respective PIC. It supports languages such as assembly. EEPROM Editor Built. Applications for PIC can be developed quickly and easily with many practical examples provided in MikroC. particularly useful when working with LCD display.16 2. For example: 1. The output format is usually in assembly. The MikroC includes a number of useful implemented tools to help in developing the application more quickly and comfortably. ANSI (with minor modifications) and so on. RTS and DTR commands.baud rate control. . Binary or Hex. USART Terminal MikroC includes USART (Universal Synchronous Asynchronous Receiver Transmitter) terminal for RS232 communication EEPROM Editor allow you to easily manage EEPROM of PIC microcontroller.1 MikroC MikroC is an advanced and comprehensive C compiler for PIC MCUs. ASCII Chart ASCII Chart is a handy tool. 2.3.2. 3.2 Software Review 2. 4.

3.2. which is object oriented programming. TDMA solution was chosen in 1987. development of digital radio frequency.3. During the period of Evolution of mobile communication technologies various systems were introduced and deployed to achieve standardization in mobile industry but all the efforts were failed. Program logic determines the next instruction to execute in response to response to conditions and user request. Each of these windows objects produces a standard user interface that makes the program becomes user friendly.17 2. 2. .3 Overview of GSM Technology GSM stands for Global System for Mobile communication. That is when GSM Technology was introduced and problems like standardization. Multiple issues were sustained like incompatibility of systems. incompatibility etc were overcame. it is narrowband system and TDMA standards for Time Division Multiple access. text boxes and so on. Microsoft Visual Basic uses a different approach. rapidly expanding and successful technology. It is an event driven programming language where programs are no longer procedural or does not follow a sequential logic. This software allows the designed programs run under the windows without complexity associated with windows programming. Standard windows buttons can be hold on design screen such as command buttons.2 Microsoft Visual Basic 2008 The traditional languages are considered as procedural language where the program specifies the exact sequence of all operations. It is a huge.2.

such as the Wave com FASTRACK Modem. International roaming is technically possible within all country using the GSM system.3. a Bluetooth link or an infrared link. 3. With ISDN compatibility new services are offered. 6. A GSM modem can be an external modem device. External modem can be connected through a serial port. the system tolerates more intercell disturbances.4 Advantages of GSM The advantages of GSM are: 1. The large market increases competition and lowers prices both for investment and usage. 4. 7. 2.5 GSM Modem A GSM modem is a wireless modem that works with a GSM wireless network. The actual way to . GSM uses radio frequencies efficiently and due to the digital radio path. 2. 5. A wireless modem is similar to a dial up modem. Speech is encrypted and subscriber information security is guaranteed. and it can be categorized as follows: 1.3. The average speech quality is better than in analogue system. a USB port.2. There are three different types of GSM Modem.18 2. Data transmission is supported throughout the GSM system.2. The main differences between them is that a dial-up modem sends and receives data through a fixed copper telephone line while a wireless modem sends and receives data through radio waves or wireless networks.

A GSM modem can be a PC Card/PCMCIA Card installed in a notebook computer. For PDU mode. the message content that wish to send has to convert to HEX code before sending is made. the mobile has to test in order to determine which type of SMS mode it is supporting.3. one is called PDU mode and another is called text mode. AT command is only used to send out the SMS.2. 3. 2. For text mode. 2. such as the Nokia Card Phone. Therefore it’s easier if mobile phone that supports both modes is used. . In this project. A GSM modem could also be a standard GSM hand phone with the appropriate cable and software driver to connect to a serial port on your computer. The AT command can be write and tested through the hyper terminal. Need to insert a GSM Subscriber Identity Module (SIM) card into this modem. There are also mobile phones that support type of SMS mode.19 use depends on the capability of the GSM modem. The SMS mode is divided is into 2 types. Before the writing of AT command. The AT commands held a very important role in this project as the project key advantage is focus on the auto SMS function.6 AT COMMAND AT command is the command uses to control the GSM modem or mobile phone to perform task for example SMS sending or phone calling. SMS can simply be the alphabet format that we written normally.

Reading. One use of the extended AT commands is to control the sending and receiving of SMS messages. mobile phones and GSM modems support an extended set of AT commands. Monitoring the signal strength. In addition to this common set of standard AT commands.20 The AT command set was developed by Hayes Microcomputer Products and this command is recognized by virtually all modems. Extended AT commands allow us to: 1. Reading. 5. 4. Monitoring the charging status and charge level of the battery.1: Example of AT COMMAND . writing and searching phone book entries. The modem supports the standard and extended Hayes AT command set. 3. Sending SMS messages. writing and deleting SMS messages. 2. Table 2. These extended AT commands are defined in the GSM standards.

CHAPTER 3 METHODOLOGY 3. So in this chapter will discuss about the methods and approaches that have been used from the beginning until the end of this project.1: Flow of Methodology .2 Stage of Methodology and Approach Below show the methodology and approach for this project: Make a research and study Planning Software implementation Hardware implementation Analysis and test Figure 3. it is important to determine the methodology used to make sure this project is a success.1 Chapter Overview Before starting the project. 3.

3. From there. journals. Survey has been done on wireless home security system and wireless home appliances control products available in the market.1 Make a research and study In this stage. Then in this stage. Night GUARDIAN Motion Sensor Light Night GUARDIAN Motion Light Sensors enhance convenience and security by automatically turning on one or more lights or other devices whenever presence is detected. Below are the wireless home security system products in the market: 1. With no minimum load requirement they can be used with low wattage appliances such as fluorescent lamps. So searching more information relating wireless home security system is very important for begin this project. Besides that. . magazines. published work and reference books. gather the information about the project via Internet.3 The work flow for the whole project 3. It is very important because their features are deeply analyzed and then it can be implemented in my project. the important features of good wireless home security system can be indentifying. alarms and video cameras.22 3. They are designed for use with one or more lights up to 600 watts. Full understanding and literature review on wireless home system are needed.

4. Techko Solar Powered Magnetic Sensor Entry Alarm Features 1. 3. and Programmable Privacy Zones. Automatic Gain control. Hi-Res Varifocal Indoor Day/Night Dome Camera This camera offers crisp clear images designed for most interior security applications. Auto White Balance. Built in 90dB alarm No tools installation Ultra thin design 3.23 2. sliding non-tinted transparent doors facing sunlight 2. Use on non-tinted transparent windows. . Motion detection. This camera is a UN Ultra Low Light Camera offering Back Light compensation.

2 Planning In this stage. This concept is very important because the project will be used the system as a main system. Then. the lacking features in their works are improved and implemented in this project. the concept of Global System of Mobile Communication (GSM) needs to be understood. This can be done by doing a lot of literature reviews.24 4. theory in how SMS is being transmitted and the protocol of mobile phone also needed to be understood. 2. Adjustable and shock sensitive. 3.450 feet unrestricted.3. the previous works related to this project are studied and analyzed in order to determine the disadvantages in their researches or projects. Cover a large area of windows. Glass Break Detector Features 1. 3. 4. . Therefore also went through the relevant thesis done by previous graduates in UTM and other projects that are related with this project. Furthermore. Radius coverage is 50 Feet. Next. Range: 240 feet restricted .

IC MAXIM 232 3. Then.25 Next. LED as a lamp Therefore to planning the process or step for my project is very important. Magnetic contact sensor 6. PIC 16F877A 2. Motion sensor 7. Mobile Phone 5. The planning process is creating by using the grant chat. facing difficulty in getting some of the desired components. After the analyzed below the important component that will be used for this project: 1. search more information about the suitable components that will be used in this project. . In this step. make analyzed the information about the component and choose the suitable component for this project. MAX 232 converter 4. This process really takes a time since need to decide the exact components for the project. Fan 8.

2: The Grant Chart for FYP 1 FINAL YEAR PROJECT 2 (FYP 2) No 1 2 3 4 Tasks/activities Project overview Hardware develop Software develop Hardware and software implementation December 1 2 January February March 3 4 5 6 7 8 9 10 11 12 13 14 5 6 7 Analysis and test Thesis writing Final presentation Figure 3.3: The Grant Chart for FYP 2 .26 Below the grant chart that show the planning. FINAL YEAR PROJECT 1 (FYP 1) July 3 4 5 No 1 2 3 4 5 6 7 8 9 10 Tasks/activities Briefing on FYP Determine topic of interest Discuss topic with supervisor Literature review Submit proposal Study on technology related Presentation preparation Determine hardware to purchase Thesis writing Submit thesis for FYP 1 August 6 7 8 9 September 10 11 12 HARI RAYA BREAK October 13 14 15 Figure 3.

3. all the hardware part such as sensor. Besides that.3.27 3. Cost is important in this project since this system is targeted on a low cost product.4: The Circuit of Voltage Regulator . PIC16F877A microcontroller and voltage regulator are combined together. the circuit design and hardware development play an important role. Where.3.1 Voltage regulator LM 7805 Voltage regulator Switch ON/OFF Power Supply Power Indicator Button master reset Figure 3. the availability of the hardware and its cost are considered in choosing the components. Then.3. the hardware is studied based on the theories and its interfacing with other components.3 Hardware Implementation To design this project.

WDT Reset (during normal operation) 5. MCLR Reset during Sleep 4. on MCLR Reset during Sleep and Brownout Reset (BOR). Power-on Reset (POR) 2. The purpose of using diode IN4007 (D1) is for circuit protection in case the polarity of the power source is incorrect. Their status is unknown on POR and unchanged in any other Reset. All the capacitor is use to stabilize the voltage input and output of the LM7805. WDT Wake-up (during Sleep) 6. MCLR Reset during normal operation 3.28 The main component to design the voltage regulator is LM 7805 voltage regulator. on the MCLR and WDT Reset.3. . 3. Normally the power supply is from 9V to 12V. The power source is from the battery or AC to DC adaptor. The LM7805 will generate some heat at the power supply.2 Reset (MCLR) The PIC 16F877A differentiates various kind of reset which includes: 1. Most other registers are reset to a “Reset state” on Power-on Reset (POR). Brown-out Reset (BOR) Some registers are not affected in any Reset condition. They are not affected by a WDT wake-up which is viewed as the resumption of normal operation. LM7805 (1A maximum) will regulate the given voltage to 5V (VCC) to supply to the PIC16F877A and pull-up the push button (input). D2 is a green Light Emitter Diode (LED) as power indicator.3.

The PIC 16F877A has a noise filter in the MCLR Reset path. For this reason.6: The Circuit of Motion Sensor to PIC .3. MCLR is concerned in this project. Voltages applied to the pin that exceed its specification can result in both Resets and current consumption outside of device specification during the Reset event.3 Interface PIC16F876A with PIR Sensor Figure 3.29 From the various kind of reset available in the microcontroller. It should be noted that a WDT Reset does not drive MCLR pin low.3.5: The Placement of Motion Sensor in a Hardware Prototype Figure 3. it is recommended that the MCLR pin no longer be tied directly to VDD. 3. The filter will detect and ignore small pulses.

4 Interface PIC16F876A with magnetic contact sensor Figure 3. 3.3. the PIR sensor is function as to detect the intruder in the home.7: The Placement of Magnetic Contact Sensor in a Hardware Prototype Figure 3.30 Output pin from PIR sensor can be connected to Port B I/O pin 2 from PIC16F877A while the Vcc pin and GND pin should be connected to 5V and GND respectively.8: The Circuit of Magnetic Contact Sensor to PIC . In this project.3. This is part for the security system in the home.

5 Interface PIC16F877A with fan and lamp Figure 3.3.31 The function of magnetic sensor is same with motion sensor.3.3.6 Interface PIC16F877A with Buzzer Figure 3.10: The Circuit of Fan and Lamp to PIC .3. 3.9: The Placement of Fan and Lamp in a Hardware Prototype The 8 LED is to combine as a lamp is connected to port d with PIC16F877A and a fan is connected to port B at pin 4. 3. The magnetic sensor is installed at the door in the home. Both will be function if the mobile phone gives the command. In this project both are as appliances to control using mobile phone. But the magnetic sensor is connected to Port B I/O pin 1 from PIC16F877A.

Negative terminal (black wire) of buzzer should be connected with collector transistor (2N2222) and positive terminal (red wire) should be connected to Vcc as shown in schematic diagram. pin 27 (PGC) and pin 28 (PGD) from PIC should be connected to USB In Circuit Programmer (UIC00A) through the external cable.32 The base of 2N2222 (transistor) can be connected to any I/O pin through a 1K Ohm resistor and the emitter should be connected to GND. So pin 1 (Vpp).7 In circuit Serial Programming (ICSP) for Programming PIC Microcontroller Figure 3.11: The Connected of USB Programmer In Circuit Serial Programming (ICSP) is used for loading program in this project. GND from the circuit board also should be connected with GND from UIC00A and pin 34 (PGM) should be pulled to GND through a 10K resistor as shown Figure 3. .3. Besides.11. ICSP offers a convenience way to load program into PIC microcontroller without removing the PIC from the circuit board.3. 3.

USART is also known as a Serial Communication Interface (SCI). Synchronous – Slave (half-duplex) . Synchronous – Master (half-duplex) 3. serial EEPROM.12: The Serial Communication Interface Circuit The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the two serial I/O modules. The USART can be configured in the following modes: 1.8 Serial Communication Interface Circuit To PIC DB-9 (Female) IC MAX 232 Figure 3. or it can be configured as a half duplex synchronous system that can communicate with peripheral devices such as A/D or D/A integrated circuits.3. Asynchronous (full-duplex) 2. The USART can be configured as a full-duplex asynchronous system that can communicate with peripheral devices such as CRT terminals and personal computer.3. and others.33 3.

Given the desired baud rate and oscillator’s frequency (Fosc). the nearest integer value for the SPBRG register in the microcontroller can be calculated using the formula in Table 3. Table 3.1.13: The Hardware Prototype . It is a dedicated 8-bit baud rate generator.1: Baud Rate formula Figure 3.34 Bit SPEN in Receive Status and Control Register (RCTA) and bit TRISC have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter. The Baud Rate Generator (BRG) supports both the asynchronous and synchronous modes of the USART.

The software is very important so that the system can be operated. Therefore it is take time to determine the software goanna be used. 2. Besides that. 3. To design the Graphic User Interface with the Visual Basic 2008. this project is designed to enable it to communicate with the computer and the mobile phone device. 4. in this stage also the programming for this project must be written and simulated to the hardware.35 3. Then. Therefore. The Proteus (ISIS 6 Professional) used to design the circuit for hardware part. software is required to program the microcontroller. .3.4 Software Implementation The software is used for simulation and programming purposes. below is the software used in this project: 1. Besides that. To make a connection between computer and hardware to mobile phone (GSM modem) is Using AT command and need know the protocol of this mobile phone. For PIC microcontroller the MicroC is used to the hardware with create programming. So the suitable software is needed to communicate there.

1 Programming the Hardware using MicroC Below is the step to make programming the hardware: Step 1: Open the microC compiler for PIC Step 2: Create the programming and save .36 3.3.4.

Figure 3.hex file will appear for both software.15: USB ICSP Programmer Device .14: PICkit 2 Software Interface Figure 3.37 Step 3: After the program had successfully been compiled. a . This file format then will be used in PICkit 2 Programmer to be “burn” into the microcontroller by using suitable programmer device preferred by the user.

38 Motion Sensor Programming Programming .

16: Flow Chart for Motion Sensor programming . Wait for PIR set.39 Start Switch button pressed? Yes Delay 15 Seconds Alarm set (LED blink in low frequency). No PIR sensor set? Yes Alarm (Buzzer) active Transmitted 1 byte data (B) to PC PC sends Message (SMS) to phone No Reset button pressed? Yes Alarm (Buzzer) still active but data not send to PC No Figure 3.

4.3 Magnetic Contact Sensor Programming Programming .40 3.3.

17: Flow Chart for Magnetic Contact Sensor Programming . No Magnetic sensor set? Yes Alarm (Buzzer) active Transmitted 1 byte data (B) to PC PC sends Message (SMS) to phone No Reset button pressed? Yes Alarm (Buzzer) still active but data not send to PC No Figure 3. Wait for Magnetic set.41 Start Switch button pressed? Yes Delay 15 Seconds Alarm set (LED blink in low frequency).

42 3.18: Flow Chart for ON/OFF Lamp .3.4.4 Home Appliances ( Fan and Lamp) Programming Programming Flow chart Start Type “ON Lamp” from Mobile Phone Send to number Phone (Setting in GUI) Lamp in hardware and GUI will light Start Type “OFF Lamp” from Mobile Phone Send to number Phone (Setting in GUI) Lamp in hardware and GUI will light Figure 3.

43 Start Type “ON Fan” from Mobile Phone Send to number Phone (Setting in GUI) Lamp in hardware and GUI will light Start Type “OFF Fan” from Mobile Phone Send to number Phone (Setting in GUI) Lamp in hardware and GUI will light Figure 3.4.5 Graphic User Interface Figure 3.20: Main of Graphic User Interface .3.19: Flow Chart for ON/OFF Fan 3.

this system is imagined as a real system to figure out the problems that could face when implemented in a home.3. Besides that.24.3. Figure 3.5.44 Figure 3. . the system hardware is analysed and tested to improve the system. 3. The setup of hyper terminal has to be done like shown in Figure 3.22.21: Output of Graphic User Interface 3.23 and Figure 3.5 Analysis and Testing In this final stage.1 Testing the AT COMMAND The AT commands can be written and tested through the use of hyper terminal.

22: The Hyper Terminal Connection Setup Figure 3.23: Hyper Terminal Com Port Setup .45 Figure 3.

46 Figure 3. .25: Testing the AT Command AT command that written and tested will then being written into the visual basic program in order to control using the mobile phone.24: The Interface for Write AT Command Figure 3.

These chapters also discuss how the project works.1: The Block Diagram for Security System . 4.2 The Block Diagram for This Project Hardware Computer Mobile Phone Figure 4.CHAPTER 4 RESULT AND DISCUSSIONS 4.1 Chapter Overview This chapter discusses the result and discussion for this project.

2: The Block Diagram for Home Appliances Control 4. 5. Then from GUI in the computer will send the SMS to home owner mobile phone to inform the thief is occur. The hardware will send the 1 byte data (A) using USART programming to the GUI in the computer. When the home owner type “ON LAMP” in the create message at the mobile phone and send to the mobile phone (is connected with computer using usb cable) so the switch “ON” for a lamp in the system will become a green colour. While for case to control a lamp by using the mobile phone also. 4.3 How Does it Work? 1. .48 Lamp Mobile Phone Computer Fan Figure 4. If the intruder through the door the magnetic sensor will work and the buzzer will sound. The process is same like magnetic sensor. 2. 3. If the thief not through the door the motion sensor will work and the buzzer will sound.

While the process for the cases of on and off fan are same with the on and off lamp.49 the lamp in a hardware and in a GUI will light and “ON LAMP” the textbox in the system show “ON LAMP”. 7. 6. When the system is run the figure 4. but the textbox will show “OFF LAMP” and lamp in a hardware and in a GUI will non active. 4. .3 The Result for This Project 4.3: The Main System This is a main system for this project. For case off a lamp also.3.3.1 For the security system Figure 4.will appears.

50 Enter your username and password Figure 4.5: The Output Graphical User Interface .4: The Login This System The user must be fill in the username and the password to login this system. Figure 4.

The system also has a message box and a com port to determine the value of serial port. . While the home appliances are grouped in a one group. Figure 4. The run and stop button is for timer. The exit button is to exit this system.51 The system was in the output interfacing. In the figure the sensor are motion and magnetic is one group.6: The System show user chosen the Com Port The user must to choose the com port for serial port to run this system. The home appliances are a lamp and a fan. Both has one button for on and off respectively.

7: The Hardware Prototype Figure 4.8: The System Show When the Magnetic Contact Sensor is Active .52 Figure 4.

” . Then the systems send this message to the owner number of mobile phone. Figure…. the button of motion sensor will become a green colour.” . Figure 4. When the owner received this message the message “Message Sent!” appears in the system.Sila ambil tindakan lanjut. When the owner received this message the message “Message Sent!” appears in the system.53 Button on power supply in the hardware is pressed and then pressed the pushbutton.Sila ambil tindakan lanjut. In the message box is appear message “ Perhatian!!! Rumah anda telah dicerobohi. Then the systems send this message to the owner number of mobile phone. If the intruders open the door the button of magnetic contact sensor will become a green colour.9: The System Show When the Motion Sensor is Active Button on power supply in the hardware is pressed and then pressed the pushbutton. If the thief occur which the intruder entered the house through the roof or other doors. .. In the message box is appear message “ Perhatian!!! Rumah anda telah dicerobohi.

10 and Figure 4.54 4.2 For the Wireless Home Appliances Control Figure 4.11 are show both a lamp in hardware and in system light when the home owners send message “ON LAMP” from the mobile phone. .10: The Hardware Prototype Show a Lamp is Light Figure 4.3.11: The System Show a Lamp is Light These Figure 4.

55 Figure 4. It also occurs at a lamp in the hardware.12 show a lamp in the system is non active when the home owners send message “OFF LAMP” from a mobile phone. Figure 4.13: The Hardware Prototype Show a fan is Active .12: The System Show a lamp is non active The Figure 4.

14: The System Show a fan is Active These Figure 4.14 show both a fan in the hardware and in the system is active when the home owners send message “ON FAN” from the mobile phone.56 Figure 4. Figure 4.15: The System Show a Fan is Non Active .13 and Figure 4.

It also occurs at a fan in the hardware.16: The System Show When the Exit Button Pressed When the home owner pressed the exit button the message is appear.57 The Figure 4.3. In the message the yes button for closed the system and no button for go to main of the system.15 show a fan in the system is non active when the home owners send message “OFF FAN” from a mobile phone.3 To Exit the System Figure 4. 4. .

The system in this project will be informed to home owners if the theft is occurred. This project also was developed that could be used to control electrical appliances through a mobile phone.1 Conclusion This project can be concluded that the target to control home appliances remotely using the SMS-based system and develop the security system based GSM has achieved.CHAPTER 5 CONCLUSION AND SUGGESTION 5. The security and home appliances control has been implemented. . GSM technology capable solution has proved to be controlled remotely. To summary the project that the project was developed to make a home security from the intruder. provide home security and is cost-effective as compared to the previously existing systems. The appliances are a lamp and a fan. Hence we can conclude that the required goals and objectives of GSM-based wireless home appliances control and security system have been achieved.

So this project can be implementing in a small house that have a narrow space. light sensor and other sensor. others limitation is the project only control not real appliances. air condition and others of electrical appliances. television. some recommendations to improve this project are hereby proposed. So the system can improve this project. Can control more appliances. Another sensor could be added to the system More of sensor can be installed to home like smoke detector. It is because these projects are connected to two sensor and two appliances.2 The Limitations The limitations of this project are this project only has two sensors to detect the intruder. . Some of the suggestions to future development are listed as below: 1. 5.3 Suggestion and Future Development Since this project is important to reduce the theft and robbery cases in Malaysia by providing advanced feature at low cost. 3. motion detector. Besides that. 2. To develop that project to control more of appliances like washing machine. Connecting more device To develop the system that connecting to more devices.59 5.

www. Cornell University. CHAN HWOH CHUENG ( MAY 2009 ). 2. Monitoring and controlling of device using GSM. Bachelor degree. AFZAHANIFF HUSSIN ( MAY 2008 ).com 10. John Iovine. ‘Sistem Penggera Keselamatan Rumah Kediaman Mudah Dan Pintar’. Skudai. Wireless home security system. Skudai. New York. Security and control system. Microchip Technology Inc. McGraw-Hill. Universiti Teknologi Malaysia. Wireless home security system. Home security system. 4. 8.60 REFERENCES 1.wikipedia. Universiti Teknologi Malaysia. 5. 6. http://www.microchip. PRIYANKA. 3. 2000. CHUN-PAI JIMMY HSIEH AND YANG CAO ( 2004).com 9. India 7. Bachelor . Bachelor degree. PIC 16F877A Manual Datasheet. Universiti Teknologi Malaysia. MOHD ROSLI BIN MAMAT ( 2007 ). Bachelor degree. PIC microcontroller project book. LOGESWARAN A/L ARUMUGAM ( MAY 2009 ). http://en. Skudai.developershome. Skudai. Universiti Teknologi Malaysia.

61 APPENDIX A Main Board Circuit Schematic .

buzzer=0. LED=0. fan=0. TRISA = 0b11111111.F4 #define LED PORTC. unsigned char data.F2 #define switch_button PORTA. delay_ms(100). . mode_2=0. // set Port D as Output Usart_Init (9600). ADCON1 = 0x06.F4 #define buzzer PORTC. if(data=='L') { lamp = 255. // set Port B as Input except port 4 TRISC = 0b00000000. unsigned int mode_1. /*RESET ALL OUTPUT*/ mode = 0. lamp=0.F1 #define motion_sensor PORTB.F0 #define lamp PORTD #define fan PORTB. // set Port A as Input TRISB = 0b11101111.F0 void main () { unsigned int mode. unsigned long temp1. mode_1=0.62 APPENDIX B The Programming for Hardware #define magnetic_sensor PORTB.mode_2. // set Port C as Output TRISD = 0b00000000.temp2. do { if(Usart_Data_Ready ()) { data = Usart_Read().

} else if (data =='F') { fan = 1. temp1=0. mode_1=3. } if ((magnetic_sensor==1)&&(mode_1==2)) { Usart_Write ('B'). delay_ms(2000). } switch(mode_1) { case 1: LED=1. } else if(data =='P') { lamp = 0. mode_1=3. } if ((mode == 1)&&(mode_1!=3)) { mode_1=1. Delay_ms(50). if(temp1<40000) buzzer=1. } } if(switch_button == 0) { while(switch_button == 0). } else if (data == 'N') { fan =0.63 delay_ms(2000). Delay_ms(50). Delay_ms(500). //Buzzer is funtion else if(temp1>60000) { . mode = 1. } if ((motion_sensor==1)&&(mode_1==2)) { Usart_Write ('A'). mode = 0. temp1+=1.

64 temp1=0; mode_1=2; } else buzzer=0; break; case 2: temp2+=1; //PORTD.F2 = 0; /*test funtion*/ buzzer = 0; if(temp2<10000) LED=1; //LED blink else if(temp2<100000) LED=0; else temp2=0; break; case 3: temp2+=1; //PORTD = 0xFF; /*test funtion*/ //PORTD.F5 = 0; PORTD.F6 = 0; /*test funtion*/ if(temp2<40000) //LED blink & buzzer are funtion { LED=1; buzzer=1; } else if(temp2<60000) { LED=0; buzzer=0; } else temp2=0; break; default: break; } } while(1); }


The Programming for Interfacing

Public Class OUTPUT Private Sub OUTPUT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MAIN.Hide() Dim COMPort As String() COMPort = System.IO.Ports.SerialPort.GetPortNames() For Each port In COMPort ComboBox1.Items.Add(port) Next End Sub

Private Sub control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles control.Enter End Sub Dim Q As Queue(Of String) = New Queue(Of String) Dim DataRead As String = 0 Dim objSMS As mCore.SMS Dim strmyMessage As String Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Timer1.Start() DataRead = SerialPort1.ReadExisting If (DataRead = "A") Then MOTION.BackColor = Color.Green End If If (DataRead = "B") Then MAGNETIC.BackColor = Color.Green End If

objSMS = CreateObject("mCore.SMS") If objSMS.LogSize > 100 Then objSMS.ClearLog(10) End If

66 objSMS.LogType = 2 objSMS.Port = "COM6" objSMS.BaudRate = 9600 objSMS.Character = 0 objSMS.LongMessage = 3 strmyMessage = "Perhatian!!! Rumah anda telah diceroboh.Sila ambil tindakan lanjut. " objSMS.SendSMS("+60129215921", strmyMessage) If Not objSMS.IsError(True) Then MessageBox.Show("Message Sent!") End If objSMS = Nothing End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick SyncLock DataRead If DataRead.Equals("A") Then Dim strInput As String = "Perhatian!!! Rumah anda telah diceroboh.Sila ambil tindakan lanjut. " TextBox1.Text = strInput DataRead = 0 End If If DataRead.Equals("B") Then Dim strInput As String = "Perhatian!!! Rumah anda telah diceroboh.Sila ambil tindakan lanjut. " TextBox1.Text = strInput DataRead = 0 End If End SyncLock End Sub Dim iResponse As Integer Dim LampOn As String = 0 Dim LampOff As String = 0 Dim FanOn As String = 0 Dim FanOff As String = 0 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged SerialPort1.Close() SerialPort1.PortName = ComboBox1.SelectedItem.ToString() If SerialPort1.IsOpen() Then SerialPort1.Close() Else SerialPort1.Open() MessageBox.Show("Port1 Open")

67 End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Timer1.Stop() SerialPort1.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Timer1.Start() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Button5.BackColor = Color.Green LampOn = "L" TextBox1.Text = "ON LAMP" SerialPort1.Write(LampOn) PictureBox1.Visible = False PictureBox3.Visible = True End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Button5.BackColor = Color.Empty PictureBox3.Visible = False PictureBox1.Visible = True TextBox1.Clear() Button6.BackColor = Color.Red LampOff = "P" TextBox1.Text = "OFF LAMP" SerialPort1.Write(LampOff) PictureBox1.Visible = True PictureBox3.Visible = False End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer2.Start() Timer3.Start() Timer4.Start() Timer3.Enabled = False Timer4.Enabled = False Button1.BackColor = Color.Green FanOn = "F" TextBox1.Text = "ON FAN" SerialPort1.Write(FanOn)

Enabled = True Timer3.EventArgs) Handles Button2.Stop() Button2.EventArgs) Handles Timer3.Text = "OFF FAN" SerialPort1.Enabled = False End Sub Private Sub Timer2_Tick(ByVal sender As System.Object. ByVal e As System.Visible = False PictureBox5.Tick PictureBox5.EventArgs) Handles Timer2.Visible = False PictureBox4.Visible = True Timer4.Object.Enabled = False End Sub End Class .Visible = True Timer2.Object.Click Timer2.Visible = False PictureBox2.Tick PictureBox2.Enabled = False End Sub Private Sub Timer4_Tick(ByVal sender As System.Enabled = True Timer2.BackColor = Color.Tick PictureBox4. ByVal e As System.Stop() Timer4.Enabled = True Timer4.EventArgs) Handles Timer4.Object. ByVal e As System.68 End Sub Private Sub Button2_Click(ByVal sender As System.Stop() Timer3.Visible = True End Sub Private Sub Timer3_Tick(ByVal sender As System.Write(FanOff) PictureBox2.Red FanOff = "N" TextBox1.Visible = True Timer3. ByVal e As System.

69 APPENDIX D The Project Prototype .

Sign up to vote on this title
UsefulNot useful