message based home automation & security system

109
MESSAGE BASED HOME AUTOMATION AND SECURITY SYSTEM By Hassan Mahmood Polash S.M. Istiaque Sekander Md. Jahid Hassan Srijohn Kumar Roy Department of Electrical & Electronics Engineering 12

Upload: jahid-hassan

Post on 14-Apr-2017

777 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Message based home automation  & security system

MESSAGE BASED HOME AUTOMATION AND SECURITY SYSTEM

By

Hassan Mahmood Polash

S.M. Istiaque Sekander

Md. Jahid Hassan

Srijohn Kumar Roy

Department of Electrical & Electronics Engineering

UNIVERSITY OF INFORMATION TECHNOLOGY & SCIENCES

12

Page 2: Message based home automation  & security system

MESSAGE BASED HOME AUTOMATION AND SECURITY SYSTEM

This Project report is submitted to the Department of Electrical and Electronic Engineering, University of Information Technology and Sciences (UITS), in partial fulfillment of the requirement for the degree of Bachelor of Science in Electrical and Electronic Engineering (EEE).

A PROJECT REPORT

SUBMITTED BY

Hassan Mahmood Polash S.M. Istiaque Sekander

ID: 09530173 ID: 09530176

Md. Jahid Hassan Srijohn Kumar Roy

ID: 09530177 ID: 10330305

SUPERVISED BY

DEEPAK KUMAR CHOWDHURY

ASSISTANT PROFESSOR

Department of EEE, UITS

Department of Electrical & Electronics Engineering

UNIVERSITY OF INFORMATION TECHNOLOGY & SCIENCES

13

Page 3: Message based home automation  & security system

MESSAGE BASE HOME AUTOMATION AND SECURITY SYSTEM

A Project Report Submitted

By

Hassan Mahmood Polash

S.M. Istiaque Sekander

Md. Jahid Hassan

Srijohn Kumar Roy

For the partial fulfillment of degree of

B.Sc in Electrical and Electronics Engineering

Examination held in December , 2014.

Approved By

____________________________

Deepak Kumar Chowdhury

Supervisor,

Assistant Professor, Depart of EEE

________________________

14

Page 4: Message based home automation  & security system

External/Second Examiner

15

Page 5: Message based home automation  & security system

ACKNOWLEDGEMENT

At first we are grateful to the almighty God owner of the supreme power and universe for giving

us the energy and ability to complete our Project work successfully.

For this project, we would like to express cordial and endless gratitude from the string of our

heart to our project supervisor Deepak Kumar Chowdhury, Assistant Professor, Department of

Electrical & Electronic Engineering, University of Information Technology & Sciences (UITS)

whose important, brave and aspiratory directions, suggestions, cooperation and cordial behavior

makes us possible to finish our Project work fruitfully. Without his guidance it was almost

impossible to carry out with the project work. He had been very helpful and ever affectionate to

endure this mistakes we had committed in the project and always encouraged us by correcting

our wrong proceedings. We would also like to express our gratefulness to all the teachers of the

EEE department for helping us several times. We would like to give special thanks to our friends

and finally we want to express our deep gratitude to our beloved parents who are the source of

inspiration and happiness in our everyday life.

Finally, we would like to thank our respective families for their constant encouragement and

support.

Authors

Hassan Mahmood Polash S.M. Istiaque SekanderMd. Jahid HassanSrijohn Kumar Roy

16

Page 6: Message based home automation  & security system

CHAPTER 1

INTRODUCTION

1.1 INTRODUCTION

Home Automation & Security System is the residential extension of building automation. Home

automation system may include centralized control of lighting, HVAC (heating, ventilation and

air conditioning), appliances, security locks of gates and doors and other systems, to provide

improved convenience, comfort, energy efficiency and security. [1]

A home automation system may include simple automated door opener to complete automation

of home appliances. Usual home automation feature may include ambient light intensity control,

temperature and humidity monitor and control system etc. Home automation helps people to get

things done conveniently. For example, it helps to turn on the microwave oven from the office

laptop, remotely start vacuuming, etc. Home automation system can be extended to home

security monitoring system. A home security system may include intruder alarm system to

CCTV monitoring facilities. The basic aim of Home automation is to control or monitor signals

from different appliances.

Home automation is a growing trend. Automation systems can control important systems like

lighting and temperature controls as well as entertainment systems and even curtains. Though

costly, control systems can ease the lifestyle of a homeowner greatly. Depending upon which

sort of control system is purchased, the ease of the customer’s life can be exponentially

increased. Especially with central control systems, users can change the temperature and lighting

in their house with a flick of the finger. No longer is it necessary to worry about leaving the heat

running or burning out light bulbs that were mistakenly left on.

In this thesis we have presented simplicity in design, a standard compatible platform of home

automation & security system. Our designed system includes a GSM modem and a

microcontroller based monitoring and control device that allows monitoring from any distance,

over GSM network using short message service (SMS). Multiple sensors feed surrounding

17

Page 7: Message based home automation  & security system

environment information to the microcontroller like – temperature and humidity and also

monitors gas leakage or smoke and human presence. And microcontroller sends that information

via SMS to a cell phone number by using a GSM modem. Our designed system constantly

monitors the temperature and humidity and display on a LCD. If the temperature reaches 50ºC

the microcontroller turns off the main power supply of the house. We have selected 50ºC,

because it is very unusual temperature for human comfort and household temperature

considering our geographical position. Hence this lead to one assessment that some, flammable

object is on fire in smaller magnitude or some electrical home appliance is about to catch fire.

Since most of the modern electrical home appliance generates temperature between 20ºC to

35ºC.

1.2 BACKGROUND

Home automation is adopted for reasons of ease, security and energy efficiency. In modern construction in most homes have been wired for electrical power, telephones, TV outlets (cable or antenna), and a doorbell. Many household tasks were automated by the development of specialized automated appliances. For instance, automatic washing machines were developed to reduce the manual labor of cleaning clothes, and water heaters reduced the energy necessary for bathing. If no one is supposed to be home and the alarm system is set, the Home Automation & Security System could call the owner, or the neighbors, or an emergency number if an intruder is detected. [1]

In simple installations, automation may be as straightforward as turning on/off the lights when a person enters the room. In advanced installations, rooms can sense not only the presence of a person inside but know who that person is and perhaps set appropriate lighting, temperature, music levels or television channels, taking into account the day of the week, the time of day, and other factors.

An example of remote monitoring in home automation could be triggered when a smoke detector detects a fire or smoke condition, causing all lights in the house to blink to alert any occupants of the house to the possible emergency. The system could also call the home owner on their mobile phone to alert them, or call the fire department or alarm monitoring company.

1.3 IMPORTANCE OF THE WORK

Home automation systems that are available in market are very expensive. Moreover it also includes high monthly service charge and installation cost. Also this system requires internet connection to operate; hence the user also has to bear internet subscription fees.

As the demand of home automation system increases, so is the complexity of construction and maintenance cost. Our goal for this project to develop a home automation system that is not only

18

Page 8: Message based home automation  & security system

simple in construction and low on maintenance cost, but also a standard compatible platform of home automation & security system. To do so, we have used four sensors (temperature sensor, humidity sensor, gas detector and PIR motion sensor) and interfaced with a microcontroller. We have tried to provide access to the user, that information about the sensors instantly from a LCD display as well as through SMS.

1.4 OBJECTIVE

Our objective is to construct a cost effective home automation system. Also to make a system which is easy to operate and low on maintenance cost. And to make a safety monitoring system that provides security against fire damage and

intruder. And to develop an automation system that can control main power supply of a house.

1.5 APPLICATION

There is several application of our project:

This project includes interfacing of temperature and humidity sensors. This concept can be used for manufacturing and processing industries.

It is also represent the use of several security features such as motion sensing ability which can be used for monitoring house, office, restricted area etc. for human trespassing.

It also includes a gas leakage detector which can be used in deep sea drilling rig, oil tanker ships for hazardous gas leakage and combustion gas detection.

This project features usage of GSM modem and SMS; this can be extended over GSM data service, like GPRS, EDGE, 3G internet for monitor and control wide range of modern home appliance over any distance and even lower cost.

19

Page 9: Message based home automation  & security system

1.6 BLOCK DIAGRAM:

1.7 METHODOLOGY

The purpose of the project is to develop an automation system based on PIC Microcontroller and GSM modem. The sensors are connected to microcontroller. Microcontroller converts the analog input into digital signal and analyzes, then takes actions to accordance. Our project’s systematic flow chart and explanation of work are given below:

20

Figure 1 Block Diagram of Proposed System

Page 10: Message based home automation  & security system

21

Figure 2 Methodology

Page 11: Message based home automation  & security system

1.7.1 EXTENSIVE LITERATURE REVIEW

In recent years there has been an exponential growth and advancement in computing technology. There has also been use of these technologies even among non-technical users as they are no longer limited to personal computers that occupy fixed desk space. Instead there has been an increasing trend towards global computing that integrates seamlessly into peripheral environment to assist ones day to day life.

Several standards have been proposed each day promising to solve standards issue. Home automation is not different. At very basic level home automation is introduced as early as 19th century with the introduction of water supply and energy distribution system. Science then several solutions was proposed by the industry and academia; but the progress has been relatively slow. Few system aims to solve issues such as ease of access and scalability, such as Microchip’s X-10. In early 2000’s, there has been several academic research were published regarding home automation, such as – in University of Utah, Utah, USA Kevin Brown, Don DeLaMare and Brian Faires proposed an land phone based home automation and security system, where a door, window, motion sensors are integrated to a MC9S12C32 microcontroller (which serve as a slave microcontroller to collect and analyze data from sensors) and a thermostat control unit and a land phone is integrated to another MC9S12C32 microcontroller (which serve as a master microcontroller to control and dial a fixed number if required). A MC9S12C32 is a powerful 16-bit microcontroller by Freescale Semiconductor Inc. It has 32KB of program memory and 4KB RAM with 52 general purpose I/O pin, with a 16-channel ADC module. In the project by Kevin Brown, Don DeLaMare and Brian Faires, they used two MC9S12C32 microcontroller, one as master and another as slave, connected to each other over I2C (inter-integrated circuit) communication protocol. The slave microcontroller is integrated with three sensors (door, window and motion) to monitor the internal situation of a house. If any of this sensor triggers then the slave microcontroller sends a signal to the master microcontroller. The master microcontroller is integrated with a keypad and a land phone. If any of the sensor were triggered then the microcontroller wait for 10 seconds for an authorized password entry from the keypad; otherwise it dials 911(emergency number in USA) to call the police.

Our system includes one 8-bit PIC16F877A microcontroller by Microchip Inc. It has 8KB program memory and 368 bytes RAM with 33 general purposes I/O pin. Since land phone are rarely used in modern days hence we replaced land phone with cell phone. Integrating a cell phone to a microcontroller is a complex process and requires an auxiliary circuit, so instead of a cell phone we used a GSM module, which is special type circuit that mimics a cell phone. It can be directly integrated to a microcontroller without the help of an auxiliary circuit. But our system’s microcontroller has a limitation of low data bus (8-bit only), program memory and RAM. Hence we had to develop a program that is low on line count compare to Kevin Brown, Don DeLaMare and Brian Faires project. We also have to remove the keypad feature for this reason. Our system incorporates four sensors (i.e. temperature, humidity, and motion and gas sensor). Our systems microcontroller gathers information from the sensors and analyzes them if

22

Page 12: Message based home automation  & security system

any one of them is triggered over an alarming level, and then a SMS is send to a predefined cell phone number. And if certain parameter is crossed over danger level then supply from the mains is cut off.

Another research was published by Sunny Peter Gomasa under Massey University, Albany, New Zealand, proposing a web service based home automation, where light, smoke and motion sensor are integrated to a single board computer ALIX 3D2 and the computer is connected to a ADSL modem. It also developed a website for the control and monitoring purpose using PHP web development language. An ALIX 3D2 is single board computer by PC Engines Ltd. A single board computer has distinctive advantage over microcontroller. Single board computer usually includes a powerful microprocessor which performance is measured in several hundred MHz; whereas the performance of a microcontroller processor is measured in MIPS (million instructions per second). An ALIX 3D2 single board computer includes AMD Geode LX800 CPU with 500 MHz clock speed and 256 MB RAM. It also includes a LAN port and two USB port. The LAN port can be used with ADSL modem for internet connection. The main purpose of an ALIX 3D2 single board computer is to allow control different load via internet. The load might be connected to one or more microcontroller powered control board. The drawback of ALIX 3D2 is, beside need of internet it also require a dedicated small computer server and its own custom website.

To avoid the complexity of using single board computer we developed our own microcontroller powered controller board. And instead of internet, we have used SMS of monitoring. But since our microcontroller is very low on ability compare to a single board computer, our system operation is only limited to notification of certain parameter via SMS and termination of mains power supply when needed. We also had to remove end-user control feature.

1.6.2 MODEL CONCEPT

During the system design, ease of construction, ease of use and cost effectiveness is given top priority. We intend to develop a home automation and security system that is low on cost for construction as well as minimum operating cost as possible. Our intention is to develop a system that is user friendly and requires no user manual to operate. Thus our system is based on SMS. Because SMS is the most versatile and easy communication method in mobile communication, requires basic handsets that are able to send and receive SMS; and almost anybody can grasp the concept of SMS. To develop a home automation and security system, the system requires auxiliary sensing equipment. So we considered the most common concern of a home owner. According to our findings a home owner mostly concerned about respectively, intruder or trespasser, fire, temperature and humidity of the house. Hence we choose four sensors that are related to these factors and they are – PIR based motion sensor, gas detector, temperature and humidity sensor.

23

Page 13: Message based home automation  & security system

1.7.3 SELECTION PROCESS

At the beginning of the selection process, access to system status via SMS and internet are both thoroughly revised and SMS is selected for the ease of construction and use. At the second phase of the selection process, selection of microcontroller is considered. There are three ranges of microcontroller are available and they are, Base Line, Mid-Range and High-End microcontroller. In our project we needed ADC module (analog-to-digital converter), UART module and general input-output option. But in a Base Line controller all these module are not available. Although High-End controller provides this features but the devices are expensive. On the other hand Mid-Range controller provides all of these modules in reasonable cost. Hence we selected Mid-Range controller (PIC16F877A).In third phase of our selection process, we needed to select those sensors which parameters are used in our daily life. Hence we select four types of sensors and they are: Temperature, Humidity, Gas and Motion sensor. In the final phase of selection of hardware, we had to decide which type of sensor is to be used. There are two types of sensor, analog and digital. Digital sensor provides low percentage of error, but they are expensive and cannot be easily found. Analog sensors require a time consuming calibration and they are error prone. But they are low on cost. Hence we selected analog type sensors for our project.

1.7.4 MODEL DEVELOPMENT

After selecting appropriate hardware for the project, we developed a virtual system using Proteus 8.1 EDA (Electronic Design Automation). A Computer-aided design or CAD software helps to remove any type design error before actual hardware are assembled. It also helps a designer to keep track of how much a system draws power. After testing the virtual system we used EAGLE (Easily Applicable Graphical Layout Editor) CAD to design the custom PCB for the project.

24

Page 14: Message based home automation  & security system

25

Figure 3 Selection Process

Page 15: Message based home automation  & security system

1.7.5 TESTING

This project is implemented with all the sensors along with LCD display, connected to the microcontroller individually for testing and calibration on a BREADBOARD. The microcontroller is then interfaced with a GSM modem and tested for sending SMS on the same BREADBOARD. Whenever a sensor status was updated, the microcontroller updated the status on the LCD display and if needed sends a status SMS to a predefined number successfully.

1.7.6 VARIFICATION

At first we connected all the devices. When power was supplied, a “Beep” sound from the buzzer ensures that the system is on. We are able to observe the system status on a LCD display where temperature, relative humidity, gas and motion sensor status are shown. We change the temperature and humidity by heating up the sensor and change of status was displayed on the LCD. Again we triggered both smoke and motion sensor separately and a SMS was sent for each sensors status, in a cell phone in our hand.

1.7.7 IMPLMENTATION

After several testing and verification, the components are soldered on a custom etched PCB. GSM modem is connected with project circuit board with jumper wires.

1.8 OUTLINE OF THE THESIS

This thesis is organized in such a way that it can be effectively helpful for any other to work with any Message based home automation system. Towards this goal the project has divided in several sections-

In Chapter One, we have described the aspect of the project in practical life. Also we tried to describe a short idea about what we are trying to implement.

In Chapter Two, we have described the importance of microcontroller, its architecture, and peripherals.

In Chapter Three, we have described about sensors, working principle of sensors, its types and construction.

In Chapter Four, we have described about the basic network structure of GSM network and SMS.

In Chapter Five, we have described about the AT command, for interfacing a GSM module with microcontroller.

In Chapter Six, we tried to make an overall familiarization of all the hardware and software to incorporate to implement these projects.

In Chapter Seven, we have described the algorithm, designing procedure and implementation of the project.

26

Page 16: Message based home automation  & security system

In Chapter Eight, we have described the future aspect of the project, its application and overall conclusion.

In Appendix A, we provided the source code of the project.

27

Page 17: Message based home automation  & security system

CHAPTER 2

INTRODUCTION TO MICROCONTROLLER

2.1 INTRODUCTION

The term microcomputer is used to describe a system that includes at minimum a microprocessor, program memory, data memory, and an input-output (I/O) device. Some microcomputer systems include additional components such as timers, counters, and analog-to-digital converters. Thus, a microcomputer system can be anything from a large computer having hard disks, floppy disks, and printers to a single-chip embedded controller.

Here we are going to consider only the type of microcomputers that consist of a single silicon chip. Such microcomputer systems are also called microcontrollers, and they are used in many household goods such as microwave ovens, TV remote control units, cookers, hi-fi equipment, CD players, personal computers, and refrigerators. Many different microcontrollers are available on the market. Here we shall be looking at programming and system design for the PIC (programmable interface controller) series of microcontrollers manufactured by Microchip Technology Inc. [4]

2.2 MICROCONTROLLER SYSTEMS

A microcontroller is a single-chip computer. Micro suggests that the device is small, and controller suggests that it is used in control applications. Another term for microcontroller is embedded controller, since most of the microcontrollers are built into (or embedded in) the devices they control. A microprocessor differs from a microcontroller in a number of ways. The main distinction is that a microprocessor requires several other components for its operation, such as program memory and data memory, input-output devices, and an external clock circuit. A microcontroller, on the other hand, has all the support chips incorporated inside its single chip. All microcontrollers operate on a set of instructions (or the user program) stored in their memory. A microcontroller fetches the instructions from its program memory one by one, decodes these instructions, and then carries out the required operations.

28

Page 18: Message based home automation  & security system

Microcontrollers have traditionally been programmed using the assembly language of the target device. Although the assembly language is fast, it has several disadvantages. An assembly program consists of mnemonics, which makes learning and maintaining a program written using the assembly language difficult. Also, microcontrollers manufactured by different firms have different assembly languages, so the user must learn a new language with every new microcontroller he or she uses.

Microcontrollers can also be programmed using a high-level language, such as mikroC by MikroElektronika Inc., CCS C by Custom Computer Services, Inc., Keil Compiler by Keil Elektronik etc. High-level languages are much easier to learn than assembly languages. They also facilitate the development of large and complex programs.

In theory, a single chip is sufficient to have a running microcontroller system. In practical applications, however, additional components may be required so the microcomputer can interface with its environment. With the advent of the PIC family of microcontrollers the development time of an electronic project has been reduced to several hours.

Basically, a microcomputer executes a user program which is loaded in its program memory. Under the control of this program, data is received from external devices (inputs), manipulated, and then sent to external devices (outputs). For example, in a microcontroller-based oven temperature control system the microcomputer reads the temperature using a temperature sensor and then operates a heater or a fan to keep the temperature at the required value.

A microcontroller is a very powerful tool that allows a designer to create sophisticated input-output data manipulation under program control. Microcontrollers are classified by the number of bits they process. Microcontrollers with 8 bits are the most popular and are used in most microcontroller-based applications. Microcontrollers with 16 and 32 bits are much more powerful, but are usually more expensive and not required in most small or medium-size general purpose applications that call for microcontrollers.

The simplest microcontroller architecture consists of a microprocessor, memory, and input-output. The microprocessor consists of a central processing unit (CPU) and a control unit (CU). The CPU is the brain of the microcontroller; this is where all the arithmetic and logic operations are performed. The CU controls the internal operations of the microprocessor and sends signals to other parts of the microcontroller to carry out the required instructions.

Memory, an important part of a microcontroller system, can be classified into two types: program memory and data memory. Program memory stores the program written by the programmer and is usually nonvolatile (i.e., data is not lost after the power is turned off). Data memory stores the temporary data used in a program and is usually volatile (i.e., data is lost after the power is turned off). [4]

There are basically six types of memories, summarized as follows:

29

Figure 4 Microprocessor vs. Microcontroller

Page 19: Message based home automation  & security system

2.2.1 RAM

RAM, random access memory, is a general purpose memory that usually stores the user data in a program. RAM memory is volatile in the sense that it cannot retain data in the absence of power (i.e., data is lost after the power is turned off). Most microcontrollers have some amount of internal RAM, 256 bytes being a common amount, although some microcontrollers have more, some less. The PIC18F452 microcontroller, for example, has 1536 bytes of RAM. Memory can usually be extended by adding external memory chips. [4]

2.2.2 ROM

ROM, read only memory, usually holds program or fixed user data. ROM is nonvolatile. If power is removed from ROM and then reapplied, the original data will still be there. ROM memory is programmed during the manufacturing process, and the user cannot change its contents. ROM memory is only useful if we have developed a program and wish to create several thousand copies of it. [4]

2.2.3 PROM

PROM, programmable read only memory, is a type of ROM that can be programmed in the field, often by the end user, using a device called a PROM programmer. Once a PROM has been programmed, its contents cannot be changed. PROMs are usually used in low production applications where only a few such memories are required. [4]

2.2.4 EPROM

EPROM, erasable programmable read only memory, is similar to ROM, but EPROM can be programmed using a suitable programming device. An EPROM memory has a small clear-glass window on top of the chip where the data can be erased under strong ultraviolet light. Once the memory is programmed, the window can be covered with dark tape to prevent accidental erasure of the data. An EPROM memory must be erased before it can be reprogrammed. Many developmental versions of microcontrollers are manufactured with EPROM memories where the user program can be stored. These memories are erased and reprogrammed until the user is satisfied with the program. Some versions of EPROMs, known as OTP (one time programmable), can be programmed using a suitable programmer device but cannot be erased. OTP memories cost much less than EPROMs. OTP is useful after a project has been developed completely and many copies of the program memory must be made. [4]

2.2.5 EEPROM

EEPROM, electrically erasable programmable read only memory, is a nonvolatile memory that can be erased and reprogrammed using a suitable programming device. EEPROMs are used to save configuration information, maximum and minimum values, identification data, etc. Some

30

Page 20: Message based home automation  & security system

microcontrollers have built-in EEPROM memories. For instance, the PIC18F452 contains a 256-byte EEPROM memory where each byte can be programmed and erased directly by applications software. EEPROM memories are usually very slow. An EEPROM chip is much costlier than an EPROM chip. [4]

2.2.6 FLASH EEPROM

Flash EEPROM, a version of EEPROM memory, has become popular in microcontroller applications and is used to store the user program. Flash EEPROM is nonvolatile and usually very fast. The data can be erased and then reprogrammed using a suitable programming device. Some microcontrollers have only 1K flash EEPROM while others have 32K or more. The PIC18F452 microcontroller has 32K bytes of flash memory. [4]

2. 3 MICROCONTROLLER ARCHITECHTURE

Two types of architectures are conventional in microcontrollers. Von Neumann architecture, used by a large percentage of microcontrollers, places all memory space on the same bus; instruction and data also use the same bus.

In Harvard architecture (used by PIC microcontrollers), code and data are on separate buses, which allows them to be fetched simultaneously, resulting in an improved performance. [4]

2.3.1 RISC and CISC

RISC (reduced instruction set computer) and CISC (complex instruction computer) refer to the instruction set of a microcontroller. In an 8-bit RISC microcontroller, data is 8 bits wide but the instruction words are more than 8 bits wide (usually 12, 14, or 16 bits) and the instructions occupy one word in the program memory. Thus the instructions are fetched and executed in one cycle, which improves performance. In a CISC microcontroller, both data and instructions are 8 bits wide. CISC microcontrollers usually have over two hundred instructions. Data and code are on the same bus and cannot be fetched simultaneously. [4]

31

Figure 6 Von Neumann ArchitectureFigure 5 Harvard Architecture

Page 21: Message based home automation  & security system

2.4 MICROCONTROLLER FEATURES

Microcontrollers from different manufacturers have different architectures and different capabilities. Some may suit a particular application while others may be totally unsuitable for the same application. The hardware features common to most microcontrollers are described in this section.

2.4.1 SUPPLY VOLTAGE

Most microcontrollers operate with the standard logic voltage of 5V. Some microcontrollers can operate at as low as 2.7V, and some will tolerate 6V without any problem. The manufacturer’s data sheet will have information about the allowed limits of the power supply voltage. PIC18F452 microcontrollers can operate with a power supply of 2V to 6.5V. Usually, a voltage regulator circuit is used to obtain the required power supply voltage when the device is operated from a mains adapter or batteries. For example, a 5V regulator is required if the microcontroller is operated from a 5V supply using a 9V battery. [4]

2.4.2 THE CLOCK

All microcontrollers require a clock (or an oscillator) to operate, usually provided by external timing devices connected to the microcontroller. In most cases, these external timing devices are a crystal plus two small capacitors. In some cases they are resonators or an external resistor-capacitor pair. Some microcontrollers have built-in timing circuits and do not require external timing components. If an application is not time- sensitive, external or internal (if available) resistor-capacitor timing components are the best option for their simplicity and low cost. An instruction is executed by fetching it from the memory and then decoding it. This usually takes several clock cycles and is known as the instruction cycle. In PIC microcontrollers, an instruction cycle takes four clock periods. Thus the microcontroller operates at a clock rate that is one-quarter of the actual oscillator frequency. [4]

The performance of a CPU in a microcontroller is normally determined by the frequency of an oscillator crystal. Typically a crystal oscillator produces a fixed sine wave—the frequency reference signal. Electronic circuitry translates that into a square wave at the same frequency for digital electronics applications. The clock distribution network inside the CPU carries that clock signal to all the components that need it. With each clock pulse, the CPU executes one instruction set. The higher the clock pulse the higher the execution rate. For example – if we use a CPU with a 20 MHz clock frequency, then it will execute an instruction in 0.05 microseconds

(since , hence or 0.05µs). But if the same CPU is given an 8 MHz clock

frequency, then it will execute the same instruction in 12.5 microseconds ( or 12.5µs).

32

Page 22: Message based home automation  & security system

Usually most CPU in microcontroller’s complete one instruction with each clock pulse, but some device requires up to 4 clock pulses to complete one instruction set, such as – PIC microcontroller we used in our project requires 4 clock pulses to complete one instruction set.

But increased clock frequency will increase heat produce by the CPU in microcontroller, which in turns increases the body temperature of the microcontroller, leading to failure of the device. According to manufacturer datasheet increase of 1MHz clock frequency will increase 5°C operating body temperature of the microcontroller per hour. Maximum operating temperature of a PIC16F877A is 125°C. [10] Using the following equation a safe operating temperature for the microcontroller can be derived.

TB= TA+FOSC×5°C±2°C

Here, TB = total body temperature of the microcontroller

TA = ambient/room temperature

FOSC = oscillating frequency

Example: if the room temperature is 30ºC and 20MHz clock frequency, then according to stated equation the body temperature of the microcontroller will be,

TB= 30+20×5°C±2°C

Or, TB= 30+100±2°C

Or, TB= 130±2°C

This exceeds the maximum operating temperature of the microcontroller. Again if the room temperature is 30ºC and 8MHz clock frequency, then according to stated equation the body temperature of the microcontroller will be,

TB= 30+8×5°C±2°C

Or, TB= 30+40±2°C

Or, TB= 70±2°C

And this is within the maximum operating range of the microcontroller. Hence, we used an 8MHz clock frequency, instead of 20MHz clock frequency.

2.4.3 TIMERS

Timers are important parts of any microcontroller. A timer is basically a counter which is driven from either an external clock pulse or the microcontroller’s internal oscillator. A timer can be 8 bits or 16 bits wide. Data can be loaded into a timer under program control, and the timer can be stopped or started by program control. Most timers can be configured to generate an interrupt when they reach a certain count (usually when they overflow). The user program can use an interrupt to carry out accurate timing-related operations inside the microcontroller.

33

Page 23: Message based home automation  & security system

Microcontrollers in the PIC16F series have at least two timers. For example, the PIC16F877A microcontroller has two built-in timers. Some microcontrollers offer capture and compare facilities, where a timer value can be read when an external event occurs, or the timer value can be compared to a preset value, and an interrupt is generated when this value is reached. Most PIC16F microcontrollers have at least two capture and compare modules. [4]

2.4.4 WATCHDOG

Most microcontrollers have at least one watchdog facility. The watchdog is basically a timer that is refreshed by the user program. Whenever the program fails to refresh the watchdog, a reset occurs. The watchdog timer is used to detect a system problem, such as the program being in an endless loop. This safety feature prevents runaway software and stops the microcontroller from executing meaningless and unwanted code. Watchdog facilities are commonly used in real-time systems where the successful termination of one or more activities must be checked regularly. [4]

2.4.5 RESET INPUT

A reset input is used to reset a microcontroller externally. Resetting puts the microcontroller into a known state such that the program execution starts from address0 of the program memory. An external reset action is usually achieved by connecting a push-button switch to the reset input. When the switch is pressed, the microcontroller is reset. [4]

2.4.6 INTERRUPTS

Interrupts are an important concept in microcontrollers. An interrupt causes the microcontroller to respond to external and internal (e.g., a timer) events very quickly. When an interrupt occurs, the microcontroller leaves its normal flow of program execution and jumps to a special part of the program known as the interrupt service routine (ISR). The program code inside the ISR is executed, and upon return from the ISR the program resumes its normal flow of execution. The ISR starts from a fixed address of the program memory sometimes known as the interrupt vector address. Some microcontrollers with multi-interrupt features have just one interrupt vector address, while others have unique interrupt vector addresses, one for each interrupt source. Interrupts can be nested such that a new interrupt can suspend the execution of another interrupt. Another important feature of multi-interrupt capability is that different interrupt sources can be assigned different levels of priority. For example, the PIC18F series of microcontrollers has both low-priority and high- priority interrupts levels. [4]

2.4.7 BROWN-OUT DETECTOR

Brown-out detectors, which are common in many microcontrollers, reset the microcontroller if the supply voltage falls below a nominal value. These safety features can be employed to prevent unpredictable operation at low voltages, especially to protect the contents of EEPROM-type memories. [4]

34

Page 24: Message based home automation  & security system

2.4.8 ANALOG-TO-DIGITAL CONVERTER

An analog-to-digital converter (A/D) is used to convert an analog signal, such as voltage, to digital form so a microcontroller can read and process it. Some microcontrollers have built-in A/D converters. External A/D converter can also be connected to any type of microcontroller. A/D converters are usually 8 to 10 bits, having 256 to 1024 quantization levels. Most PIC microcontrollers with A/D features have multiplexed A/D converters which provide more than one analog input channel. For example, the PIC18F452 microcontroller has 10-bit 8-channel A/D converters. The A/D conversion process must be started by the user program and may take several hundred microseconds to complete. A/D converters usually generate interrupts when a conversion is complete so the user program can read the converted data quickly. A/D converters are especially useful in control and monitoring applications, since most sensors (e.g., temperature sensors, pressure sensors, force sensors, etc.) produce analog output voltages. [4]

2.4.9 SERIAL INPUT-OUTPUT

Serial communication (also called RS232 communication) enables a microcontroller to be connected to another microcontroller or to a PC using a serial cable. Some microcontrollers have built-in hardware called USART (universal synchronous- asynchronous receiver-transmitter) to implement a serial communication interface. The user program can usually select the baud rate and data format. If no serial input-output hardware is provided, it is easy to develop software to implement serial data communication using any I/O pin of a microcontroller. The PIC18F series of microcontrollers has built-in USART modules. Some microcontrollers (e.g., the PIC18F series) incorporate SPI (serial peripheral interface) or I2C (integrated interconnect) hardware bus interfaces. These enable a microcontroller to interface with other compatible devices easily. [4]

2.4.10 EEPROM DATA MEMORY

EEPROM-type data memory is also very common in many microcontrollers. The advantage of an EEPROM memory is that the programmer can store nonvolatile data there and change this data whenever required. For example, in a temperature monitoring application, the maximum and minimum temperature readings can be stored in an EEPROM memory. If the power supply is removed for any reason, the values of the latest readings are available in the EEPROM memory. The PIC18F452 microcontroller has 256 bytes of EEPROM memory. Other members of the PIC18F family have more EEPROM memory (e.g., the PIC18F6680 has 1024 bytes). The mikroC language provides special instructions for reading and writing to the EEPROM memory of a PIC microcontroller. [4]

2.4.11 LCD DRIVERS

LCD drivers enable a microcontroller to be connected to an external LCD display directly. These drivers are not common since most of the functions they provide can be implemented in software. For example, the PIC18F6490 microcontroller has a built-in LCD driver module. [4]

35

Page 25: Message based home automation  & security system

2.4.12 ANALOG COMPARATOR

Analog comparators are used where two analog voltages need to be compared. Although these circuits are implemented in most high-end PIC microcontrollers, they are not common in other microcontrollers. The PIC18F series of microcontrollers has built-in analog comparator modules. [4]

2.4.13 REAL-TIME CLOCK

A real-time clock enables a microcontroller to receive absolute date and time information continuously. Built-in real-time clocks are not common in most microcontrollers, since the same function can easily be implemented by either a dedicated real-time clock chip or a program written for this purpose. [4]

2.4.14 SLEEP MODE

Some microcontrollers (e.g., PICs) offer built-in sleep modes, where executing this instruction stops the internal oscillator and reduces power consumption to an extremely low level. The sleep mode’s main purpose is to conserve battery power when the microcontroller is not doing anything useful. The microcontroller is usually woken up from sleep mode by an external reset or a watchdog time-out. [4]

2.4.15 POWER-ON RESET

Some microcontrollers (e.g., PICs) have built-in power-on reset circuits which keep the microcontroller in the reset state until all the internal circuitry has been initialized. This feature is very useful, as it starts the microcontroller from a known state on power-up. An external reset can also be provided, where the microcontroller is reset when an external button is pressed. [4]

2.5 PIC16F877A MICROCONTROLLER OVERVIEW

High-Performance RISC CPU:

• Only 35 single-word instructions to learn• All single-cycle instructions except for program branches, which are two-cycle• Operating speed: DC – 20 MHz clock input

DC – 200 ns instruction cycle• Up to 8K x 14 words of Flash Program Memory, Up to 368 x 8 bytes of Data Memory (RAM),

Up to 256 x 8 bytes of EEPROM Data Memory• Pin out compatible to other 28-pin or 40/44-pin

PIC16CXXX and PIC16FXXX microcontrollers

36

Page 26: Message based home automation  & security system

Peripheral Features:

Timer0: 8-bit timer/counter with 8-bit prescaler Timer1: 16-bit timer/counter with prescaler, can be incremented during Sleep via

external crystal/clock Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler Two Capture, Compare, PWM modules

Capture is 16-bit, max. resolution is 12.5 ns Compare is 16-bit, max. resolution is 200 ns PWM max. resolution is 10-bit

Synchronous Serial Port (SSP) with SPI™ (Master mode) and I2C™ (Master/Slave)

Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection

Parallel Slave Port (PSP) – 8 bits wide with external RD, WR and CS controls (40/44-pin only)

Brown-out detection circuitry for Brown-out Reset (BOR) 10-bit, up to 8-channel Analog-to-Digital Converter (A/D)

Device

Program Memory

Data SRAM (Bytes)

EEPROM (Bytes) I/O

10-bitA/D (ch)

CCP (PWM)

MSSP

USARTTimers8/16-bit Comparators

Bytes# Single

WordInstructions

SPIMaster

I2C

PIC16F877A 14.3K 8192 368 256 33 8 2 Yes

Yes Yes 2/1 2

2.6 WHY SELECT PIC16F877A?

PIC16F877A has a operating range at DC 20MHz clock frequency. It has 386 bytes RAM and vast 8192 single word instruction or 14.3Kbytes program memory. It also provides an ADC and USART module. It also provides CCP, SPI, I2C Comparator and Timers module.

To implement our design we needed an ADC module to read sensors analog data and analyze. To send SMS using a GSM Modem, we need an UART module to communicate with module. That’s why we selected PIC16F877A microcontroller.

2.7 USED PIN IN OUR PROJECT

37

Page 27: Message based home automation  & security system

PIN01 – it is Master Reset pin, it also used for power on reset feature where microcontroller program cycle is reset and start from the beginning.

PIN 02 – 0 5 – are part of the ADC module of the microcontroller, can be used as both analog and digital input, and digital output.

PIN 13 – 14 – used for receiving an external clock frequency using a crystal oscillator. PIN 11 – 32 – used for power supply to microcontroller, usually +5v. PIN 12 – 31 – used for grounding end to complete the circuit. PIN 25 – is connected to UART module of microcontroller, performs the transition of

data. PIN 26 – is connected to UART module of microcontroller, performs the receiving of

data.

38

Page 28: Message based home automation  & security system

CHAPTER 3

SENSOR

3.1 INTRODUCTION

A sensor is a device that measures a physical quantity and converts it into a signal which can be read by an observer or by an (today mostly electronic) instrument. A sensor is a device, which responds to an input quantity by generating a functionally related output usually in the form of an electrical or optical signal. A sensor's sensitivity indicates how much the sensor's output changes when the measured quantity changes.

A good sensor obeys the following rules:

Is sensitive to the measured property only Is insensitive to any other property likely to be encountered in its application

Does not influence the measured property

Ideal sensors are designed to be linear or linear to some simple mathematical function of the measurement, typically logarithmic. The output of such a sensor is an analog signal and linearly proportional to the value or simple function of the measured property. The sensitivity is then defined as the ratio between output signal and measured property. [1]

3.2 TEMPERATURE SENSOR

A temperature is a numerical measure of hot and cold. Its measurement is by detection of heat radiation, particle velocity, kinetic energy, or most commonly, by the bulk behavior of a thermometric material. It may be calibrated in any of various temperature scales, Celsius, Fahrenheit, Kelvin, etc. [3]

 

39

Figure 7 Temperature Sensor

Page 29: Message based home automation  & security system

3.2.1 TEMPERATURE AND ITS MEASUREMENT

Simply speaking, temperature is the degree of hotness of the body which is a measure of the heat content in the body. The problem to quantify the heat content of the body on a scale did not arise until the invention of the Steam Engine. The curiosity of scientists to understand the behavior of water at different levels of heat contents gave rise to a formal and better laid out study. One of the first references for ‘temperature’ dates back to 1760, when Joseph Black declared that applying the same heat to different materials resulted in different temperatures. Years of rigorous scientific study led to many theories ranging from the simple ‘Caloric’ concept, which treated heat as a material substance which is exchanged among materials, to Carnot’s description of heat as a form of energy (which laid the foundation of the first law of thermodynamics). However, none of them satisfactorily explained the concept of temperature. It was Maxwell’s theory which offered good reasoning into it. He defined temperature of a body as is its thermal property which provides information about the energy content of the system. It is the measure of the average kinetic energy (energy by virtue of motion) of the molecules of the substance and signifies a heat potential due to which heat flows from higher temperature to lower temperature.  The word ‘temperature’ itself is said to be derived of the Latin word ‘tempera’ meaning ‘moderate or soften’. Moving along Maxwell’s line of thought, the velocity of molecules should be the basis of selecting the value of temperature, with absolute heatlessness being a state where the molecules are totally static. But, this measurement is not possible practically, and hence, other manifestations of the effect of heat are utilized to measure temperature, for example, the geometric expansion of materials. [3]

3.2.2 TYPES OF TEMPERATURE SENSORS

Temperature can be classified into following classes:

The classes of temperature sensors based on their mechanical property:

Contact Temperature Sensing: The sensor is brought into physical contact with the object to be monitored. This method can be used with solids, liquids and gases. The sensors used for measurement can vary from capillary bulb thermometers and bi-metal sensors to sensors that use varying voltage signals or resistance values. [3]

 Expansion Thermometers: These sensors use Bi-metallic strips which have different expansion rates at a particular temperature. Thus, this difference of expansion can be translated into temperature change using a mechanical pointer. Though not very accurate, these devices offer the advantage of being portable. Low cost applications like time compensators in mechanical clocks, thermostats where a higher temperature may open the contact as in heating control or may close it like in refrigerators make use of bimetallic strips to open and close mechanical switches which in turn control electrical switches like circuit breakers. [3]

 Filled System Thermometers: These devices are filled with some substitute which expands or contracts due to temperature change. They may be filled with mercury. However, as it is

40

Page 30: Message based home automation  & security system

considered to be an environmental hazard, organic liquid types may be used instead. These do not require any electric power to operate and are stable even after repeated use. However, they do not provide any kind of reading storage solution and also cannot make point measurements. These find use in medical industry to measure body temperatures. [3]

The classes of temperature sensors based on their electrical property:

Voltage signal based sensors: Thermocouples are the main sensors of this category. The underlying principle is the Seebeck effect. When two different metals or alloys are placed together so as to form two junctions, a voltage is induced across the junctions when there is a difference of temperatures between the junctions. These sensors are capable of detecting very high temperatures (as high as 1700o), have a very simplistic design which makes them quite robust to shock and vibration and can have almost immediate response to temperature changes. They however provide localized temperature readings and need a cold junction compensation to maintain the temperature gradient. Also, they are highly non-linear devices when compared to other sensors and require extremely good algorithms on the part of the conditioning electronics and processors to compensate for the non-linearity. Thermocouples find application in extremely high temperature sensing applications, chemical reaction monitoring, metal cutting, gas chromatography, sensing temperatures inside internal combustion engines etc. owing to their wide temperature range and ruggedness; however, if high accuracy and linearity are desired, other temperature sensors must be used. Simple implementation ideas can be like the one in the following: [3]

Resistance value based sensors: The resistance of metals and semiconductors offered to the flow of current through them changes with temperature. This change can be monitored and mapped to various temperature values on a scale. Further, on increasing the temperature, the value of resistance may increase or decrease. Substances with a positive temperature coefficient like most metals undergo a positive change of resistance with increasing temperature, while resistance of most semiconductors decreases with increasing temperature owing to their negative temperature coefficients. Based on the temperature coefficients, the Resistance Temperature Detectors (RTD) can be further divided into two types: [3]

41

Figure 8 Circuit Diagram of Voltage Signal based Sensor

Page 31: Message based home automation  & security system

Resistance Wire: Mainly built with materials with positive resistance coefficient materials like platinum, RTDs are resistive elements which exhibit predictable change in resistance with temperature. The change of Resistance with temperature is given by the relation:

Here, Rt and Ro are the resistance of the material at temperatures t and to ºC; and α is the Average temperature Coefficient. These devices may be in the forms of Thin Film Resistors or Wire-wounded Resistors. They offer a very wide linear range of temperature measurement (-200 to 650oC) and are very stable with minimal drift even with repeated operation year after year. The signal output is quite large as compared to thermocouples, and can use ordinary copper wires for extension. Also, these can be spread over a large area. Such sensors may be mounted on one arm of a balanced Wheatstone bridge circuit as shown in the figure below and the entire circuit be used to calculate and also control actuators for maintenance of temperature using feedback. They provide the desired linear range of operation where thermocouples fall short. RTDs find use in applications like cold junction compensation, calibration purposes, in a wheat stone bridge circuit and process control. The linearity simplifies the implementation of signal conditioning circuitry and makes RTDs suitable for high precision applications. RTDs measure absolute temperature in contrast with the thermocouples, and hence, might not be suitable for maintaining uniform temperature throughout the surface like the thermocouples are used. [3]

 

   

Thermistor: Semiconductors offer a variety of phenomenon and form the very basis of electronics. Both Positive (PTC) and Negative Temperature Coefficient (NTC) semiconductors are present and sensors based on them are differentiated as cold-wire PTC-Thermistor and hot-wire NTC-Thermistor. For PTC-Thermistor, Ferro electricity is the predominant phenomenon causing the positive coefficient in a short range of temperature. The short temperature range of operation for these materials makes them suitable for use as temperature limiting switches. They have been used successfully in CRT monitors as timers in degaussing coils. They can be used as replacements for fuses in the form of current limiting devices. If the current increases, more heat is generated which heats up the Thermistor. This increases the resistance which reduces the current and voltage available to the device thus protecting it from increased currents. For NTC-

42

Figure 9 RTD Circuit Diagram

Page 32: Message based home automation  & security system

Thermistor, the relation between resistance and temperature is negative and exponential which is very repeatable. In the range of use, this exponential curve can be seen as a fairly linear plot and can even provide more sensitivity than RTDs which makes them more attractive in terms of accuracy in measurements.Owing to their low costs, they find ample use in automotive and consumer products industries like coolant and oil temperature monitors, incubator temperature maintenance, low temperature thermometers, modern digital thermostats, battery pack temperature monitors etc. A more recent application where NTC Thermistor have been used is 3D printing, where Thermistor are used to maintain a constant temperature at the hot end of 3D printers for the proper melting of plastic filaments. [3]

Integrated Silicon Temperature Sensors: Besides all these classifications, integrated circuits have been designed to provide ease of use while measuring temperatures in the desired scale. For example, the LM35 IC from Texas Instruments is a precision temperature sensor IC that offers reading directly on the Celsius scale and LM34 is another one offering readings on the Fahrenheit scale. These ICs provide Voltage readings which are directly proportional to a certain multiplier of temperature and hence can be directly read off a multimeter, or fed directly into an ADC for further processing. They provide easy integration and interfacing with other elements of the circuit. Many semiconductor companies like Analog Devices, Microchip, Smartek, ZMD and ST Microelectronics are into temperature sensors design and even provide signal processing circuitry and digital I/O interfaces for microcontrollers. These temperature sensors find widespread use in consumer products like personal computers, office electronics equipment, cellular phones, HVACs and battery management solutions. Apart from these major principles of temperature measurement, other methods have also been developed. Some of them are, oscillating quartz temperature sensors, thermal noise thermometers, fiber optic thermometers and temperature measurement systems. [3]

43

Figure 10 LM35 IC Temperature Sensor

Page 33: Message based home automation  & security system

3.2.3 SELECTION CRITERIA OF TEMPERATURE SENSORS

None of the temperature sensing devices are versatile enough to be used everywhere. If the thermocouples are known for their wide temperature range of operation, RTDs are unrivalled in the linearity range and Thermistor is very accurate while the silicon sensors are easy to integrate in circuits. The use of a particular temperature sensor in some applications is governed by a number of parameters, the most important being temperature itself. The temperature range for the application, the rate at which the temperature may change, etc. help decide the type of design. For example, for sensors with high operating temperatures, special connection leads would be needed, while for sensors which have to deal with temperature shocks, wire-wound type of construction is preferred.  The stability and accuracy of the sensor at the prescribed operating conditions is another major factor to weigh while choosing design. Sensitivity of the device to measure small changes and how prone it is to self heating, determines the reliability of the device and its performance. The response time of the sensor is often governed by the size of the sensor. For example, the small dimensions of a film type resistor based sensor result in minimal associated heat capacity and hence, short response times (0.1 s in water and 3 to 6s in air). In the same application area, wire type resistor would respond in 0.2 to 0.5s in water and 4 to 25s in air. To aid you in choosing the right temperature sensor for your application, a comparison table of the 4 popular sensors is drawn below for easy reference:

Table 1 Comparison among Different Types of Temperature Sensor

Type Thermocouple RTD Thermistor Integrated Silicon

Temperature Range

-270 - 1800°C -250 - 900°C -100 - 450°C -55 - 150°C

Accuracy ±0.5°C ±0.01°C ±0.1°C ±1°C

Linearity (Minimum order of polynomial, lesser

the better)

4th order polynomial

2nd order polynomial

3rd order polynomial Linearization not required. Within ±1°C

Sensitivity ? 10µV/°C 0.00385 ?/?/°C (Pt)

Several ?/ ?/°C -2mV/°C

Ruggedness Larger the gauge of wire, more is the ruggedness

Quite susceptible to breakage due

to vibration

Hermetic Thermistor housed

in glass, not affected by shock or

vibration

As rugged as an IC in plastic package like a

DIP.

Responsiveness (test conditions)

Tres<1s 1s<Tres<10s 1s<Tres<5s 4s<Tres<60s

External Excitation Required

None Current Source Voltage Source Supply Voltage

44

Page 34: Message based home automation  & security system

Output Voltage Resistance Resistance Digital/Current/Voltage

 

Apart from these considerations, the choice of contact or non-contact sensors is subject to various other environmental conditions. While contact sensors may provide economical measurements and are quite accurate, the need physical contact, which may lead to contamination, wear and tear and heat sinking which alters the temperature to be measured. On the other hand, non-contact sensing offers faster response and monitoring from a remote location, but cannot measure gas temperatures and has ambient temperature restrictions which may affect the readings. [3]

3.2.4 SENSOR WE USED & HOW DOES IT WORKS

For our project we have used a NTC Thermistor type temperature sensor. A NTC Thermistor is typically a semiconductor, made from oxides of cobalt, copper, nickel, iron or titanium, pressed into a small bead, disk or wafer. Varying the combinations of metal oxides and temperature to which they are heated allows a range of temperature characteristics to be produced. NTC Thermistor initially has a high resistance, which limits the current that can flow. However, power is dissipated as heat, which raises the body heat of the Thermistor. This lowers the resistance of the Thermistor and increases the current flow, which, in turn, increases the power dissipated. This cycle continues until thermal equilibrium is reached.

3.3 HUMIDITY SENSOR

Humidity is the presence of water in air. The amount of water vapor in air can affect human comfort as well as many manufacturing processes in industries. The presence of water vapor also influences various physical, chemical, and biological processes.  Humidity measurement in industries is critical because it may affect the business cost of the product and the health and safety of the personnel. Hence, humidity sensing is very important, especially in the control systems for industrial processes and human comfort.

 

45

Figure 11 Humidity Sensor

Page 35: Message based home automation  & security system

Controlling or monitoring humidity is of paramount importance in many industrial & domestic applications. In semiconductor industry, humidity or moisture levels needs to be properly controlled & monitored during wafer processing. In medical applications, humidity control is required for respiratory equipments, sterilizers, incubators, pharmaceutical processing, and biological products. Humidity control is also necessary in chemical gas purification, dryers, ovens, film desiccation, paper and textile production, and food processing. In agriculture, measurement of humidity is important for plantation protection (dew prevention), soil moisture monitoring, etc. For domestic applications, humidity control is required for living environment in buildings, cooking control for microwave ovens, etc.  In all such applications and many others, humidity sensors are employed to provide an indication of the moisture levels in the environment. [3]

3.3.1 RELEVANT MOISTURE TERMS

To mention moisture levels, variety of terminologies are used. The study of water vapor concentration in air as a function of temperature and pressure falls under the area of psychometrics. Psychometrics deals with the thermodynamic properties of moist gases while the term “humidity” simply refers to the presence of water vapor in air or other carrier gas. Humidity measurement determines the amount of water vapor present in a gas that can be a mixture, such as air, or a pure gas, such as nitrogen or argon. [3]

Various terms used to indicate moisture levels are tabulated in the table below:

Table 2 Measuring Terms of Humidity

S.N Term Definition Unit1 Absolute Humidity

(Vapor Concentration)Ratio of mass (vapor) to volume. grams/m3

2 Mixing Ratio OR Mass Ratio

Ratio of mass(vapor) to mass(dry gas) grams/m3

3 Relative Humidity Ratio of mass (vapor) to mass (saturated vapor) OR ratio of actual vapor pressure to saturation vapor pressure.

%

4 Specific Humidity Ratio of mass (vapor) to total mass. %5 Dew Point Temperature(above 0°C) at which the water vapor in a gas condenses

to liquid water)°C

6 Frost Point Temperature(below 0°C) at which the water vapor in a gas condenses to ice

7 Volume Ratio Ratio of partial pressure(vapor) to partial pressure (dry gas) % by volume

8 PPM by Volume Ratio of volume(vapor) X 106 to volume(dry gas)PPMV

9 PPM by Weight PPMV X PPMW

 Most commonly used units for humidity measurement are Relative Humidity (RH), Dew/Frost point (D/F PT) and Parts per Million (PPM). RH is a function of temperature, and thus it is a relative measurement. Dew/Frost point is a function of the pressure of the gas but is independent of temperature and is therefore defined as absolute humidity measurement. PPM is also an

46

Page 36: Message based home automation  & security system

absolute measurement.  Dew points and frost points are often used when the dryness of the gas is important. Dew point is also used as an indicator of water vapor in high temperature processes, such as industrial drying. Mixing ratios, volume percent, and specific humidity are usually used when water vapor is either an impurity or a defined component of a process gas mixture used in manufacturing. Correlation among RH, Dew/Frost point and PPMv is shown below: [3]

 

3.3.2 HUMIDITY SENSING – CLASSIFICATION & PRINCIPLES

According to the measurement units, humidity sensors are divided into two types: Relative Humidity (RH) sensors and Absolute Humidity (moisture) sensors. Most humidity sensors are relative humidity sensors and use different sensing principles. [3]

A table showing important parameters of different types of humidity sensors is given below:

Table 3 Comparison of Different Types Of Humidity Sensor

Active Material Thermo-setPolymer

ThermoplasticPolymer

ThermoplasticPolymer

Bulk Thermoplastic

BulkAlO3

LithiumChloride

Film

Substrate Ceramic orSilicon

Ceramic orsilicon

Polyester orPolymer film

N/A N/A Ceramic

Sensed Parameter Capacitance Capacitance Capacitance Resistance Resistance ConductivityMeasured Parameter

%RH %RH %RH %RH %RH %RH

RH Change 0% to 100% 0% to 100% 0% to 100% 20% to 100% 2% to 90% 15% to <100%

RH Accuracy ±1% to ±5% ±3% to ±5% ±3% to ±5% ±3% to ±10% ±1% to ±5%

±5%

Interchangeability ±2% to±10% RH

±3% to±20% RH

±3% to±20% RH

±5% to±25% RH

poor ±3% to±10% RH

Hysteresis <1% to 3% RH

2% to 5% RH 2% to 5% RH 3% to 6% RH <2% RH very poor

Linearity ±1% RH ±1% RH ±2% RH poor poor Very poorRise time 15 s to 60 s 15 s to 90 s 15 s to 90 s 2 min to 5 min 3 min to 5

min3 min to 5

minTemperature

Range-40 °C to185 °C

-30 °C to190 °C

-25°C to100 °C

10 °C to40 °C

-10 °C to75 °C

-

47

Figure 12 Correlation of Measuring Scale of Humidity

Page 37: Message based home automation  & security system

Long TermStability

±1%RH/5 yr

±1%RH/yr ±1%RH/yr ±3%RH/yr ±3% RH/yr

>1% RH/°C

 

 3.3.3 SENSING PRINCIPLE

Humidity measurement can be done using dry and wet bulb hygrometers, dew point hygrometers, and electronic hygrometers. There has been a surge in the demand of electronic hygrometers, often called humidity sensors. Electronic type hygrometers or humidity sensors can be broadly divided into two categories: one employs capacitive sensing principle, while other uses resistive effects. [3]

 

3.3.3.1 SENSORS BASED ON CAPACITIVE EFFECT

Humidity sensors relying on this principle consists of a hygroscopic dielectric material sandwiched between a pair of electrodes forming a small capacitor. Most capacitive sensors use a plastic or polymer as the dielectric material, with a typical dielectric constant ranging from 2 to 15. In absence of moisture, the dielectric constant of the hygroscopic dielectric material and the sensor geometry determine the value of capacitance. At normal room temperature, the dielectric constant of water vapor has a value of about 80, a value much larger than the constant of the sensor dielectric material. Therefore, absorption of water vapor by the sensor results in an increase in sensor capacitance. At equilibrium conditions, the amount of moisture present in a hygroscopic material depends on both the ambient temperature and the ambient water vapor pressure.

This is true also for the hygroscopic dielectric material used on the sensor. By definition, relative humidity is a function of both the ambient temperature and water vapor pressure. Therefore there is a relationship between relative humidity, the amount of moisture present in the sensor, and sensor capacitance. This relationship governs the operation of a capacitive humidity instrument. Basic structure of capacitive type humidity sensor is shown below:

48

Figure 13 Types of Humidity Sensor

Page 38: Message based home automation  & security system

On Alumina substrate, lower electrode is formed using gold, platinum or other material. A polymer layer such as PVA is deposited on the electrode. This layers senses humidity. On top of this polymer film, gold layer is deposited which acts as top electrode. The top electrode also allows water vapor to pass through it, into the sensing layer.  The vapors enter or leave the hygroscopic sensing layer until the vapor content is in equilibrium with the ambient air or gas. Thus capacitive type sensor is basically a capacitor with humidity sensitive polymer film as the dielectric. [3]

3.3.3.2 SENSORS BASED ON RESISTIVE EFFECT

Resistive type humidity sensors pick up changes in the resistance value of the sensor element in response to the change in the humidity. Basic structure of resistive type humidity sensor from TDK is shown below:

Thick film conductor of precious metals like gold, ruthenium oxide is printed and culminated in the shape of the comb to form an electrode. Then a polymeric film is applied on the electrode; the film acts as a humidity sensing film due to the existence of movable ions. Change in impedance occurs due to the change in the number of movable ions. [3]

3.3.4 SENSOR WE USED & HOW DOES IT WORKS

To monitor humidity we have used a capacitive humidity sensor. A capacitive humidity sensor gauges the humidity of the air relatively using a capacitor-based system. The sensor is made out of a film usually made of either glass or ceramics. The insulator material which absorbs the water is made out of a polymer which takes in and releases water based on the relative humidity of the given area. This changes the level of charge in the capacitor of the on board electrical circuit. Capacitive humidity or electronic hygrometers, in general, control the temperature of a surface based on electronic feedback and measure the resulting condensation. The hygrometer

49

Figure 14 Capacitive Type Humidity Sensor

Figure 15 Resistive Type Humidity Sensor

Page 39: Message based home automation  & security system

reads the air temperature and adjusts the surface temperature of a sensor until condensation forms and can be measured. Capacitive hygrometers measure condensation by running an alternating current between two plates to test capacitance, which is the ability of something to hold an electrical charge. As the presence of water increases, the ability to hold a charge also increases.

3.4 GAS DETECTOR

A gas detector is a device which detects the presence of various gases within an area, often as part of a safety system. This type of equipment is used to detect a gas leak and interface with a control system so a process can be automatically shut down.

Gas detectors can be classified according to the operation mechanism (semiconductors, electrochemical, ultrasonic etc.). [3]

3.4.1 ELECTROCHEMICAL GAS DETECTOR

Electrochemical gas detectors work by allowing gases to diffuse through a porous membrane to an electrode where it is either chemically oxidized or reduced. The amount of current produced is determined by how much of the gas is oxidized at the electrode, indicating the concentration of the gas. Manufactures can customize electrochemical gas detectors by changing the porous barrier to allow for the detection of a certain gas concentration range. Also, since the diffusion barrier is a physical/mechanical barrier, the detector tended to be more stable and reliable over the sensor's duration and thus required less maintenance than other early detector technologies.

However, the sensors themselves are subject to corrosive elements or chemical contamination, and may last only 1–2 years before a replacement is required. Electrochemical gas detectors are used in a wide variety of environments such as refineries, gas turbines, chemical plants, underground gas storage facilities, and more. [1]

3.4.2 SEMICONDUCTOR GAS DETECTOR

Semiconductor sensors detect gases by a chemical reaction that takes place when the gas comes in direct contact with the sensor. Tin dioxide (TiO2) is the most common material used in semiconductor sensors, and the electrical resistance in the sensor is decreased when it comes in

50

Figure 16 Capacitive Humidity Sensor

Page 40: Message based home automation  & security system

contact with the monitored gas. The resistance of the Tin dioxide (TiO2) is typically around 50 kΩ in air but can drop to around 3.5 kΩ in the presence of 1% methane. This change in resistance is used to calculate the gas concentration. Semiconductor sensors are commonly used to detect hydrogen, oxygen, alcohol vapor, and harmful gases such as Carbon Monoxide. One of the most common uses for semiconductor sensors is in carbon monoxide sensors. They are also used in Breathalyzers. Because the sensor must come in contact with the gas in order to detect it, semiconductor sensors work over a smaller distance than infrared point or ultrasonic detectors. [1]

3.4.3 ULTRASONIC GAS DETECTOR

Ultrasonic gas detectors use acoustic sensors to detect changes in the background noise of its environment. Since most high-pressure gas leaks generate sound in the ultrasonic range of 25 KHz to 10 MHz, the sensors are able to easily distinguish these frequencies from background acoustic noise which occurs in the audible range of 20 Hz to 20 KHz. The ultrasonic gas leak detector then produces an alarm when there is an ultrasonic deviation from the normal condition of background noise. Despite the fact that ultrasonic gas leak detectors cannot measure gas concentration, the device is still able to determine the leak rate of an escaping gas because the ultrasonic sound level depends on the gas pressure and size of the leak. Ultrasonic gas detectors are mainly used for remote sensing in outdoor environments where weather conditions can easily dissipate escaping gas before allowing it to reach gas leak detectors that require contact with the gas in order to detect it and sound an alarm. These detectors are commonly found on offshore and onshore oil/gas platforms, gas compressor and metering stations, gas turbine power plants, and other facilities that house a lot of outdoor pipeline.

Gas detectors can be used to detect combustible, flammable and toxic gases, and oxygen depletion. This type of device is used widely in industry and can be found in a variety of locations such as on oil rigs, to monitor manufacture processes and emerging technologies such as photovoltaic. [1]

3.4.4 SENSOR WE USED & HOW DOES IT WORKS

For this project we have used a semiconductor gas detector. When a gas interacts with this sensor, it is first ionized into its constituents and is then adsorbed by the sensing element. This absorption creates a potential difference on the element.

51

Figure 17 MQ - 9 Gas Detector

Page 41: Message based home automation  & security system

The gas detecting module consists of a steel exoskeleton under which a sensing element is housed. This detecting element is subjected to current through connecting leads. This current is known as heating current through it; the gases coming close to the sensing element get ionized and are absorbed by the sensing element. This changes the resistance of the sensing element which alters the value of the current going out of it.

Figure 17 shows externals of a standard gas sensor module: A Steel Mesh, Copper Clamping Ring and Connecting Leads. The top part is a stainless steel mesh which takes care of the following: Filtering out the suspended particles so that only gaseous elements are able to pass to insides

of the sensor.   Protecting the insides of the sensor. Exhibits an anti explosion network that keeps the sensor module intact at high temperatures

and gas pressures.

In order to manage above listed functions efficiently, the steel mesh is made into two layers. The mesh is bound to rest of the body via a copper plated clamping ring.

The connecting leads of the sensor are thick so that sensor can be connected firmly to the circuit and sufficient amount of heat gets conducted to the inside part. They are casted from copper and have tin plating over them. Four of the six leads are for signal fetching while two are used to provide sufficient heat to the sensing element. The pins are placed on a Bakelite base which is a good insulator and provides firm gripping to the connecting leads of the sensor.

52

Figure 18 External structure of MQ-9 Gas Detector

Figure 19 Steel Mesh of MQ-9 Gas Detector

Page 42: Message based home automation  & security system

The top of the gas sensor is removed off to see the internals parts of the sensor: Sensing Element and Connection Wiring. The hexapod structure is constituted by the sensing element and six connecting legs that extend beyond the Bakelite base.

Figure 20 shows the hollow sensing element which is made up from Aluminum Oxide based ceramic and has a coating of Tin Oxide. Using a ceramic substrate increases the heating efficiency and Tin Oxide, being sensitive towards adsorbing desired gas’ components (in this case methane and its products) suffices as sensing coating. The leads responsible for heating the sensing element are connected through Nickel-Chromium, well known conductive alloy. Leads responsible for output signals are connected using Platinum wires which convey small changes in the current that passes through the sensing element.  The Platinum wires are connected to the body of the sensing element while Nickel-Chromium wires pass through its hollow structure.

53

Figure 20 Internal Parts of the Sensor

Figure 21 MQ-9 Internal Element

Page 43: Message based home automation  & security system

Figure 21 shows the ceramic with Tin Dioxide on the top coating that has good adsorbing property. Any gas to be monitored has specific temperature at which it ionizes. The task of the sensor is to work at the desired temperature so that gas molecules get ionized. Through Nickel-chromium wire, the ceramic region of the sensing element is subjected to heating current. The heat is radiated by the element in the nearby region where gases interact with it and get ionized. Once, ionized, they are absorbed by the tin dioxide. Adsorbed molecules change the resistance of the tin dioxide layer. This changes the current flowing through the sensing element and is conveyed through the output leads to the unit that controls the working of the gas sensor.

3.5 PIR SENSOR

Infrared sensors can be classified as Active Infrared Sensors and Passive Infrared Sensors. Both of them use the same infrared rays and same underlying physics. However, the only difference between the two is that, active infrared sensors employ infrared source (an active element) in addition to infrared detector.

Active infrared sensors operate by transmitting energy from either a light emitting diode (LED) or a laser diode. An LED is used for a non-imaging active IR detector, and a laser diode is used for an imaging active IR detector.  In both types of these, the LED or laser diode illuminates the target, and the reflected energy is focused onto a detector consisting of a pixel or an array of pixels. Photoelectric cells, Photodiode or phototransistors are generally used as detectors.Contrary to Active Infrared sensors, Passive Infrared sensors do not contain any source of infrared radiation, they simply detect IR radiations. They totally rely on the three governing laws explained earlier. 

A passive infrared system detects energy emitted by objects in the field of view and may use signal-processing algorithms to extract the desired information. It does not emit any energy of its own for the purposes of detection.

54

Figure 22 Main Sensing Element

Page 44: Message based home automation  & security system

 Humans at normal body temperature radiate quite strongly in the infrared region at a wavelength around 10 µm. Passive infrared sensors convert the infrared signal to current or voltage. Accordingly, they are used to detect presence, occupancy, and count. Primarily used for intrusion detection, passive infrared sensor as used as a special purpose radiometer which detects the heat emitted by the body of an intruder. It offers high probability of detection within a defined area even without responding to anything else. Its presence is hard to detect which is not the case with active infrared sensors, ultrasonic detectors and the like.  Passive Infra-Red Sensors were originally being used for military and scientific applications.  Nowadays they can be seen in a wide range of commercial products for automatic light control, safety, cost-savings, etc. Almost any region where people occasionally walk or move through and need not be continuously lit, could be benefitted from the installation of a PIR sensor. Some examples are hallways, foyers, paths, driveways, garden areas and car parking’s. [3]

3.5.1 PASSIVE INFRARED DETECTORS: CLASSIFICATION 

Passive Infrared detectors primarily are of two types: Thermal & Quantum. In the PIR sensors used for human/pets detection for automatic lighting systems, intrusion detection, etc. thermal type- Pyroelectric based PIR sensors are used. Types of PIR detectors are explained below: [3]

 

3.5.2.1 THERMAL PIRs 

Thermal type has no wavelength dependence. They use the infrared energy as heat and their photosensitivity is independent of wavelength. Thermal detectors don’t require cooling but have disadvantages that response time is slow & detection time is low. Types of Thermal type PIR detectors are:

THERMOCOUPLE-THERMOPILEThermocouple uses Seebeck effect, one of the thermoelectric effects and is a detector that converts temperature into an electrical signal. The junction of dissimilar metals generates a voltage potential, which is directly proportional to the temperature. This junction can be made into multiple junctions to improve sensitivity. Such a configuration is called a thermopile. Thus, a thermopile is nothing but a junction of thermocouples connected in series. 

55

Figure 23 Working Principle of Thermocouple-Thermopile PIR Sensor

Page 45: Message based home automation  & security system

The active or ‘Hot’ junctions are blackened to efficiently absorb radiation. The reference or ‘Cold’ junctions are maintained at the ambient temperature of the detector. The absorption of radiation by the blackened area causes a rise in temperature in the ‘hot’ junctions as compared to the ‘cold’ junctions of the thermopile. This difference in temperature between the active junction and a reference junction kept at a fixed temperature produces an electric potential which is directly proportional to the differential temperature created. 

These detectors has a relatively slow response time, but offers the advantages of DC stability, requiring no bias, and responding to all wavelengths. [3]

BOLOMETERA bolometer is a simple thermal or total power detector. A bolometer changes resistance when incident infrared radiation interacts with the detector. Therefore, sensing material used for bolometer should have very high temperature coefficient of resistance; superconductor is an ideal candidate for sensing temperature in a bolometer. Typically, thermally sensitive semiconductor is made of a sintered metal oxide material. It has a high temperature coefficient of resistance.  It consists of two main elements: a sensitive thermometer and a high cross section absorber. The absorber is connected by a weak thermal link to a heat sink (at temperature T0). Incoming energy falls upon the absorber. Incoming energy is converted to heat in the absorber. Temperature of the absorber changes depending upon the changes in the power of incoming energy. Bolometer works by measuring this change in temperature. [3]

 

 

PYROELECTRIC DETECTOR Pyroelectric detectors use PZT having pyroelectic effect, a high resistor and a low noise FET, hermetically sealed in a package. Pyroelectric materials are crystals, such as lithium tantalate,

56

Figure 24 Thermocouple-Thermopile PIR Sensor

Figure 25 Working Principle of Bolometer

Page 46: Message based home automation  & security system

which exhibit spontaneous polarization, or a concentrated electric charge that is temperature dependent.PZT is spontaneously polarized in dark state. As infrared radiation strikes the detector surface, the change in temperature causes a current to flow. This results in change of polarization state which is reflected in terms of voltage change at the output.

 This detector exhibits good sensitivity and good response to a wide range of wavelengths, and does not require cooling of the detector. While thermopiles are proportional to incident radiations, pyroelectric detectors are proportional to rate of change of incident radiation. Thus, pyroelectric detectors are AC coupled devices. Also, pyroelectric detectors have very high impedance and hence require a buffer. [3]

3.5.2.2 QUANTUM TYPE PIRs 

Quantum type offer higher detection performance and a faster response speed although their photosensitivity is wavelength dependant. Quantum type detectors require cooling for accurate measurements (except for those in near IR region). [3]

 

PHOTOCONDUCTIVEPhotoconductive type of IR detectors makes use of photoconductive effect. This effect causes change in resistance when IR radiation falls upon detecting elements. [3]

Examples are PbS, PbSe, MCT (HgCdTe)Band gap of PbS, PbSe have negative temperature coefficient and hence their spectral response characteristics shift to long wavelength region when cooled. However, band gap of HgCdTe depends upon the composition and therefore, spectral response characteristics can be tailored to suit the requirements.

 PHOTOVOLTAICPhotoconductive type of IR detectors makes use of photovoltaic effect. Incident IR light cause increase in voltage output of these detectors. [3]

Examples are InGaAs PIN photodiodes, InAs, InSb 

EXTRINSIC TYPEVarious types of detectors like Ge: Au, Ge:Hg, Ge:Cu, Ge:Zn, Si:Ga, Si:As and are used depending upon the required application- spectral response, D*(Photosensitivity per unit area of the detector), etc. [3]

57

Figure 26 Pyroelectric Detector

Page 47: Message based home automation  & security system

3.5.2 SENSOR WE USED & HOW DOES IT WORKS

For this project we have used a pyroelectric type passive infrared (PIR) based motion sensor. A PIR sensor is made of ceramic material that generates surface charge when exposed to infrared radiations. As the amount of radiation increases, the surface charge generated increases. A FET is used to buffer this signal. As the sensor is sensitive to a wide range of radiations, a filter is used which limits the infrared rays falling on the sensor to 8µm-14µm range. Thus the output of an IR sensor is a function of infrared radiation. But since the output is affected by vibration, radio interference, sunlight, etc. as well, dual sensing elements are used. Both sensors are connected out of phase such that any excitation common to both gets cancelled out.The field of view of these sensors is the area or zone which it sees or where changes in the infra-red radiation can be sensed or detected. Typically, to enhance the range and field of view, the field of view is divided into number of zones (both vertically as well as horizontally) with the help of Fresnel Lens; a Fresnel lens is a Plano convex lens that is collapsed on itself to form a flat lens which retains its optical properties, but is thinner and has lesser absorption losses.  

 Fresnel lens focuses the infra-red radiation emitted by an infrared source onto the PIR detector. After the light falls upon the PIR sensor, an electrical signal corresponding to the varying amount of infra red radiations is generated. 

58

Figure 27 PIR Sensor Circuit

Figure 28 Fresnel Lance

Page 48: Message based home automation  & security system

All PIR sensors detect changes in infra-red radiation; infrared radiations in the form of heat emitted by the bodies including human beings, vehicles, etc. Bigger is the body more is the infra-red radiation and it becomes easier for the PIR sensor to detect them. In most of the applications, passive infrared sensors look for the change in the environment. The sensors are sensitive to changes in infrared energy rather than absolute levels. The sensor first sets up equilibrium with the background conditions. If the state equilibrium is disturbed due to some intrusion or by some other mechanism, it perceives it as a change. This change is fundamental to the operation of PIR sensors. 

 

By dividing the region into a number of zones, numbers of separated zones are created. A person while walking through the area will appear in one zone, then disappear and then reappear in the next zone and so on. By doing so, he modulates the reference equilibrium conditions; the process is referred to as chopping. The signal produced is proportional to the temperature difference between the intruder and the background.                                   When a person enters into a particular zone, infra-red level in that zone increases. The increase in the infra-red energy level is detected. The dual elements are excited one after another; resultant output is a positive signal followed by negative signal.  In this way, movement of a person is the field of view of the sensor can be detected. However, if the person moves within a zone, it is not possible to detect the changes. [3]

59

Figure 29 Operation of a PIR Sensor

Page 49: Message based home automation  & security system

CHAPTER 4

GSM NETWORK & SMS

4.1 INTRODUCTION

GSM (Global System for Mobile Communications, originally Groupe Spécial Mobile), is a standard developed by the European Telecommunications Standards Institute (ETSI) to describe protocols for second generation (2G) digital cellular networks used by mobile phones. It is the defacto global standard for mobile communications with over 90% market share, and is available in over 219 countries and territories.

The GSM standard was developed as a replacement for first generation (1G) analog cellular networks, and originally described a digital, circuit-switched network optimized for full duplex voice telephony. This was expanded over time to include data communications, first by circuit-switched transport, then packet data transport via GPRS (General Packet Radio Services) and EDGE (Enhanced Data rates for GSM Evolution or EGPRS). [1]

4.2 GSM NETWORK

The heart of the GSM network includes the following systems to operate wireless services:

Base station subsystem, GSM carrier frequencies, Subscriber identity module.

4.2.1 BASE STATION SUBSYSTEM

GSM is a cellular network, which means that cell phones connect to it by searching for cells in the immediate vicinity. There are five different cell sizes in a GSM network—macro, micro, pico, femto, and umbrella cells. The coverage area of each cell varies according to the implementation environment. Macro cells can be regarded as cells where the base station antenna is installed on a mast or a building above average rooftop level. Micro cells are cells whose antenna height is under average rooftop level; they are typically used in urban areas. Picocells are small cells whose coverage diameter is a few dozen meters; they are mainly used indoors. Femtocells are cells designed for use in residential or small business environments and connect to the service provider’s network via a broadband internet connection. Umbrella cells are used to cover shadowed regions of smaller cells and fill in gaps in coverage between those cells.

Cell horizontal radius varies depending on antenna height, antenna gain, and propagation conditions from a couple of hundred meters to several tens of kilometers. The longest distance

60

Page 50: Message based home automation  & security system

the GSM specification supports in practical use is 35 kilometers (22 mi). There are also several implementations of the concept of an extended cell, where the cell radius could be double or even more, depending on the antenna system, the type of terrain, and the timing advance.

Indoor coverage is also supported by GSM and may be achieved by using an indoor Picocells base station, or an indoor repeater with distributed indoor antennas fed through power splitters, to deliver the radio signals from an antenna outdoors to the separate indoor distributed antenna system. These are typically deployed when significant call capacity is needed indoors, like in shopping centers or airports. However, this is not a prerequisite, since indoor coverage is also provided by in-building penetration of the radio signals from any nearby cell. [1]

4.2.2 GSM CARRIER FREQUENCIES

GSM networks operate in a number of different carrier frequency ranges (separated into GSM frequency ranges for 2G and UMTS frequency bands for 3G), with most 2G GSM networks operating in the 900 MHz or 1800 MHz bands. Where these bands were already allocated, the 850 MHz and 1900 MHz bands were used instead (for example in Canada and the United States). In rare cases the 400 and 450 MHz frequency bands are assigned in some countries because they were previously used for first-generation systems.

Most 3G networks in Europe operate in the 2100 MHz frequency band. Regardless of the frequency selected by an operator, it is divided into timeslots for individual phones. This allows eight full-rate or sixteen half-rate speech channels per radio frequency. These eight radio timeslots (or burst periods) are grouped into a TDMA frame. Half-rate channels use alternate frames in the same timeslot. The channel data rate for all 8 channels is 270.833 Kbit/s, and the frame duration is 4.615 ms.

The transmission power in the handset is limited to a maximum of 2 watts in GSM 850/900 and 1 watt in GSM 1800/1900. [1]

4.2.3 SUBSCRIBER IDENTITY MODULE (SIM)

One of the key features of GSM is the Subscriber Identity Module, commonly known as a SIM card. The SIM is a detachable smart card containing the user's subscription information and phone book. This allows the user to retain his or her information after switching handsets. Alternatively, the user can also change operators while retaining the handset simply by changing the SIM. Some operators will block this by allowing the phone to use only a single SIM, or only a SIM issued by them; this practice is known as SIM locking. [1]

4.3 SMS (SHORT MESSAGE SERVICE)

Short message service is a mechanism of delivery of short messages over the mobile networks. It is a store and forward way of transmitting messages to and from mobiles. The message (text

61

Page 51: Message based home automation  & security system

only) from the sending mobile is stored in a central short message center (SMC) which then forwards it to the destination mobile. This means that in the case that the recipient is not available; the short message is stored and can be sent later. Each short message can be no longer than 160 characters. These characters can be text (alphanumeric) or binary Non-Text Short messages. An interesting feature of SMS is return receipts. This means that the sender, if wishes, can get a small message notifying if the short message was delivered to the intended recipient. Since SMS used signaling channel as opposed to dedicated channels, these messages can be sent/received simultaneously with the voice/data/fax service over a GSM network. SMS supports national and international roaming. This means that we can send short messages to any other GSM mobile user around the world. With the PCS networks based on all the three technologies, GSM, CDMA and TDMA supporting SMS, SMS is more or less a universal mobile data service. [4]

4.3.1 HOW DOES SMS WORK?

The figure below shows a typical organization of network elements in a GSM network supporting SMS.

Figure 30 GSM network supporting SMS

The SMC (Short Message Center) is the entity which does the job of store and forward of messages to and from the mobile station. The SME (Short Message Entity) which can be located in the fixed network or a mobile station receives and sends short messages.

The SMS GW MSC (SMS gateway MSC) is a gateway MSC (Mobile Switching Center) that can also receive short messages. The gateway MSC is a mobile network’s point of contact with other networks. On receiving the short message from the short message center, GMSC uses the SS7 network to interrogate the current position of the mobile station form the HLR, the home location register.

62

Page 52: Message based home automation  & security system

HLR (Home Location Register) is the main database in a mobile network. It holds information of the subscription profile of the mobile and also about the routing information for the subscriber, i.e. the area (covered by a MSC) where the mobile is currently situated. The GMSC is thus able to pass on the message to the correct MSC.

MSC (Mobile Switching Center) is the entity in a GSM network which does the job of switching connections between mobile stations or between mobile stations and the fixed network.

A VLR (Visitor Location Register) corresponds to each MSC and contains temporary information about the mobile, information like mobile identification and the cell (or a group of cells) where the mobile is currently situated. Using information from the VLR, the MSC is able to switch the information (short message) to the corresponding BSS (Base Station System, BSC + BTSs), which transmits the short message to the mobile. The BSS consists of transceivers, which send and receive information over the air interface, to and from the mobile station. This information is passed over the signaling channels so the mobile can receive messages even if a voice or data call is going on. [4]

4.4 HOW WE IMPLEMENTED GSM NETWORK IN OUR PROJECT

GSM (Global System for Mobile Communication) is the most popular mobile communication system around the world dominating over 90% of the total mobile communication market. GSM service provider offers various types of services, which includes three main services and they are voice call, short message service (SMS) and internet. GSM services can be gained by using a mobile phone and GSM modem.

For our project we have used SMS as our remote monitoring feature for a user. In below we have described the steps how we implemented the GSM network, in our project:

In our project, the microcontroller collects and analyzes the information from the sensors. Then the microcontroller converts that information into a string of data to form a SMS. Next the microcontroller sends a destination number to the GSM modem, to set

destination for the SMS. Then the microcontroller transmits the SMS to the GSM modem. By using the GSM network’s SMS gateway, GSM modem sends the SMS to the

destination.

63

Figure 31 Block diagram of implementation of GSM network in the project.

Page 53: Message based home automation  & security system

CHAPTER 5

AT COMMAND

5.1 GSM MODEMS

A GSM modem is a wireless MODEM that works with a GSM wireless network. A wireless modem behaves like a dial-up modem. The main difference between them is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. There are several types of modems out there. Some shown below: [5]

                                               

 

                                                                       

5.2 What is AT Command?         

AT commands are instructions used to control a modem. AT is the abbreviation of “ATtention”. Every command line starts with "AT" or "at" and the command is terminated by a Carriage Return ("Enter" key in keyboard). That's why modem commands are called AT commands. [5]

 The general syntax of AT commands is straightforward. The syntax rules are provided below. 

Syntax rule 1All command lines must start with "AT" and end with a Carriage Return character. In a terminal program like HyperTerminal of Microsoft Windows, we can press the Enter key on the keyboard to output a carriage return character. The ASCII value of CR is 0x0D (Decimal13) and string value is "\r". [5]

Syntax rule 2 A string is enclosed between double quotes. [5]

64

Figure 34 WAVECOM GSM MODEM

Figure 33 SIM900 GSM Module

Figure 32 Telit G862 GSM Module

Page 54: Message based home automation  & security system

Example: To read all SMS messages from message storage in SMS text mode (at this time we do not need to know what SMS text mode is. More information will be provided later in this SMS tutorial), we need to assign the string "ALL" to the AT command, like this:

AT+CMGL="ALL" 

 Syntax rule 3 Information responses and result codes always start and end with a Carriage Return character and a Line Feed character (ASCII = 0x0A; Decimal = 10; string = '\n'). [5]

Example: After sending the command line "AT+CGMI " to the mobile device, the mobile device should return a response similar to this:

LF CR  Nokia LF CRLF CR    OK    LF CR

The first line is the information response of the AT command and the second line is the final result code. The final result code "OK" marks the end of the response. It indicates no more data will be sent from the mobile device to the PC.

When a terminal program such as HyperTerminal of Microsoft Windows sees a carriage return character, it moves the cursor to the beginning of the current line. When it sees a linefeed character, it moves the cursor to the same position on the next line.

Case Sensitivity of AT CommandsIn the SMS specification, all AT commands are in uppercase letters. However, many GSM/GPRS modems and mobile phones allow us to type AT commands in either uppercase or lowercase letters. For example, on Nokia 6021, AT commands are case-insensitive and the following two command lines are equivalent:

AT+CMGL        at+cmgl     

 The ETSI GSM 07.07 (3GPP TS 27.007) specifies AT commands. The AT command list can be found in their website. However, as this project’s application limited to SMS, only the SMS related AT commands were explained below. [5]

1) ATE0 – Turn off echo This command is used to determine whether or not the modem echoes characters received by microcontroller. For example if we send the following command: "AT", then modem will simply reply: "OK". But if echo is turn on then it will reply: [5]

LF CR   AT  LF CRLF CR    OK    LF CRIt will reply first what he receive and then the response. By default Echo is ON. It should be off for less traffic. 

65

Page 55: Message based home automation  & security system

       

2) AT+CNMI – New message indication This command selects how modem will behave when a new SMS will come.  See AT command sheet for more explanation of the parameters. [5]

        

We will use above configuration (AT+CNMI=2,1,0,0). When new message received, module send following string:

CMTI: "SM",1This mean, a new message received which is stored in SIM memory (SM) and this message's index number is 1. 

3) AT+CPMS – Preferred Message Storage This command allows the message storage area to be selected (for reading, writing, etc).If we want to know what memory storage were modem supports, then write: [5]

AT+CPMS = ?  (*by giving "=?" after any AT command we can find what parameter were modem supports)If we need to know what modem’s default storage was, write:

AT+CPMS?(*by giving "?" after any AT command we can find default parameter) As I am going to use SIM memory, so AT command will be:

AT+CPMS = "SM"Also we can use:“SM”: SMS message storage in SIM (default)“BM”: CBM message storage (in volatile memory).“SR”: Status Report message storage

4) AT+CMGF - Text Mode This command is to select in which mode we handle msg. There are two types: PDU mode and Text mode. PDU mode is a little complex, I bet we don’t want to know about it. So I prefer Text mode, which is "AT+CMGF=1".  [5]

66

Page 56: Message based home automation  & security system

5) AT+CMGR – Read Message This command allows the application to read stored messages. [5]

      

 

 

 

6) AT+CMGD – Delete Message This command is used to delete one or several messages from preferred message storage. [5]

  

7) AT+CMGS – Send Message This command is for sending SMS. Write:AT+CMGS="phone number"Example: AT+CMGS=”+8801911193901” [5]

After that a prompt (‘>’) will return from modem. Then simply type was message and at the end

enters a "Ctrl-Z" character (ASCII 26). Was message will be send with OK confirmation.

67

Page 57: Message based home automation  & security system

 8) AT+IPR – Baud Rate In Wavecom the default baud rate is 152000bps, whereas in Telit it is 9600bps. Not all microcontrollers support that much speed. So before use any module read datasheet carefully. To check were module's baud rate write:

AT+IPR?To set were preferable baud rate, write:

AT+IPR = 9600

But if we now restart were module, the default baud rate it had earlier, will set again. So if we want to change were module's baud rate permanently, after change the baud rate, we have to save it in the module. The AT command for it is: 

AT&WThis command save all the configuration it has, at the time of this code executed. (Note: At the end of all AT command we should send Carriage Return (CR) and some module also need Line Feed (LF) character with CR.) That is the end of AT commands explanation. [5]

5.3 “AT” COMMANDS ARE USED IN OUR PROJECT

1) AT

According to syntax rule 1 every “AT” command should begin with “AT” including the double quotes. The AT command is used for testing the GSM modem weather it is working or not. This command is also used for the calling attention of the modem before every other command.

2) AT+CMGF=1

“AT+CMGF=1” command is used for configuring the modem into text SMS mode.

3) AT+CMGS=

“AT+CMGS=” command is used to set the destination number for the SMS.

68

Page 58: Message based home automation  & security system

CHAPTER 6

HARADWARE & SOFTWARE DESCRIPTION

6.1 HARDWARE REQUIREMENT

PIC Microcontroller – 16F877A, Temperature Sensor – HSM-20G, Humidity Sensor – HSM-20G, Gas Detector – MQ9, PIR Motion Detector Module, SIMCOM 900 GSM Module, LCD Display, Crystal oscillator, Piezo Buzzer, Relay.

6.2 DESCRIPTION of HARDWARE

6.2.1 PIC MICROCONTROLLER (PIC16F877A)

Microcontroller is the most important instrument for this project. Multiple sensors are used in this project, hence reading their analog data and convert them into digital data to analyze requires a powerful microcontroller. The microcontroller also sends that information via SMS in real time and display on a LCD.

6.2.2 SIM900 GSM MODULE

GSM/GPRS module is used to establish communication between a computer and a GSM-GPRS system. Global System for Mobile communication (GSM) is an architecture used for mobile communication in most of the countries. Global Packet Radio Service (GPRS) is an extension of GSM that enables higher data transmission rate. GSM/GPRS module consists of a GSM/GPRS modem assembled together with power supply circuit and communication interfaces (like RS-232, USB, etc) for computer. GSM/GPRS MODEM is a class of wireless MODEM devices that are designed for communication of a computer with the GSM and GPRS network. It requires a SIM (Subscriber Identity Module) card just like mobile phones to activate communication with the network. Also they have IMEI (International Mobile Equipment Identity) number similar to mobile phones for their identification. A GSM/GPRS MODEM can perform the following operations: 

69

Page 59: Message based home automation  & security system

1.      Receive, send or delete SMS messages in a SIM.2.      Read, add, search phonebook entries of the SIM.3.      Make, Receive, or reject a voice call. The MODEM needs AT commands, for interacting with processor or controller, which are communicated through serial communication. These commands are sent by the controller/processor. The MODEM sends back a result after it receives a command. Different AT commands supported by the MODEM can be sent by the processor/controller/computer to interact with the GSM and GPRS cellular network.

6.2.3 HSM – 20G TEMPERATURE & HUMIDITY SENSOR

The module of HSM-20G is a combination of both temperature and humidity sensor. This module implements resistive (Thermistor – NTC type) temperature sensing principle and capacitive humidity sensing principle.

6.2.4 MQ – 9 GAS DETECTOR

MQ – 9 is a semiconductor type gas detector. This model is particularly sensitive to methane (CH4), LPG (liquidize pressurized gas) and Carbon Monoxide (CO). Its sensing element is made of Al2O3 ceramic tube and SnO2 wire.

6.2.5 PIR MOTION SENSING MODULE

It is a pyroelectric sensor module which developed for human body detection. An integrated PIR sensor combined with a Fresnel lens which is mounted on a compact PCB, and limited components to form the module. Delay time, Lux is adjustable. Customization is accepted.

6.2.6 LCD DISPLAY

The LCD display used in this project is an alphanumeric 16×2 display. It contains total of 16 pins, 8 data pins, 1registor select pin, 1 read-write pin, 1 enable signal pin, 1display brightness control pin, 2 power supply pin, 2 backlight pin.

6.2.7 PIEZO BUZZER

Piezo buzzer is an electronic device commonly used to produce sound. Light weight, simple construction and low price make it usable in various applications like car/truck reversing indicator, computers, call bells etc.

6.2.8 CRYSTAL OSCILLATOR

A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency. This frequency is commonly used to keep track of time, to provide a stable clock

70

Page 60: Message based home automation  & security system

signal for digital integrated circuits; in this provides it provides an 8MHz clock frequency for microcontroller.

6.2.9 RELAY

A relay is an electrically operated switch the employs electromagnet to mechanically operate a switch. Here a relay is to mains supply as protective measurement of the load and the entire circuit.

6.3 SOFTWARE REQUIRMENT

Proteus 8.1, mikroC, PicKit 2.

6.3.1 PROTEUS 8.1

Proteus 8.1 is software for microprocessor based embedded system design and simulation, schematic capture and PCB layout design. It is developed by Labcenter Electronics Ltd. England.

6.3.2 MikroC PRO for PIC

MikroC PRO for PIC is the most popular C compiler for PIC microcontroller. It is high level programming language. It provides a vast built in library function for electronic hobbyist and professional embedded system developer. It is developed by Mikroelektronika under third party license from Microchip Technologies.

6.3.3 PicKit 2

PicKit2 is programmer (firmware burner) software for PIC microcontroller.

71

Page 61: Message based home automation  & security system

CHAPTER 7

CIRCUIT DIAGRAM & ALGORITHM

7.1 CIRCUIT DIAGRAM

7.2 ALGORITHM

PART 01: FOR SENSORS

Step 01: Start

Step 02: Declare Variables; Preprocessor and User Function (if any).

Step 03: Create an array with appropriate label for sending SMS.

72

Figure 35 Message Based Home Automation and Security System Circuit Diagram

Figure 36 Power Supply Circuit Diagram

Page 62: Message based home automation  & security system

Step 04: Start main function.

Step 05: Set PORTA all PIN as Input,

PORTC PIN 2 as Output to Buzzer,

PORTD PIN 3 as Output to Relay.

Step 06: Set PORTC PIN 2 as Output 0 or 0V for Buzzer,

PORTD PIN 3 as Output 1 or 5V for Relay.

Step 07: Initiate LCD display.

Step 08: Initiate UART peripheral.

Step 09: Initiate ADC peripheral.

Step 10: DO FOREVER.

Step 11: Get analog readings from Analog Input Channel 2 twenty times, then acquire an average

value and place it in a variable (suppose a).

Step 12: Convert that value into a voltage output using following equation

and store it in another variable (suppose x)

Step 13: Apply the value of x into the following equation to get humidity value. Store it in

SMS array and another variable (suppose Humidity).

Step 14: Get value derive in Step 13 and convert it into ASCII character to display on the LCD.

Step 15: Repeat Step 11 to Step 12 for Analog Input Channel 3.

Step 16: Repeat Step 13 for the following equation for the value derived at Step 15.

Step 17: Repeat Step 14 for Step 16.

Step 18: Get analog readings from Analog Input Channel 1.

Step 19: Check if

Channel 1 reading is > 800 ,

73

Page 63: Message based home automation  & security system

set flag bit = 1.

check again if

flag bit == 1,

start buzzer, send SMS “YES”,

display “YES”

else

stop buzzer,

display “NO”.

Step 20: Repeat Step18 for Analog Input Channel 0.

Step 21: Repeat Step19 for Channel 0 reading is > 512.

Step 22: Check if

Step 16 reading is > 50 and Step 19 flag bit == 1

Invert Step 06 output.

Send SMS

Step 23: Stop

74

Page 64: Message based home automation  & security system

PART 02: FOR SENDING SMS (GSM COMMAND)

Step 01: Start

Step 02: Prepare GSM modem by writing “AT” command to UART module.

Step 03: Send “Carriage Return” as end of command.

Step 04: Set SMS Text mode by writing “AT+CMGF = 1” to UART module.

Step 05: Repeat Step 02.

Step 06: To set destination number write “AT+CMGS =” to UART module.

Step 07: Repeat Step 02.

Step 08: Write the destination number between “” to UART module.

Step 09: Repeat Step 02.

Step 10: Send “Line Feed” command.

Step 11: IF send SMS invoked THEN

write message to UART module

write Ctrl+Z to UART module as end of message indication.

Repeat Step 02 and Step 09.

Step 12: Stop.

75

Page 65: Message based home automation  & security system

7.3 FLOW CHART

76

Page 66: Message based home automation  & security system

77

Page 67: Message based home automation  & security system

7.3.1 DESCRIPTION

At first we turn on the supply for the system. Upon power supply to the system, a buzzer sound indicates that the system is on. When the power supply is on, the microcontroller initiates its internal ADC, UART module. Microcontroller uses the UART module to communicate with GSM modem. After initialization of ADC module, microcontroller starts reading the sensor value. The sensors are connected to the ADC module in the following manner respectively, RA0 pin is connected to PIR motion sensor, RA1 pin is connected to gas detector, RA2 pin is connected to temperature sensor and RA3 pin is connected to humidity sensor. If the readings from RA0 pin exceeds 512, which indicates motion and human presence; then the microcontroller turns on the buzzer and sends a SMS using GSM modem. At the same time if the readings from RA1 pin exceeds 800, which indicates existence of gas or smoke particle; then the microcontroller turns off the relay which controls the main power supply of the house and sends a SMS using GSM modem. In the mean time the microcontroller checks for changes of value from RA2 pin. If so, then the microcontroller calculates the value and checks if that the value is 50ºC or not. If the value is 50ºC, then the microcontroller turns off the relay and sends a SMS using GSM modem and also shows the temperature on LCD. Again at the same time microcontroller check for changes of value from RA3 pin. If the value changes, then microcontroller calculate the value and show the result on a LCD.

Here 512 and 800 is ADC value. It is unit less. These values can be calculated by following method;

ADC voltage resolution, Q =

Here, reference voltage is 5V. Since PIC16F877A has a 10-bit A/D converter, hence

Here, 2.5V is input voltage from PIR sensor and 0.004887V is minimum ADC resolution voltage.

Here, 3.9 V is input voltage from PIR sensor and 0.004887V is minimum ADC resolution voltage.

78

Page 68: Message based home automation  & security system

79

Page 69: Message based home automation  & security system

CHAPTER 8

CONCLUSION & FUTURE DEVELOPMENT

8.1 CONCLUSION

Message Based Home Automation and Security System has a strong appeal because it provides a flexible monitoring service over any distance.

In this project, a microcontroller is interfaced with a GSM modem and four sensors (temperature, humidity, gas & motion). Temperature and Humidity sensor constantly feed information about the ambient, to the microcontroller. Then microcontroller convert those analog data into digital data with the help of built in ADC module and process them and show on a LCD display. If a certain level of temperature (50oC) is crossed, microcontroller turns of the entire system. Also sends a message to a predefined cell phone number.

A gas and a PIR motion sensor is also interfaced with the same microcontroller and constantly monitor. If any of them is triggered it sends an immediate warning message to a predefine phone number.

The resulting system operates in real time. And can be easily modified to get any desired result to related feature. The system operation is cost effective.

8.2 DRAWBACKS

Even though the system operates in a cost effective manner, its construction is much complex and time consuming. Since 4 individual sensors were used, it demands individual testing of each sensor before the whole system is assembled together. Besides that, each sensors needs to be interfaced with microcontroller separately to operate in real time, so they do not interfere each other’s operation.

Another drawback of this project that we encountered is shortage of RAM in the microcontroller. The program we developed for this system uses almost all the RAM available in the microcontroller; which creates a problem of hang of the system. So we had to reprogram several times to make available space in the RAM to operate smoothly.

A complex algorithm also required to develop a program that allows the microcontroller to use the GSM network to send SMS to owner.

80

Page 70: Message based home automation  & security system

8.3 FUTURE DEVELOPMENT

This system incorporate a gas detector which can be used in garments industry for early warning of combustible gas which might lead to fire; since these factories are built in congested space.

This system can be implemented to monitor temperature, humidity and hazardous gas deposition in oil and gas mining fields.

Law enforcement agencies can use this concept for monitoring burglar warning. Fire service and civil defense can use this concept receive fire warning. This system can be expanded to home automation system.

81

Page 71: Message based home automation  & security system

Appendix A

SOURCE CODE

/*****************************************************************************

* Program for "Home Automation System"

* MCU: PIC16F877A;

* X-Tal: 8MHz (Ex.)

*****************************************************************************/

// LCD module connections

sbit LCD_RS at RB2_bit;

sbit LCD_EN at RB3_bit;

sbit LCD_D4 at RB4_bit;

sbit LCD_D5 at RB5_bit;

sbit LCD_D6 at RB6_bit;

sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;

sbit LCD_EN_Direction at TRISB3_bit;

sbit LCD_D4_Direction at TRISB4_bit;

sbit LCD_D5_Direction at TRISB5_bit;

sbit LCD_D6_Direction at TRISB6_bit;

sbit LCD_D7_Direction at TRISB7_bit;

// End LCD module connections

unsigned int Humidity = 0;

unsigned int Temperature = 0;

82

Page 72: Message based home automation  & security system

short smoke = 0;

short human = 0;

short system = 0;

short stt1,stt2,stt3;

short sms_musk1;

long adc_rd = 0;

long Cnt_human = 0;

long cnt_sms=0;

char uart_rd;

#define Buzzer RC2_bit

#define Relay RD3_bit

#define ON 1

#define OFF 0

void Get_Humidity(void);

void Get_Temperature(void);

void Get_PIR_Sensor(void);

void Get_Gas_Sensor(void);

void System_Control(void);

void Send_Presense(void);

void SMS_Int(void);

void UART_Write_CText(const char *cptr)

{

char chr;

for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);

83

Page 73: Message based home automation  & security system

}

char SMS[] = "Human: . Smoke: . Temp: C. Hum: %";

void main()

{

TRISA = 0xFF;//all input

ADCON1 = 0x00;//all analog

TRISC2_bit = 0; // Set as output

TRISD3_bit = 0; //Set as output

Relay = OFF;

Buzzer = ON;

// LCD Initialization...

Lcd_Init();

Lcd_Cmd(_LCD_CLEAR); //clear LCD

Lcd_Cmd(_LCD_CURSOR_OFF); //Cusros Off

Lcd_Out(1,4,"SMART HOME ");

Lcd_Out(2,4,"AUTOMATION ");

Delay_ms(500);

Lcd_Cmd(_LCD_CLEAR);

Buzzer = OFF;

UART1_Init(9600);

Delay_ms(100);

while(1)

{

84

Page 74: Message based home automation  & security system

Get_Humidity(void);

Get_Temperature(void);

Get_Gas_Sensor(void);

Get_PIR_Sensor(void);

//main system control...

System_Control(void);

cnt_sms++;

if(cnt_sms>5000)

{

cnt_sms = 0;

SMS_Int(void);

UART1_Write_Text(SMS);

UART1_Write((char)26);//send Control + Z

UART1_Write((char)13);

UART1_Write((char)10);

}

}//while...(1)

}//void main

/*****************************************************************************

********************** Get_Humidity ***********************************

*****************************************************************************/

void Get_Humidity(void)

{

char hum[] = "RH: %";

85

Page 75: Message based home automation  & security system

int ii;

float voltage = 00.00;

ADCON0 = 0b00010001;// Select Channel 2

adc_rd = 0; //Clear Previous Data

for(ii=0;ii<20;ii++)

{

adc_rd += ADC_Read(2); //Take sample and add

}

adc_rd /= 20;// Get the average data

voltage = adc_rd*0.004883;// 5/1023

Humidity = (int)((3.71 * voltage * voltage * voltage) - (20.65 * voltage * voltage) + (64.81 * voltage) - 27.44);

hum[3] = Humidity/10 + 48;

hum[4] = Humidity%10 +48;

Lcd_Out(1,1,hum);

// collect data...

SMS[37] = hum[3];

SMS[38] = hum[4];

}

/*****************************************************************************

********************** Get_Temperature *********************************

*****************************************************************************/

void Get_Temperature(void)

{

char Tmp[] = "Temp: C";

int jj;

float voltage = 00.00;

ADCON0 = 0b00011001;// Select Channel 3

86

Page 76: Message based home automation  & security system

adc_rd = 0; //Clear Previous Data

for(jj=0;jj<20;jj++)

{

adc_rd += ADC_Read(3); //Take sample and add

}

adc_rd /= 20;// Get the average data

voltage = adc_rd*0.004883;// 5/1023

Temperature = (int)((5.26 * voltage * voltage * voltage) - (27.34 * voltage * voltage) + (68.87 * voltage) - 17.81);

Tmp[5] = Temperature /10 + 48;

Tmp[6] = Temperature %10 +48;

Tmp[7] = 223;

Lcd_Out(1,8,Tmp);

// collect data...

SMS[27] = Tmp[5];

SMS[28] = Tmp[6];

SMS[29] = Tmp[7];

}

/*****************************************************************************

********************** Get_Gas_Sensor *********************************

*****************************************************************************/

void Get_Gas_Sensor(void)

{

Lcd_Out(2,1,"SMK:");

ADCON0 = 0b00001001;//select Channel 1

if(ADC_Read(1)>800)

{

smoke = 1;

87

Page 77: Message based home automation  & security system

Lcd_Out(2,5,"YES");

if(stt2 && smoke)//generate single pulse

{

Buzzer = ON;

SMS_Int(void);

UART_Write_CText("Smoke Found");

UART1_Write((char)26);//send Control + Z

UART1_Write((char)13);

UART1_Write((char)10);

Delay_ms(100);

Buzzer = OFF;

stt2 = 0;

}

SMS[17] = 'Y';

SMS[18] = 'E';

SMS[19] = 'S';

}

else

{

smoke = 0;

Lcd_Out(2,5,"No ");

stt2 = 1;

SMS[17] = 'N';

SMS[18] = 'O';

SMS[19] = ' ';

}

88

Page 78: Message based home automation  & security system

}

/*****************************************************************************

********************** Get_PIR_Sensor ********************************

*****************************************************************************/

void Get_PIR_Sensor(void)

{

Lcd_Out(2,9,"Man:");

ADCON0 = 0b00000001;//select Channel 0

if(ADC_Read(0)>512)

{

human = 1;

Lcd_Out(2,13,"YES");

if(stt1 && human)//generate single pulse

{

Buzzer = ON;

SMS_Int(void);

UART_Write_CText("Human Found");

UART1_Write((char)26);//send Control + Z

UART1_Write((char)13);

UART1_Write((char)10);

Delay_ms(100);

Buzzer = OFF;

stt1 = 0;

}

SMS[6] = 'Y';

SMS[7] = 'E';

89

Page 79: Message based home automation  & security system

SMS[8] = 'S';

}

else

{

human = 0;

Lcd_Out(2,13,"No ");

stt1 = 1;

SMS[6] = 'N';

SMS[7] = 'O';

SMS[8] = ' ';

}

// after movement hysteresis...

if(human == 1)

{

system = 1;

Cnt_human = 0;

}

else

{

if(Cnt_human<50)Cnt_human++;

while(Cnt_human>=49)

{

system = 0;

break;

}

}

90

Page 80: Message based home automation  & security system

}

/*****************************************************************************

********************** Get_PIR_Sensor ********************************

*****************************************************************************/

void System_Control(void)

{

if(system)

{

if(Temperature<60 && smoke ==0)

{

Relay = ON;

}

else

{

Relay = OFF;

if(Temperature>60 || smoke==1)

{

Buzzer = ~Buzzer;

Delay_ms(500);

}

}

}

else

{

Relay = OFF;

}

91

Page 81: Message based home automation  & security system

if(Temperature>60 || smoke==1)

{

Buzzer = ~Buzzer;

Delay_ms(500);

SMS_Int(void);

UART_Write_CText("Fire Found");

UART1_Write((char)26);//send Control + Z

UART1_Write((char)13);

UART1_Write((char)10);

}

}

/*****************************************************************************

********************** SMS_Int ************************************

*****************************************************************************/

void SMS_Int(void)

{

UART1_Write_Text("AT\r");

Delay_ms(500);

UART_Write_CText("AT+cmgf=1\r");

Delay_ms(500);

UART_Write_CText("AT+cmgs=");

UART1_Write((char)'"');

UART_Write_CText("01799251992");

UART1_Write((char)'"');

UART1_Write((char)13);

UART1_Write((char)10);

Delay_ms(500);

}

/********************** End Of The Program *********************************/

92

Page 82: Message based home automation  & security system

Appendix B

REFERENCES:

Website:

1) http://en.wikipedia.org/wiki/Main_Page 2) http://electrosome.com/ 3) http://www.engineersgarage.com/ 4) http://www.wirelessdevnet.com/ 5) https://www.techshopbd.com/

Books:

6) Advanced PIC Microcontroller Projects in C - Dogan Ibrahim

7) Microcontroller Based Temperature Monitoring And Control - Dogan Ibrahim

8) Microcontroller Programming The Microchip PIC - Julio Sanchez

9) Interfacing PIC Microcontrollers Embedded Design By Interactive Simulation –

Martin P. Bates

10) PIC16F877A Datasheet.

93