You are on page 1of 73

GSM BASED HOME AUTOMATION

A PROJECT REPORT
Submitted by

YUVARAJA.R

6109314

In partial fulfillment for the award of the degree of

BACHELOR OF ENGINEERING IN ELECTRONICS & COMMUNICATION ENGINEERING

MEENAKSHI ACADEMY FOR HIGHER EDUCATION AND RESEARCH

WEST K.K. NAGAR CHENNAI - 600078 June 2012

1|Page

MEENAKSHI ACADEMY OF HIGHER EDUCATION AND RESEARCH (MEENAKSHI UNIVERSITY)


(Established under Section 3 of the UGC Act, 1956 vide Notification No.F.9-5/2002-U.3, dt.31.03.2004)

BONAFIDE CERTIFICATE
Certified that this project report GSM BASED HOME AUTOMATION is the Bonafide work of YUVARAJA.R ( 6109314 ) carried put the research under my supervision. Certified further, that to the best of my knowledge, the work reported herein does not form part of any other project report or dissertation on the basis of which a degree or award was conferred on an earlier occasion on this or any other candidate

[SUPERVISOR]

[HEAD OF THE DEPARTMENT]

Evaluated and Viva Voce Conducted on: .

INTERNAL EXAMINER
2|Page

EXTERNAL EXAMINER

ACKNOWLEDGEMENT
We are greatly indebted to our beloved chancellor Thiru. A.N. Radha Krishnan M.A., D.Com. for giving an opportunity to complete this project work. We are thankful to our Vice Chancellor In charge Dr.P.Jayakumar MDS for his kind help rendered to us in finishing this project successfully. We also express our sincere thanks to the director of part time course Ms.V.Priyanka Rajan M.A., M.B.A., B.Ed., M.Phil., L.L.B., for extending valuable assistance. We would like to express our sincere thanks to our project guide Mr. M.Thamil Selvan ME., Asst. Professor for providing valuable guidance and extensive support. I express my gratitude to my friends for their support in all aspects to accomplish this project. I deem it fit to thank all the staff of Mechanical engineering dept, who helped me a lot during the project work and nurtured an environment of creativity and support.

3|Page

DECLARATION

I Yuvaraja.R , of 7th Semester, Department of Electronics and Communication Engineering, MAHER University had done a project on the title GSM BASED HOME AUTOMATION under the guidance of Mr. M.Thamil selvan M.E., I declare that the project done is an original work by me.

( YUVARAJA.R ) (Reg.No:6109314)

Place: Chennai. Date:

4|Page

TABLE OF CONTENTS S.NO . 1. 2. 3. 2.1 2.2 ABSTRACT INTRODUCTION CONTROL SYSTEM Block diagram Components Descriptions 2.1.1 Schematic Diagram 2.2.1 Max-232 Circuit 2.2.2 Driver Circuit 2.2.3 Relay Circuit 2.2.4 LCD Display 4. GSM MODEM 3.1 History of Cellular Mobile Radio 3.2 Evolution of GSM 3.3 Architecture of GSM Network 3.4 SMS in GSM 3.5 Specification GSM Modem 3.6 Commands used in GSM Modem 22 23 24 25 26 8 9 11 12 13 14 15 16 17 18 20 21 TITLE PAGE NO

5|Page

5. 6. 7. 8. 9. 10. 11. 12.

MICRO CONTROLLER AT89C51RD2BN LDR MEMORY (24C16) RTC (DS1307) POWER SUPPLY UNIT SOURCE CODE ( C PROGRAM ) CONCLUSION REFRENCES

29 36 39 44 48 50 67 68

6|Page

LIST OF ABBREVIATIONS

GSM SMS SIM SMPS ISP ESTI RISC PDU EMF GPRS EDGE CDMA TDMA ISDN

Global System for Mobile Communications Short Message Service Subscriber Identity Module Switched Mode Power Supply In System Program European Standard Telecommunication Institute Reduced Instruction Set Computer Protocol Data Unit Electro Magnetic Field General Packet Radio Service Enhanced Data for GSM Evolution Code Division Multiple Access Time Division Multiple Access Integrated Services Digital Network

ABSTRACT
7|Page

Gsm Based Home Automation


The development of GSM-based control home appliances for smart home system. The main aim of the prototype development is to reduce electricity wastage. GSM module was used for receiving short message service (SMS) from users mobile phone that automatically enable the controller to take any further action such as to switch ON and OFF the home appliances such as light, airconditioner etc. The system can be controlled and monitored via SMS from anywhere that covered by GSM service. For example if you are aside of your home, you want control and monitor appliances like motor, TV, lights, air-conditioner etc. by sending a SMS to the GSM modem presented in home you can monitor all the above appliances and you can also control some appliances like fans and AC. Whenever you send SMS to do specific task GSM modem will send an acknowledgement to the user so that user can know the status of his request. The system was integrated with microcontroller and GSM network interface using Embedded C language. The system is activated when user sends the SMS to controller at home. Upon receiving the SMS command, the microcontroller unit then automatically controls the electrical home appliances by switching ON or OFF the device according to the user order

INTRODUCTION

8|Page

The development of digital information has led the rapid change in human lifestyle. The use of electricity is very important as one of the main source of energy that is vital in today modern life. Some kinds of mechanism using available technology could be used to reduce wastage in electricity usage. Thus a prototype based on a microcontroller device using SMS is developed. It can automatically control any electrical equipment at home remotely using Mobile phone. GSM (SMS) Controlled system which is capable of receiving a set of command instructions in the form of Short message service and performs the necessary actions like ON, OFF and STATUS. We will be using a dedicated modem/mobile at the receiver module i.e., with the commands using SMS service as per the required actions. The mobile unit which is connected with an intellectual device called Micro controller so that it takes the responsibility of reading the received commands in the from of SMS from the mobile unit and perform the corresponding predefined tasks such as device ON, OFF and STATUS

EXISTING SYSTEM:

9|Page

Automation is todays fact, where more things are being completed every day automatically, usually the basic tasks of turning on or off certain devices and beyond, either remotely or in close proximity. Human can power on the motor ,light ac etc.But power off some due to memory loss they cannot power off the applications. Some time advanced power onof applications is not possible. So human can power on applications manually.Thats why automatically power on using gsm home automation.

PROPOSED SYSTEM: To overcome the existing problem, we construct a model the project is a clear indication of a multi purpose control done via sms reducing the manual efforts and time required while paying individual attention for controlling each device. At time night are automatically using sensors it will saves time and energy of the individual. The system requires less design and implementation cost. For handicapped people it may be really not entertaining to involve much in manual work and this system helps them to locate themselves in a place and operate the lights of their room, switch on the fan etc. user can make use of this system for controlling motor, fan, lamps and also several other devices necessarily operated in the home. We found many device control operations and applications existing out of it

CONTROL SYSTEM

10 | P a g e

Control System consists of the following components Controlled Devices


GSM Modem MAX232 Circuit AT89C51RD2BN Microcontroller ULN 2003 to Driver Relay Embedded C Language

LDR

LCD Display

Memory Ic (24C16) RTC (DS1307)

Power Supply Circuit

2.0

BLOCK DIAGRAM

11 | P a g e

Block diagram of the home appliance control system using SMS. The Mobile Phone is integrated with the microcontroller AT89s52, which receives SMS message from user Mobile Phone and sends a command t to control whether to turn ON or OFF the output. The Mobile Phone also sends status reporting to the user regarding the electrical appliance. The system utilizes a low cost microcontroller that is currently available in the market. The development of this device involves with both hardware and software to provide a preferable results.

2.1 SCHEMATIC DIAGRAM AT89C51 INTERFACING RTC ,MEMORY AND ULN2803


12 | P a g e

U 5 V + C 3 C C 1 C 1 k 1 R 2 3 1 Y Q S 1 T9 A 2 1 8 9 8 C7 6T L5 A 5 V 1 1 1 S1 1 2 3 4 5 6 7 8 U E L X 1 X 2 R 2 3 I N 4 I N D TA 0 5 T 1 P P P P P P P P 8 0 1 1 1 1 1 1 1 1 E S T 0 T 1 E T 1 4 A / V P P P P P P P P P P P P P P P P P 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 . . . . . . . . . . . . . . . . 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 R E L L L L S N C C C C 1 2 3 4 5 6 7 1 1 2 2 3 3 G

1 A Y A Y A Y N

0 V 6 6 5 5 4 D4 C A Y A Y A Y 1 C1 1 1 1 9 8 4 3 2 1 0

5 V U 1 2 3 4 5 6 7 8 9 U L N 8 1 1 1 1 1 1 1 1 1 8 7 6 5 4 3 2 1 0 R R L L L L E E L L A A 1 2 3 4 Y Y 1 2

E E E E

D D D D

2 . 6 X 3

7 8 K UH 5 Z 1 2 3 4 T 1 X 1 X 2 B A T G N D D S 1 3 V C O U S C S D

7 4 H D D D D O 1 2 3

1 4

2 8 0

1 B 3 . 3 2 V

0 7

. . . . . . . .

0 / T 2 1 / T 2 2 3 4 5 6 7

1 7 R D 1 6 W R 2 9 P S E 3N 0 A L E 1 P1 / T X D 1 0 R X D 5 V

U 5 6 7 8

4 4 3 2 1 2 4 C 1 6

5 2

AT89C51 INTERFACING 16X2 LCD AND MAX 232


VCC 10K PO T 1 2 3 P1 .0 4 P1 .1 5 P1 .2 6 P2 .0 7 P2 .1 8 P2 .2 9 P2 .3 10 P2 .4 11 P2 .5 12 P2 .6 13 P2 .7 14 15 16 5 9 4 8 TXD RXD 3 7 2 6 1 CT S RT S V CC

U1 P 0.0 P 0.1 P 0.2 P 0.3 P 0.4 P 0.5 P 0.6 P 0.7 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 19 P 0.0/ AD0 P 0.1/ AD1 P 0.2/ AD2 P 0.3/ AD3 P 0.4/ AD4 P 0.5/ AD5 P 0.6/ AD6 P 0.7/ AD7 P 1.0 P 1.1 P 1.2 P 1.3 P 1.4 P 1.5 P 1.6 P 1.7 X1 P2. 0/A 8 P2. 1/A 9 P 2. 2/A 10 P 2. 3/A 11 P 2. 4/A 12 P 2. 5/A 13 P 2. 6/A 14 P 2. 7/A 15 P3. 0/RX D P3. 1/ TXD P3. 2/ INT0 P3. 3/ INT1 P 3.4/ T0 P 3.5/ T1 P 3. 6/WR P3. 7/RD ALE PS EN X2 EA RST V CC 89C51 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 30 29

Connect or DB9

LCD P 3. 2 P 3. 3 P 3. 4 P 3. 5 P 3. 6 P 3. 7 A LE P SE N-

P 1.3 P 1.4 P 1.5 P 1.6 P 1.7 33pF

9 10 12 11 1 0. 1M F 3

6 1 R2OUT T 2IN R1OUT T 1IN C1+ V+ V15 C1C2+ T1OUT R1I N R2I N T2OUT C C V 2 6

V CC

0. 1M F

11.0592M Hz 18 31 9 40

0. 1M F GND 14 13 8 7 R XD T XD RTS CTS

33pF VCC

RST

20

V CC PS EN1 2 3 0. 1M F

C2I CL232

T iny S witc h

COMPONENTS DESCRIPTIONS Power Supply circuit:


13 | P a g e

The STEP DOWN Transformer gives the 12v AC then regulator and filter will gives the 12v DC delivered to MCU Circuits & Relays GSM Modem: GSM Modem receives the signal and converts the data and pushes instruction to microcontroller. MAX232 Circuit: It is an interface between GSM Modem and Microcontroller. AT89C51 Controller: This is the heart of the control system which control the device(s) based on the SMS. ULN 2003 to Driver: It is power driver circuit that controls the relay(s). Relay: The Relay is connected to the output device(s). LCD Display: This displays the status of the device. LDR: Light dependent resistor using light intensity dependent to lights on Embedded C Language: The software is used to program the AT89C51 Controller. Controlled Device: The wide variety of home appliances and such as Lights, Fans, etc. can be connected. LED: Light Emitting Diode ) is a semiconductor light source Max-232 Circuit When communicating with various micro processors one needs to convert the RS232 levels down to lower levels, typically 3.3 or 5.0 Volts. Serial RS-232 (V.24)
14 | P a g e

communication works with voltages -15V to +15V for high and low. On the other hand, TTL logic operates between 0V and +5V . Modern low power consumption logic operates in the range of 0V and +3.3V or even lower. Thus the RS-232 signal levels are far too high TTL electronics, and the negative RS-232 voltage for high cant be handled at all by computer logic. To receive serial data from an RS-232 interface the voltage has to be reduced. Also the low and high voltage level has to be inverted. This level converter uses a Max232 and five capacitors..The MAX232 from Maxim was the first IC which in one package contains the necessary drivers and receivers to adapt the RS-232 signal voltage levels to TTL logic.

Fig 2.2 MAX-232 Circui

2.2.1

DRIVER CIRCUIT

ULN 2803:

15 | P a g e

The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. It consists of seven NPN Darlington pairs that feature high-voltage outputs with common-cathode clamp diode for switching inductive loads. The collector-current rating of a single Darlington pairs 500mA. The Darlington pairs may be paralleled for higher current capability. Applications include relay drivers, hammer drivers, lamp drivers, display drivers (LED gas Discharge), line drivers, and logic buffers. The ULN2803 has a 2.7kW series base resistor for each Darlington pair for operation directly with TTL or 5V CMOS devices. Specification:

High Voltage, High Power Relay control Max: 7 Relay 500mA rated collector current ( Single output )

High-voltage outputs: 50V Inputs compatible with various types of logic. Relay driver application.

Fig 2.4 ULN2803 Circuit with Led

1.2.3. RELAY CIRCUIT The relay driver is used to isolate both the controlling and the controlled device. The relay is an electromagnetic device, which consists of
16 | P a g e

solenoid, moving contacts (switch) and restoring spring and consumes comparatively large amount of power. Hence it is possible for the interface IC to drive the relay satisfactorily. To enable this, a driver circuitry, which will act as a buffer circuit, is to be incorporated between them. The driver circuitry senses the presence of a high level at the input and drives the relay from another voltage source. Hence the relay is used to switch the electrical supply to the appliances.

Fig 2.5 Relay Structure NC: - Normally Connected NO: - Normally Open COM: - Common

The common contact or moving contact establishes the GSM Based Control System connection with a new terminal which is indicated as a normally open terminal (N/O). Whenever, the supply coil is withdrawn the magnetizing force is vanished. Now, the spring pulls the moving contact back to initial position, where it makes a connection makes with N/C terminal. However, it is also to be noted that at this time also a back emf is produced. The withdrawal time may be in microsecond, the back emf may be in the range of few kilovolts and in opposite polarity with the supplied terminals the voltage is known as surge voltage. It must be neutralized or else it may damage the system

2.2.4 LCD DISPLAY A liquid crystal display (LCD) is a thin, flat display device made up of any number of color or monochrome pixels arrayed in front of a light source or reflector. It is often
17 | P a g e

utilized in battery-powered electronic devices because it uses very small amounts of electric power. Specification: Model: JHD162A Type: Reflective Yellow Green Interface : 4 Bit Mode Number of characters: 16 characters*2 lines. Power Supply : 5V DC
Table 2.1: PIN Details of LCD

LCD wring diagram

GSM MODEM
18 | P a g e

A GSM Modem can be an external Modem device, such as the LINKTO. Insert a GSM SIM card into this Modem and connect the modem to an available serial port on the computer to check the performance of the same. A GSM Modem could be a standard GSM mobile phone with the appropriate cable and software driver to connect to a serial port on the computer.

HISTORY OF CELLULAR MOBILE RADIO The idea of cell-based mobile radio systems appeared at Bell Laboratories (in USA) in the early 1970s. However, mobile cellular systems were not introduced for commercial use until the 1980s. During the early 1980s, analog cellular telephone systems experienced a very rapid growth in Europe, particularly in Scandinavia and the United Kingdom. Today cellular systems still represent one of the fastest growing telecommunications systems. But in the beginnings of cellular systems, each country developed its own system, which was an undesirable situation for the following reasons:

The equipment was limited to operate only within the boundaries of each country.

The market for each mobile equipment was limited.

19 | P a g e

In order to overcome these problems, the Conference of European Posts and Telecommunications (CEPT) formed, in 1982, the Group Special Mobile (GSM) in order to develop a pan-European mobile cellular radio system (the GSM acronym became later the acronym for Global System for Mobile communications). The standardized system had to meet certain criteria:

Spectrum efficiency International roaming Low mobile and base stations costs Good subjective voice quality Compatibility with other systems such as ISDN (Integrated Services Digital Network)

Ability to support new services

Unlike the existing cellular systems, which were developed using an analog technology, the GSM system was developed using a digital technology. In 1989 the responsibility for the GSM specifications passed from the CEPT to the European Telecommunications Standards Institute (ETSI). The aim of the GSM specifications is to describe the functionality and the interface for each component of the system, and to provide guidance on the design of the system. These specifications will then standardize the system in order to guarantee the proper inter-working between the different elements of the GSM system. In 1990, the phase I of the GSM specifications was published but the commercial use of GSM did not start until mid-1991. The most important events in the development of the GSM system are presented in the table 1. Year 1982 Events CEPT establishes a GSM group in order to develop the standards for a panEuropean cellular mobile system

20 | P a g e

TDMA is chosen as access method (in fact, it will be used with FDMA) Initial 1987 1989 1990 1991 1992 1993 1995 Memorandum of Understanding (MoU) signed by telecommunication operators (representing 12 countries) The responsibility of the GSM specifications is passed to the ETSI Appearance of the phase 1 of the GSM specifications Commercial launch of the GSM service Enlargement of the countries that signed the GSM- MoU> Coverage of larger cities/airports Coverage of main roads GSM services start outside Europe Phase 2 of the GSM specifications Coverage of rural areas
Table 3.1: Events in the development of GSM

From the evolution of GSM, it is clear that GSM is not anymore only a European standard. GSM networks are operational or planned in over 80 countries around the world. The rapid and increasing acceptance of the GSM system is illustrated with the following figures:

1.3 million GSM subscribers worldwide in the beginning of 1994. Over 5 million GSM subscribers worldwide in the beginning of 1995. Over 10 million GSM subscribers only in Europe by December 1995.

Since the appearance of GSM, other digital mobile systems have been developed. The table 2 charts the different mobile cellular systems developed since the commercial launch of cellular systems.

EVOLUTION OF GSM GSM is a global system for mobile communication GSM is an international digital cellular telecommunication. The GSM standard was released by ETSI (European Standard Telecommunication Institute) back in 1989. The first commercial services were launched in 1991 and after its early introduction in Europe;
21 | P a g e

the standard went global in 1992. Since then, GSM has become the most widely adopted and fastest-growing digital cellular standard, and it is positioned to become the worlds dominant cellular standard. Todays second-generation GSM networks deliver high quality and secure mobile voice and data services (such as SMS/ Text Messaging) with full roaming capabilities across the world. GSM platform is a hugely successful technology and as unprecedented story of global achievement. In less than ten years since the first GSM network was commercially launched, it become, the worlds leading and fastest growing mobile standard, spanning over 173 countries. Today, GSM technology is in use by more than one in ten of the worlds population and growth continues to sour with the number of subscriber worldwide expected to surpass one billion by through end of 2003. Todays GSM platform is living, growing and evolving and already offers an expanded and feature-rich family of voice and enabling services. The Global System for Mobile Communication (GSM) network is a cellular telecommunication network with a versatile architecture complying with the ETSI GSM 900/GSM 1800 standard. Siemens implementation is the digital cellular mobile communication system D900/1800/1900 that uses the very latest technology to meet every requirement of the standard.

The following GSM generation passed in 3decades: 1G 2G 2.5G 2.75G


22 | P a g e

Analog Communication Digital Communications GPRS EDGE

3G 4G

Enhanced feature of Video call High-speed Wireless Broadband

ARCHITECTURE OF GSM NETWORK The GSM technical specifications define the different entities that form the GSM network by defining their functions and interface requirements. The architecture of the GSM network is presented in figure 2.

Fig. 3.1 Architecture of the GSM network

SMS IN GSM SMS stands for Short Message Service. It is a technology that enables the sending and receiving of message between mobile phones. SMS first appeared in Europe in 1992. It was included in the GSM (Global System for Mobile Communication) standards right at the beginning. Later it was ported to wireless technologies like CDMA and TDMA.
23 | P a g e

The GSM and SMS standards were originally developed by ETSI. ETSI is the abbreviation for European Telecommunication Standard Institute. 1. Now the 3GPP (Third Generation Partnership Project) is responsible for the development and maintenance of the GSM and SMS standards. One SMS message can contain at most 140 bytes (1120 bits) of data, so one SMS message can contain up to: 160 characters if 7-bit character encoding is used. (7-bit character encoding is suitable for encoding Latin characters like English alphabets.) 70 characters if 16-bit Unicode UCS2 character encoding is used. (SMS text messages containing non-Latin characters like Chinese character should use 16-bit character encoding.) Once the message is sent the message is received by SMSC, which must then get it to the appropriate mobile device. To do this the SMSC sends a SMS request to Home Location Register (HLR) to find the roaming customer. Once HLR receives the request, it responds to the SMSC with the subscribers status: 1 Inactive or active 2 Where subscriber is roaming.

SMS provides a mechanism for transmitting short message to and from wireless devices. The service makes use of an SMSC, which acts as a store and forward system for short messages. One major advantage of SMS is that it is supported by 100% GSM mobile phones. Almost all subscription plans provided by wireless carriers include inexpensive SMS messaging service.
24 | P a g e

SPECIFICATIONS OF GSM MODEM Output Power Class 4 2W @ 900MHz Class 1 1W @ 1800MHz Input voltage5V-24VDC Input current1A-2A 5mA readiness for action, 140mA in GSM 900MHz @ 12V telephone conversation condition 5mA readiness for action, 100mA in GSM 1800/1900MHz @ 12V telephone conversation condition SMS service function -Writing and PDU -Point-to-point (MT/MO) -Plot broadcast RS232 connection -Orders with AT to make the remote control (GSM07.07 and 07.05) -Establishes contacts the baud rate by 300 to 1.15,2 million bits/s -Automatic baud rate (300 to 38,,400 bits/s) SMA antenna connection Slides into the type SIM card memory

COMMANDS USED IN GSM MODEM Receiving SMS messages using AT commands

25 | P a g e

AT+CMGF=1 <ENTER> If the modem responds with "OK" this mode is supported. Please note that using this mode it is only possible to send simple text messages. It is not possible to send multipart, Unicode, data and other types of messages. Setting up the modem: In order to send a SMS, the modem has to be put in SMS text mode first using the following command: AT+CMGF=1 <ENTER> If the modem responds with error, either the modem does not support SMS text mode, or the SIM card is not ready. In this case please check that the SIM card is inserted and the pin code is entered. Reading a message To list a single message, you have to use the read command. You must use the list command first, so you know the indexes of the messages in the storage. For instance, to read the message on memory location '2' use: AT+CMGR=2 <ENTER> The modem will list the single message: +CMGR: "REC READ","+31625012254",,"07/07/05,09:56:03+08" Test message 2 OK Send SMS using AT commands Some advanced GSM modems like Waveform and Multitask, support the SMS text mode. This mode allows you to send SMS messages using AT commands, without the need to encode the binary PDU field of the SMS first. This is done by the GSM modem
26 | P a g e

To check if your modem supports this text mode, you can try the following command: AT+CMGF=1 <ENTER> If the modem responds with "OK" this mode is supported. Please note that using this mode it is only possible to send simple text messages. It is not possible to send multipart, Unicode, data and other types of messages. Sending the message: AT+CMGS="+31638740161" <ENTER> Replace the above phone number with your own cell phone number. The modem will respond with: > You can now type the message text and send the message using the <CTRL>-<Z> key combination: Hello World ! <CTRL-Z> After some seconds the modem will respond with the message ID of the message, indicating that the message was sent correctly: +CMGS: 62

SMS responding Relay or light power ON / OFF commands list. SMS SENDING COMMANDS
27 | P a g e

COMMAND RESPONDING ON / OFF IN HARDWARE

CURRENT STATUS SMS SEND TO THE OWNER NUMBER

*xxxxxS1ON# *xxxxxS2ON# *xxxxxS3ON# *xxxxxS4ON# *xxxxxS1OF# *xxxxxS2OF# *xxxxxS3OF# *xxxxxS4OF# *xxxxxPASSxxxxxx# *xxxxxSTAT#

AC POWERED ON LIGHT POWERED ON FAN POWERED ON MOTOR POWERED ON AC POWERED OFF LIGHT POWERED OFF FAN POWERED OFF MOTOR POWERED OFF PASSWORD CHANGING FORMAT OLD TO NEW ALL APPLICATIONS STATUS ARE SEND TO THE OWNER NUMBER TIME AND DATE UPDATED TO RTC TIME DEPENDENT RELAY ON/OFF OWNER NUMBER CHANGING COMMAND

AC OFF LIGHT OFF FAN OFF MOTOR OFF AC OFF LIGHT OFF FAN OFF MOTOR OFF PASSWORD CHANGED AC ON | IN LIGHT OFF | MOTOR ON | FAN ON | OUT LIGHT OFF ----------OWNER NUBER CHANGED

*xxxxxxTIME DDMMYYHHMMSS# *xxxxxxRONOFddmmyyhh ddmmyyhh# *xxxxxxPHON9791260935#

Sms Command sending sequence: (*) start bit ( xxxxxx ) password (TIME) 4 character command name (#) end bit

MICRO CONTROLLER AT89C51RD2BN

Features: Compatible with MCS-51 Products 8K Bytes of In-System Programmable (ISP)


28 | P a g e

Write/Erase Cycles 4.0V to 5.5V Operating Range Fully Static Operation: 0 Hz to 33 MHz Three-level Program Memory Lock 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Eight Interrupt Sources Full Duplex UART Serial Channel Low-power Idle and Power-down Modes Interrupt Recovery from Power-down Mode Watchdog Timer Dual Data Pointer Power-off Flag AT89c51 pin diagram

It has a 64k program memory space (flash) and 64k external data memory space. One special 16 bit programmable counter array (PCA) is present. It also provides system programming (ISP) facility and operates at 20 MHz max. clock operation. Philips 89c51 has the features of on-chip PWM generation & watchdog timer facility suited for motor control applications.

3.2 89C51 architecture

29 | P a g e

ACCUMULATOR (ACC): Accumulator is a general-purpose register, which stores runtime results. Before performing any operation upon an operand, operand has to be stored in the accumulator. Results of arithmetical operations are also stored in the accumulator. When transferring data from one register to another, it has to go through the accumulator. Due to its versatile role, this is the most frequently used register, essential part of every MCU.

30 | P a g e

B REGISTER: B Register is used along with the Accumulator for multiplication and division. This B register provides temporary storage space for the result of multiplication & division operation. Instructions of multiplication and division can be applied only to operands located in registers A and B. Other instructions can use this register as a secondary accumulator (A).

PORTS: Term "port" refers to a group of pins on a microcontroller which can be accessed simultaneously, or on which we can set the desired combination of zeros and ones, or read from them an existing status. Ports represent physical connection of Central Processing Unit with an outside world. Microcontroller uses them in order to monitor or control other components or devices. 89C51 has 4 ports; with each port have 8-bit length. All the ports are bit and byte addressable.

31 | P a g e

Port 0 (P0): Port 0 has two-fold role: If external memory is used, P0 behaves as address output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at low logical level, otherwise all bits of the port are either input or output. Another feature of this port comes to play when it has been designated as output. Unlike other ports, Port 0 lacks the "pull up" resistor (resistor with +5V on one end). This seemingly insignificant change has the following consequences: When designated as input, pin of Port 0 acts as high impedance offering the infinite input resistance with no "inner" voltage. When designated as output, pin acts as "open drain". Clearing a port bit grounds the appropriate pin on the case (0V). Setting a port bit makes the pin act as high impedance. Therefore, to get positive logic (5V) at output, external "pull up" resistor needs to be added for connecting the pin to the positive pole. Therefore, to get one (5V) on the output, external "pull up" resistor needs to be added for connecting the pin to the positive pole. Port 1 (P1): Port 1 is I/O port. Having the "pull up" resistor, Port 1 is fully compatible with TTL circuits. The alternate functions of Port1 are

32 | P a g e

Pin P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7


Port 2 (P2):

Alternate Name T2 T2EX ECI CEX0 CEX1 CEX2 CEX3 CEX4

Alternate Function Serial input Serial output External interrupt 0 External interrupt 1 Timer 0 external input Timer 1 external input Signal write to external memory Signal read from external memory

When using external memory, this port contains the higher address byte

(addresses A8A15), similar to Port 0. Otherwise, it can be used as universal I/O port. Port 3 (P3): Beside its role as universal I/O port, each pin of Port 3 has an alternate function. In order to use one of these functions, the pin in question has to be designated as input, i.e. the appropriate bit of register P3 needs to be set. By selecting one of the functions the other one is disabled. From a hardware standpoint, Port 3 is similar to Port 0. The alternate functions of Port 3 is given below

Pin P3.0 P3.1


33 | P a g e

Alternate Name RXD TXD

Alternate Function Serial input Serial output

P3.2 P3.3 P3.4 P3.5 P3.6 P3.7

INT0 INT1 T0 T1 WR RD

External interrupt 0 External interrupt 1 Timer 0 external input Timer 1 external input Signal memory Signal read from external memory write to external

Data Pointer (DPTR) : The Data pointer register is made up of two 8 bit registers, named DPH (Data Pointer High) and DPL (Data Pointer Low). These registers are used to give addresses of the internal or external memory. The DPTR is under the control of program. DPTR is also manipulated as one 16 bit register, DPH & DPL are each assigned an address. The 89C51 microcontroller has additional DPTR. The dual DPTR structure is a way by which the chip will specify the address of an external data memory location. There are two 16-bit DPTR registers that address the external memory, and a single bit called DPS (bit0 in AUXR1) that allows the program code to switch between them. Stack Pointer (SP) : The stack refers to an area of internal RAM that is used in conjunction with certain opcodes to store and retrieve data quickly. The register used to access the stack is called Stack Pointer. The 8 bit stack pointer register is used by the 89C51 to hold an internal RAM address that is called then top of the stack. The stack pointer increments before storing the data on the stack. As retrieved from the stack the SP is decremented by one.

34 | P a g e

Program Counter (PC): Used to access code memory. Program counter always points to the address of the next instruction in memory to be executed. Upon reset (or turning the power on), the program counter resets to the starting location of the program. Instruction Register: When an instruction is fetched from the Flash memory, it is loaded in the instruction register. Timing & Control unit: The timing and control unit synchronizes the operation of the microcontroller and generates control signals necessary for communication between the microcontroller and the peripherals. Program Status Word (PSW): The Program Status Word (PSW) register is an 8 bit register. It is also referred to as the flag register. It contains the math flags, user program flag F0, and the register select bits that identify which of the four general purpose register banks is currently in use by the program. Oscillator: Oscillator circuit is used for providing a microcontroller with a clock. Clock is needed so that microcontroller could execute a program or program instructions. Stable pace provided by the oscillator allows harmonious and synchronous functioning of all other parts of MCU. The manufacturers make available 89C51 designs that can run at specified maximum and minimum frequencies, typically 1 megahertz to 33 megahertz. Minimum frequencies imply that some internal memories are dynamic and must always operate above a minimum frequency or data will be lost. Interrupts: An interrupt is a signal from a device attached to a computer or from a program within the computer that causes the main program that operates the computer to stop and points out what to do next. In general, there are hardware interrupts and software interrupts. A hardware interrupt is related to the hardware of the system. For example, when an I/O operation is completed such as reading some data into the computer from a keyboard interrupt the main program. As the name implies the
35 | P a g e

software interrupts related to the software of the system. It occurs when an application program terminates or requests certain services from the operating system. Timers/Counters: Timers are usually the most complicated parts of a microcontroller. Physically, timer is a register whose value is continually increasing to FFFFh, and then it starts all over again: 0h, 1h, 2h, 3h, 4h...FFFFh....0h, 1h, 2h, 3h......etc. The 89C51 MCU clock employs a quartz crystal. As this frequency is highly stable and accurate, it is ideal for time measuring. Since one instruction takes 12 oscillator cycles to complete, the math is easy. 89C51 has three Timers/Counters marked as T0, T1 & T2. Their purpose is to measure time and count external occurrences, but can also be used as clock in serial communication purpose called as, Baud Rate. Serial Port: Serial port is used to provide communication among two devices. Serial data communication has been widely used for long distance communication because of the ease and the economy of using only one wire to transmit data. Serial port is also referred as RS232 port. RS232 is a asynchronous way of communication. Asynchronous transmission allows data to be transmitted without the sender having to send a clock signal to the receiver. Instead, the sender and receiver must agree on timing parameters in advance and special bits are added to each word, which are used to synchronize the sending and receiving units. When a word is given to the UART for Asynchronous transmissions, a bit called the "Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and to force the clock in the receiver into synchronization with the clock in the transmitter.

36 | P a g e

LIGHT DEPENDENT RESISTOR: LDRs or Light Dependent Resistors are very useful especially in light/dark sensorcircuits. Normally the resistance of an LDR is very high, sometimes as high as 1000 000ohms, but when they are illuminated with light resistance drops dramatically. Two cadmium sulphide (cds) photoconductive cells with spectral responses similar to that of the human eye. The cell resistance falls with increasing light intensity. Applications include smoke detection, automatic lighting control, and batch counting and burglar alarm systems.

37 | P a g e

Fig: LDR Fig: Example Circuitry This is an example of a light sensor circuit. When the light level is low the resistance of the LDR is high. This prevents current from flowing to the base of the transistors. Consequently the LED does not light. However, when light shines onto the LDR its resistance falls and current flows into the base of the first transistor and then the second transistor. The LED lights. The preset resistor can be turned up or down to increase or decrease resistance, in this way it can make the circuit more or less sensitive. There are just two ways of constructing the voltage divider, with the LDR at the top, or with the LDR at the bottom: You are going to investigate the behaviour of these two circuits. You will also find out how to choose a sensible value for the fixed resistor in a voltage divider circuit. Remember the formula for calculating Vout : Rbottom x Vin Rbottom x Rtop

Sensitivity: The sensitivity of a photo detector is the relationship between the light falling on the device and the resulting output signal. In the case of a photocell, one is dealing with the relationship between the incident light and the corresponding resistance of the cell. Fig2: Resistance as function of Illumination Fig3: Spectral Response

38 | P a g e

Spectral Response: Like the human eye, the relative sensitivity of a photoconductive cell is dependent on the wavelength (color) of the incident light. Each photoconductor material type has its own unique spectral response curve or plot of the relative response of the photocell versus wavelength of light. Electrical Characteristics:

Applications: Analog Applications Camera Exposure Control Auto Slide Focus - dual cell Photocopy Machines - density of toner
39 | P a g e

Colorimetric Test Equipment Densitometer Digital Applications Automatic Headlight Dimmer Night Light Control Oil Burner Flame Out Street Light Control Absence / Presence (beam breaker) Position Sensor

MEMORY IC (24C16)
Features
Low-voltage and Standard-voltage Operation 2.7 (VCC = 2.7V to 5.5V) 1.8 (VCC = 1.8V to 5.5V) Internally Organized 128 x 8 (1K), 256 x 8 (2K), 512 x 8 (4K), 1024 x 8 (8K) or 2048 x 8 (16K) Two-wire Serial Interface Schmitt Trigger, Filtered Inputs for Noise Suppression Bidirectional Data Transfer Protocol 100 kHz (1.8V) and 400 kHz (2.7V, 5V) Compatibility Write Protect Pin for Hardware Data Protection 8-byte Page (1K, 2K), 16-byte Page (4K, 8K, 16K) Write Modes
40 | P a g e

Partial Page Writes Allowed Self-timed Write Cycle (5 ms max) High-reliability Endurance: 1 Million Write Cycles Data Retention: 100 Years Automotive Grade and Lead-free/Halogen-free Devices Available 8-lead PDIP, 8-lead JEDEC SOIC, 8-lead MAP, 5-lead SOT23, 8-lead TSSOP and 8-ball dBGA2 Packages Die Sales: Wafer Form, Waffle Pack and Bumped Wafers

Description The AT24C01A/02/04/08A/16A provides 1024/2048/4096/8192/16384 bits of serial electrically erasable and programmable read-only memory (EEPROM) organized as 128/256/512/1024/2048 words of 8 bits each. The device is optimized for use in many industrial and commercial applications where low-power and low-voltage operation are essential. The AT24C01A/02/04/08A/16A is available in space-saving 8-

41 | P a g e

lead PDIP, 8-lead JEDEC SOIC, 8-lead MAP, 5-lead SOT23 (AT24C01A/AT24C02/AT24C04),

8-lead TSSOP, and 8-ball dBGA2 packages and is accessed via a Two-wire serial interface. In addition, the entire family is available in 2.7V (2.7V to 5.5V) and 1.8V (1.8V to5.5V) versions.

Pin Description:

42 | P a g e

SERIAL CLOCK (SCL): The SCL input is used to positive edge clock data into each EEPROM device and negative edge clock data out of each device. SERIAL DATA (SDA): The SDA pin is bidirectional for serial data transfer. This pin is open-drain driven and may be wire-ORed with any number of other open-drain or opencollector devices. DEVICE/PAGE ADDRESSES (A2, A1, A0): The A2, A1 and A0 pins are device address inputs that are hard wired for the AT24C01A and the AT24C02. As many as eight 1K/2K devices may be addressed on a single bus system (device addressing is discussed in detail under the Device Addressing section). The AT24C04 uses the A2 and A1 inputs for hard wire addressing and a total of four devices may be addressed on a single bus system. The A0 pin is a no connect. The AT24C08A only uses the A2 input for hardwire addressing and a total of two 8K devices may be addressed on a single bus system. The A0 and A1 pins are no connects. The AT24C16A does not use the device address pins, which limits the number of devices on a single bus to one. The A0, A1 and A2 pins are no connects. WRITE PROTECT (WP): The AT24C01A/02/04/08A/16A has a Write Protect pin that provides hardware data protection. The Write Protect pin allows normal Read/Write operations when connected to ground (GND). When the Write Protect pin is connected to VCC, the write protection feature is enabled

43 | P a g e

44 | P a g e

45 | P a g e

DS1307 RTC
GENERAL DESCRIPTION The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24- hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the battery supply. FEATURES Real-Time Clock (RTC) Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the week, and Year with Leap-Year Compensation Valid Up to 2100 56-Byte, Battery-Backed, Nonvolatile (NV) RAM for Data Storage I2C Serial Interface Programmable Square-Wave Output Signal Automatic Power-Fail Detect and Switch Circuitry Consumes Less than 500nA in Battery Backup Mode with Oscillator Running
46 | P a g e

Optional Industrial Temperature Range: -40C to +85C Available in 8-Pin DIP or SO

47 | P a g e

I2C DATA BUS The DS1307 supports the I2C protocol. A device that sends data onto the bus is defined as a transmitter and a device receiving data as a receiver. The device that controls the message is called a master. The devices that are controlled by the master are referred to as slaves. The bus must be controlled by a master device that generates the serial clock (SCL), controls the bus access, and generates the START and STOP conditions. The DS1307 operates as a slave on the I2C bus. Data transfer may be initiated only when the bus is not busy.

48 | P a g e

During data transfer, the data line must remain stable whenever the clock line is HIGH. Changes in the data line while the clock line is high will be interpreted as control signals. Accordingly, the following bus conditions have been defined: Bus not busy: Both data and clock lines remain HIGH. Start data transfer: A change in the state of the data line, from HIGH to LOW, while the clock is HIGH, defines a START condition. Stop data transfer: A change in the state of the data line, from LOW to HIGH, while the clock line is HIGH, defines the STOP condition. Data valid: The state of the data line represents valid data when, after a START condition, the data line is stable for the duration of the HIGH period of the clock signal. The data on the line must be changed during the LOW period of the clock signal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and terminated with a STOP condition. The number of data bytes transferred between START and STOP conditions is not limited, and is determined by the master device. The information is transferred byte-wise and each receiver acknowledges with a ninth bit. Within the 2-wire bus specifications a standard mode (100kHz clock rate) and a fast mode (400kHz clock rate) are defined. The DS1307 operates in the standard mode (100kHz) only. Acknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the reception of each byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit. A device that acknowledges must pull down the SDA line during the acknowledge clock pulse in such a way that the SDA line is stable LOW during the HIGH period of the acknowledge related clock pulse. Of course, setup and hold times must be taken into account. A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that has been clocked out of the slave. In this case, the slave must leave the data line HIGH to enable the master to generate the STOP condition.

49 | P a g e

50 | P a g e

POWER SUPPLY UNIT

Power supply is to provide the required level of DC power to the load using an AC supply at the input. Different applications require different attributes, but more often than not these days DC power supplies provide an accurate output voltage - this is regulated using electronic circuitry so that it provides a constant output voltage over a wide range of output loads. In most power supplies there are number of different elements. These may not all be present in every design.

Input transformer: The input transformer is used to transform the incoming line voltage down to the required level for the power supply. Typically the input transformer provides a step down function. It also isolates the output circuit from the line supply.

Rectifier: The power supply rectifier converts the incoming signal from an AC format into raw DC. Either half wave or more commonly full wave rectifiers may be used as they make use of both halves of the incoming AC signal.

51 | P a g e

Smoothing: The raw DC from the rectifier is far from constant falling to zero when the AC waveform crossed the zero axis, and then rising to its peak. The addition of a reservoir capacitor here fills in the troughs in the waveform, enabling the next stage of the power supply to operate. Large value capacitors are normally used within this stage.

Regulator: This stage of the power supply takes the smoothed voltage and uses a regulator circuit to provide a constant output virtually regardless of the output current and any minor fluctuations in the input level.

POWER SUPPLY CIRCUIT

Fig 5.3 Voltage regulator circuit Diagram

52 | P a g e

SOURCE CODE C PROGRAM

#include <reg51.H> #define LCD_PORT P2 #define REL_PORT P0 #define RON 1 #define ROFF 0 #define ON 0 #define OFF 1 sbit RS = P2^0; sbit EN = P2^1; sbit data0 = P2^2; sbit data1 = P2^3; sbit data2 = P2^4; sbit data3 = P2^5; sbit sbit sbit sbit sbit sbit sbit sbit RELAY1 RELAY2 RELAY3 RELAY4 sense1 sense2 sense3 sense4 = P0^4; = P0^5; = P0^6; = P0^7; = P0^0; = P0^1; = P0^2; = P0^3;

//port2 for lcd connections //port0 for relay connections //buzzer pin on state //buzzer pin off state //buzzer pin on state //buzzer pin off state //register select pin of LCD //enable pin for LCD //data pin bit 0(LSB) //data pin bit 1 //data pin bit 2 //data pin bit 3 //relay1 control pin //relay2 control pin //relay3 control pin //relay4 control pin //sensor pin 1 //sensor pin 2 //sensor pin 3 //sensor pin 4 //SDA pin for RTC memory //SCL pin for RTC memory //clock pin for memory //data pin for mempry //buzzer pin (void); (void); (void); (void); (void); (void); (unsigned char ); (unsigned char ); (unsigned char ); (unsigned char ); (unsigned char ); (unsigned char ); (unsigned char *); (unsigned char *); //delay of 1 milli seconds //delay of 3 milli seconds //30 milli second delay //delay of 1 second //routine to initialise LCD //clears LCD screen //displays the value in digits //displays one char //sets the display position //writes data in to LCD as instruction //writes one byte into LCD as data //writes one byte into LCD //prints a line on LCD //prints a line on LCD //initialise serial communication

sbit rtc_SDA = P3^6; sbit rtc_SCL = P3^27 sbit SCL = P3^4; sbit SDA = P3^5; sbit buzzer = P1^6; void del_1ms void del_3ms void del_30ms void del_1s void lcd_init void clear_display void display_digits void display_data void set_add void write_in void write_data void write void printLcd void printLcd2 void serial_init (void);

53 | P a g e

void send_digits (unsigned char); //sends the digits to PC void send_byte (unsigned char); //sends ASCII value to PC void sendString (unsigned char *str); unsigned char recv_byte (void); //recieves th ASCII unsigned char read_byte (unsigned char); //reads 1 byte from specified location of card unsigned char read_mem (void); //clocks out 8 bits of data to card void start_bits (void); //start condition void stop_bits (void); //stop condition void write_byte (unsigned char,unsigned char); //writes 1 byte from specified location of card void write_mem (unsigned char); //clocks in 8 bits of data to card void beep(void); void rtc_init (void); //RTC initialisation void read_time (void); //erad time from RTC void display_time (void); //diplay time to LCD void rtc_start_bits (void); //rtc start bits void rtc_stop_bits (void); //rtc stop bits void write_rtc (unsigned char); //to write data to rtc unsigned char rtc_read_ack (void); //read with ack bit unsigned char rtc_read_noack(void); //read with no ack bit void compare_time (void); //to compare the current time to stored time void time_set (void); //set the time for perticular relay void enter (void); //for enter command void modem_init (void); //routine for modem void send_error (void); //sending the error void status_owner (void); //sending the error s void password (void); //for changing void phone_no (void); //to change the owner void data_compare (void); //to compare the data void status (void); //send the status to s unsigned char recv_sms_no(void); //read the sms number from void read_sms (unsigned char ); //read the message from modem void delete_sms (unsigned char ); //deleting the sms from mode void sensor_owner (unsigned char *); //sending the sensor output unsigned char volatile xdata datas[4],new[16],run,dum,check,nos,result,s1,s2,s3,s4; unsigned char volatile xdata com1[4]="S1ON",com2[4]="S1OF",com3[4]="S2ON",com4[4]="S2OF",com5[4]="S3ON",com6[4]="S3OF"; unsigned char volatile xdata com7[4]="PASS",com8[4]="PHON",com9[4]="STAT",comA[4]="S4ON",comB[4]="S4OF",comC[4]="TIME"; unsigned char volatile xdata seconds,hours,minutes,weekdays,date,month,year; unsigned int volatile xdata times; void main() { unsigned char volatile no; del_30ms(); del_30ms(); lcd_init(); serial_init(); REL_PORT=0XF0;del_30ms(); clear_display(); //initial delay //initialisations of serial,lcd

if(read_byte(0x55) != 'T') { del_3ms(); write_byte(0x55,'T'); for(no=10;no<16;no++) {

//checking of new memory //if it is new store initial datas //memory locaions of //0-9 for sender phone //10-15 for password

54 | P a g e

write_byte(no,'0'); } rtc_init(); } printLcd("SYSTEM INSTALING"); printLcd2("PLZ WAIT....... "); printLcd(" GSM USING "); printLcd2("HOME AUTOMATION"); del_s(); printLcd(" YUVARAJA.R "); printLcd2("REG NO : 6109314"); del_s(); printLcd("MAHER UNIVERSITY"); printLcd2(" B.E ECE (P.T) "); del_s(); printLcd(" PROJECT GUIDE "); printLcd2(" THAMIL SELVAN "); del_s(); printLcd(" GSM printLcd2(" "); ");

//20-29 for owner number //30-34 for enter time

del_1s();del_1s(); del_1s();del_1s(); del_1s(); modem_init(); printLcd(" GSM MODEM "); printLcd2(" "); TR0=1; while(1) { if(RI) { TR0=0; no=recv_sms_no(); if(RI) read_sms(no); data_compare(); delete_sms(no); TR0=1;del_30ms();RI=0;

//initial delays for initialisation //modem initialisation

//checking of MSG //receive the SMS NO from //read the MSG from simcard //compare the stament to stored //deleting of MSG

} //following datas for checking the sensor if((!sense1) && (s1==0)) {sensor_owner("FIRE DETECTED ");s1=1;} if((!sense2) && (s2==0)) {sensor_owner("HIGH VOLTAGE DETECTED");s2=1;}

55 | P a g e

if((!sense3) && (s3==0)) {sensor_owner("RPM OF MOTOR IS HIGH");s3=1;} if((!sense4) && (s4==0)) {sensor_owner("PRODUCTION COMPLETED");s4=1;} if(sense1) if(sense3) s1=0;if(sense2) s3=0;if(sense4) s2=0; s4=0;

if(times >= 0x0100) { read_time(); display_time(); if(read_byte(0x51)=='1') compare_time(); times=0; } } } void timer0(void) interrupt 1 { times ++; } /* ROUTINES FOR GSM */ //ROUTINE FOR INITIALIZATION OF MODEM void modem_init() { unsigned char volatile ch[20],i=0; //checking for AT command clear_display(); del_30ms(); set_add(0x80); send_byte('A'); display_data(recv_byte()); send_byte('T'); display_data(recv_byte()); enter(); while(i<6) { ch[i++]=recv_byte(); } if(ch[5]=='K') printLcd("INSTALING... "); else { printLcd2("ERROR... "); modem_init(); } //timer count for reading the rtc time //read the time from rtc //display the time to lcd //checking of weather time is setted or not //compare the stored time

//receiving the eachoback character //receiving the eachoback character //entering //response from modem

//checking of last character OK //if last character is not OK /print error

56 | P a g e

//removing eaco char del_1s();i=0;RI=0; clear_display(); del_30ms(); set_add(0x80); send_byte('A'); display_data(recv_byte()); send_byte('T'); display_data(recv_byte()); send_byte('E'); display_data(recv_byte()); send_byte('0'); display_data(recv_byte()); enter(); while(i<6) { ch[i++]=recv_byte(); } if(ch[4]=='K') printLcd("INSTALING... "); else { printLcd2("ERROR...........");//print error modem_init(); } //setting the text command del_1s();i=0;RI=0; clear_display(); del_30ms(); set_add(0x80); sendString("AT+CMGF=1"); enter(); while(i<6) { ch[i++]=recv_byte(); } if(ch[3]=='K') printLcd("INSTALING... "); else { printLcd2("ERROR...........");//print error modem_init(); } // to enable the sms del_1s();i=0;RI=0; clear_display(); del_30ms(); set_add(0x80); sendString("AT+CNMI=1"); enter(); while(i<6) //following comands for getting infomation //from MODEM that is MSG received //response from modem //following comands for getting text //comand from MODEM //response from modem //following comands for removing //the eacho character from MODEM

//response from modem

//checking of last character OK //if last character is not OK

//checking of last character OK //if last character is not OK

57 | P a g e

{ ch[i++]=recv_byte(); } if(ch[3]=='K') printLcd("MODEM SETTED.. "); else { printLcd("NOT SETTED... ");//print error modem_init(); } del_1s();i=0;RI=0; clear_display(); del_30ms(); set_add(0x80); } //RECEIVING THE SMS ID FROM MODEM set_add(0xC1); j=0; for(i=1;i<11;i++) { display_data(ch[i]); write_byte(j,ch[i]); j++; } del_30ms(); //password checking while(ch[i]!='*') i++; for(j=10;j<16;j++) { i++; if(read_byte(j)!=ch[i]) { printLcd("PASSWORD "); printLcd2(" INCORRECT"); k=0; send_error(); del_1s(); break; } else k=1; } //taking STATEMENT and DATA if(k) { for(j=0;j<4;j++) { i++; datas[j]=ch[i]; } for(j=0;j<15;j++) { i++; new[j]=ch[i]; //checking of last character OK //if last character is not OK

//for taking the received number from SIM

//from "*" to 6chars are password

//compare the password with stored pass

//password is correct

//take the 4char statement //STATEMENT

//remainig for pass,phone,time

58 | P a g e

} } del_30ms();RI=0; return; } //ROUTINE FOR DELETING THE MESSAGE void delete_sms(unsigned char msg) { unsigned char volatile ch[20],i=0; del_1s();RI=0; sendString("AT+CMGD="); del_1ms(); send_byte(msg); enter(); while(i<6) { ch[i++]=recv_byte(); } if(ch[3]=='K') { printLcd("SMS DELETED... "); printLcd2(" "); beep(); del_1s(); printLcd(" GSM MODEM "); printLcd2(" "); RI=0; } else { printLcd("NOT DELETED... "); printLcd2(" "); delete_sms(msg); } } void data_compare() { if(!strncmp(datas,com1,4)) { RELAY1 = RON; status_owner(); } else if(!strncmp(datas,com2,4)) { RELAY1 = ROFF; status_owner(); } else if(!strncmp(datas,com3,4)) { RELAY2 = RON; status_owner(); } //following commands for compare //OUR fomate with received fomate

//following commands for delete the //MSG after reading //(AT+CMGD=1)

//response from modem

59 | P a g e

else if(!strncmp(datas,com4,4)) { RELAY2 = ROFF; status_owner(); } else if(!strncmp(datas,com5,4)) { RELAY3 = RON; status_owner(); } else if(!strncmp(datas,com6,4)) { RELAY3 = ROFF; status_owner(); } else if(!strncmp(datas,comA,4)) { RELAY4 = RON; status_owner(); } else if(!strncmp(datas,comB,4)) { RELAY4 = ROFF; status_owner(); } else if(!strncmp(datas,comC,4)) time_set(); else if(!strncmp(datas,com7,4)) password(); else if(!strncmp(datas,com8,4)) phone_no(); else if(!strncmp(datas,com9,4)) status(); else { send_error(); del_1s();RI=0; } } //ROUTINE FOR PASSWORD CHAGE void password() { unsigned char i=0; for(nos=10;nos<16;nos++) { write_byte(nos,new[i]); i++; } printLcd("PASSWORD CHANGED"); printLcd2(" "); del_1s(); } //ROUTINE FOR PHONE NUMBER CHANGE void phone_no() { unsigned char i=0;

//command for set the time for //perticular relay //for password change //for phone number change //FOR SENDING THE STATUS TO SENDER //if commaands are not matched //send error MSG to sender

//for replacing the new password

60 | P a g e

for(nos=20;nos<30;nos++) { write_byte(nos,new[i]); i++; } printLcd(" OWNER PHONE "); printLcd2(" NUMBER CHANGED "); del_1s(); } //ROUTINE FOR SET THE TIME void time_set() { unsigned char i,j; j=0;i=0; for(run=30;run<35;run++) { i = new[j] & 0x0f; i=i<<4;j++; dum=new[j] & 0x0f; dum = i|dum;j++; write_byte(run,dum); } write_byte(run,new[j]); write_byte(0X51,'1'); }

//replacing the owner phone number

//store thereceived time to memory //with conversion of dec to hex

//storing the relay status

//COMPARING OF CURRENT TIME TO STORED TIME void compare_time() { //following commands for compare thye result=0; //stored time with current time if(date==read_byte(30)) if(month==read_byte(31)) if(year==read_byte(32)) if(hours==read_byte(33)) if(minutes>=read_byte(34)) result = 1; del_3ms(); if(result==1) { if(read_byte(35)=='Y') //switch on the relay { RELAY4=RON; sensor_owner("YOUR TIMER RELAY HAS SWITCHED ON"); } else { RELAY4=ROFF; sensor_owner("YOUR TIMER RELAY HAS SWITCHED OFF"); } write_byte(0X51,'0'); } } void status()

61 | P a g e

{ printLcd(" MESSAGE SENDING"); printLcd2(" "); dum = REL_PORT; del_1s();RI=0; sendString("AT+CMGS="); send_byte('"'); for(run=0;run<10;run++) send_byte(read_byte(run)); send_byte('"'); enter(); run=0; while(run!='>') { run=recv_byte(); } del_1ms();RI=0; if(dum & 0x01) sendString(" RELAY1 ON"); else sendString(" RELAY1 Off"); if(dum & 0x02) sendString(" RELAY2 ON"); else sendString(" RELAY2 Off"); if(dum & 0x04) sendString(" RELAY3 ON"); else sendString(" RELAY3 Off "); if(dum & 0x08) sendString(" RELAY4 ON"); else sendString(" RELAY4 Off "); del_1ms(); send_byte(0x1A); run=0; while(run!='K') { run=recv_byte(); } del_30ms(); beep(); RI=0; } void sensor_owner(unsigned char *sen) { printLcd(" MESSAGE SENDING"); printLcd2(" "); del_1s();RI=0; sendString("AT+CMGS="); send_byte('"'); //following are checking the status //following commands for sending the relay //status to sender //command

//following commands for checking the sensor //and send sensor status to owner

62 | P a g e

for(run=20;run<30;run++) send_byte(read_byte(run)); send_byte('"'); enter(); run=0; while(run!='>') { run=recv_byte(); } del_1ms();RI=0; sendString(sen); del_1ms(); send_byte(0x1A); run=0; while(run!='K') { run=recv_byte(); } del_30ms(); beep();RI=0; printLcd(" GSM MODEM "); printLcd2(" "); del_1s();RI=0; } void printLcd2(unsigned char *str) { unsigned char len,i; len = strlen(str); set_add(0xC0); for(i=0;i<len;i++) { display_data(*str); str++; } } //rouine to set the display position void set_add(unsigned char ch) { unsigned char dummy; dummy = ch; ch &= 0xf0; write_in(ch); ch = dummy; ch &= 0x0f; ch = ch << 4; write_in(ch); } //sets display position in first line

//displays the character on LCD

//backup in variable //takes MSByte //writes it as instruction //loads original value //takes LSByte //writes it as instruction

//routine to write an instruction to LCD

63 | P a g e

void write_in(unsigned char ch) { data0 = 0; data1 = 0; data2 = 0; data3 = 0; // } //routine to write a data to LCD void write_data(unsigned char ch) { data0 = 0; data1 = 0; data2 = 0; data3 = 0; // } //routine to transfer 8 bits to LCD module void write(unsigned char ch) { LCD_PORT |= ch; EN = 1; del_3ms(); EN = 0; del_3ms(); } //routine to initialise the lcd void lcd_init(void) { del_30ms(); del_30ms(); write_in(0x20); del_3ms(); write_in(0x20); del_3ms(); write_in(0xc0); del_3ms(); //Display on/off write_in(0x00); del_3ms(); write_in(0xc0); del_3ms(); RS = 1; ch = reverse(ch); ch = ch >> 2; write(ch); //rs = 1 fopr data //transfers 8 bits to LCd module RS = 0; ch = reverse(ch); ch = ch >> 2; write(ch); //rs =0 for instr //routine to transfer 8 bits to LCD

//preserves the old value of port //enable pin high //enable = 0

//function set

64 | P a g e

//display clear write_in(0x00); del_3ms(); write_in(0x10); del_3ms(); //Entry mode set write_in(0x00); del_3ms(); write_in(0x60); del_3ms(); } //memory routines unsigned char read_byte(unsigned char add1) { unsigned char ch; start_bits(); write_mem(0xa0); write_mem(add1); //i2c standard start condition //device address //writes device address to memory module //writes location address to memory module

start_bits(); write_mem(0xa1); ch = read_mem(); stop_bits(); return(ch); }

//i2c standard start condition //control word to initiate a read operation //reads a byte from memory module //i2c standard stop condition

//this routine writes the character in value variable to the location specified by mem_add variable void write_byte(unsigned char add1,unsigned char dat) { start_bits(); write_mem(0xa0); write_mem(add1); write_mem(dat); stop_bits(); del_3ms(); } //this routine takes one byte transfered by memory module unsigned char read_mem() { unsigned char i,j,ch=0; SDA = 1; for(i=0;i<8;i++) { //release data pin to recieve values

//i2c standard start condition //device address for memoru module //writes a character to memory module //writes the location address to memory module //writes the data to the location specified //i2c standard stop condition

65 | P a g e

SCL = 0; for(j=0;j<5;j++); SCL = 1; ch = ch << 1; if(SDA == 1) ch |= 0x01; SCL = 0; } SDA = 1; SCL =1; for(j=0;j<5;j++); SCL = 0; return(ch); } //i2c standard start condition void start_bits() { unsigned char i; SDA = 1; SCL = 1; for(i=0;i<5;i++); SDA = 0; for(i=0;i<5;i++); SCL =0; for(i=0;i<5;i++); } //i2c standard stop condition void stop_bits() { unsigned char i; SDA= 0; SCL =1; for(i=0;i<5;i++); SDA =1; for(i=0;i<5;i++); SCL =0; for(i=0;i<5;i++); SCL = 1; } //this routine writes a byte into memroy module void write_mem(unsigned char ch) { unsigned char i,j; for(i=0;i<8;i++) { if(ch & 0x80)

//starts a bit period //one bit period over

//one bit period for acknowledge bit

66 | P a g e

SDA = 1; else SDA = 0; ch = ch << 1; SCL =1; for(j=0;j<5;j++); SCL = 0; } SDA = 1; SCL = 1; for(j=0;j<5;j++); SCL = 0; del_3ms(); //transfers one bit //starts a bit period //end of one bit period

//one bit period for acknowledgement

// }

//routin to RTC CONTROLS void rtc_init(void) { del_30ms(); rtc_start_bits(); write_rtc(0xd0); write_rtc(0x00); write_rtc(seconds); write_rtc(minutes); write_rtc(hours); write_rtc(weekdays); write_rtc(date); write_rtc(month); write_rtc(year); rtc_stop_bits(); rtc_start_bits(); write_rtc(0xd0); write_rtc(0x00); write_rtc(0x00); rtc_stop_bits(); return; } void read_time(void) { unsigned char dat; rtc_start_bits(); write_rtc(0xd0); write_rtc(0x00); rtc_start_bits(); write_rtc(0xd1); dat=rtc_read_ack(); seconds = 0x7f & dat;

67 | P a g e

dat=rtc_read_ack(); minutes = 0x7f & dat; dat=rtc_read_ack(); hours = 0x3f & dat; dat=rtc_read_ack(); weekdays = 0x07 & dat; dat=rtc_read_ack(); date = 0x3f & dat; dat=rtc_read_ack(); month = 0x1f & dat; dat=rtc_read_noack(); year = dat; rtc_stop_bits(); } unsigned char rtc_read_ack(void) { unsigned char i,j,ch=0; rtc_SDA=1; for(i=0;i<8;i++) { rtc_SCL=0; for(j=0;j<6;j++); rtc_SCL = 1; ch = ch << 1; if(rtc_SDA == 1) ch |= 0x01; for(j=0;j<6;j++); rtc_SCL = 0; } rtc_SDA = 0; rtc_SCL =1; for(j=0;j<6;j++); rtc_SCL = 0; return(ch); } unsigned char rtc_read_noack() { unsigned char i,j,ch=0; rtc_SDA = 1; for(i=0;i<8;i++) { rtc_SCL = 0; for(j=0;j<6;j++); rtc_SCL = 1; ch = ch << 1; if(rtc_SDA == 1) ch |= 0x01;

//one bit period over

//one bit period for acknowledge bit

//release data pin to recieve values //starts a bit period //one bit period over

68 | P a g e

for(j=0;j<6;j++); rtc_SCL = 0; rtc_SDA = 1; } rtc_SCL =1; for(j=0;j<6;j++); rtc_SCL = 0; return(ch); } //i2c standard start condition void rtc_start_bits() { unsigned char i; rtc_SDA = 1; rtc_SCL = 1; for(i=0;i<6;i++); rtc_SDA = 0; for(i=0;i<6;i++); rtc_SCL =0; for(i=0;i<6;i++); } void write_rtc(unsigned char ch) { unsigned char i,j; for(i=0;i<8;i++) { if(ch & 0x80) rtc_SDA = 1; else rtc_SDA = 0; rtc_SCL = 1; for(j=0;j<6;j++); rtc_SCL = 0; for(j=0;j<6;j++); rtc_SDA = 1; ch = ch << 1; } rtc_SCL = 1; for(j=0;j<6;j++); rtc_SCL = 0; } void del_30ms() { unsigned char j; for(j=0;j<10;j++) del_3ms(); } void del_1s() { unsigned char i; for(i=0;i < 60;i++) del_30ms();

//one bit period for acknowledge bit

69 | P a g e

}
// END

CONCLUSION Recent development in Science and Technology provide a wide range of scope of application of reduction power wastage. This project is useful in the domestic as well in the industrial applications. It has the scope to enhance several devices by appropriate add-on circuits. Even the Vibration , Glass Break, Fire or Smoke detector can be configured to report to the user. The cost involved is moderate and the status can be sent to the user(s) for the decision

70 | P a g e

FUTURE ENHANCEMENT

In this project in future we can add a multimedia camera to see what is going inside the home by sitting in office or somewhere to view the video using 3g technology.

71 | P a g e

REFERENCES

David Tse, Pramod Viswanth (2005) Fundamentals of Wireless Communication Cambridge University Press, Edition-I Goankar Ramesh Goankar (2006), Fundamentals of Microcontroller and applications in Embedded system with PIC o Cengafe Demalmar Learning Publishers,Edition-1

Larry O Cull,Richard Bennett, Sarah Cox (2003), Embeded C Programming and Microchip PIC Cengage Demalmar Learning Publishers Edition-I

Siegmund Redl, Mathias K.Weber (1995), Introduction to GSM Artech house Publishers Edition-1

Thodre S. Rapport (2001), Wireless Communication Principle and Practice Pearson Educaion Publishers. Edition-2

John B.Peatman (1988), Design with Microcontrollers McGraw Hill International Edition-1

72 | P a g e

Bruce Carlson, Communication Systems, Tata McGraw Hill, 1986

73 | P a g e

You might also like