Sei sulla pagina 1di 80

8051 Microcontroller based gas & smoke alarm system

Chapter 1

INTRODUCTION
The main aim of our project is to alert people and take safety measures during fire
and gas leak emergencies.
Smoke sensor is used to detect the break out of fire.LPG is most commonly used
as cooking gas everywhere. Due to some defects, the gas may start leaking and it may
result in big hazards.. This system is meant for detecting such leakages and fire break out
in an early stage and take appropriate steps and send warning messages to the consumer.
.

1.1 FUNCTIONING OF THE SYSTEM:


The project consists of 8051 controller, LCD, gas sensor, smoke sensor, stepper
motor, dc fan, buzzer, and GSM modem.

This system will detect any chances for a gas leakage from cylinder-based
appliance (e.g. LPG cylinder). Usually fire occurs in a cylinder-based appliance
due to leakage of gas through the gas pipeline. By using a gas sensor, the above
reason is detected in advance.

By using smoke sensor and installing it in an appropriate place, fire-break out can
be detected.

If gas leakage occurs, closing the gas outlet valve can control it. This is achieved
with the help of a stepper motor connected to the valve. Also an exhaust fan is
turned on to expel the leaked gas out.

If a fire emergency occurs, a water valve is opened, which may be connected to a


fire sprinkler and use to extinguish fire.

DEPT. OF ECE

Page 1

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

In both these cases, a buzzer alarm is used to alert people and appropriate alert
message is displayed on LCD.

The controlling operation of LCD, stepper motor and buzzer is done by the 8051
controller.

The controller also sends a warning SMS to the user by using GSM modem
interfaced to the system.

A number of devices are controlled by the microcontroller through a 12v relay.

A vibrator is used to alert people belonging high risk groups.

The user can control any of the devices connected to the relay using GSM.

DEPT. OF ECE

Page 2

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 2

BLOCK DIAGRAM

LCD

GAS
SENSOR
SMOKE
SENSOR

STEPPER
MOTOR
MICRO
CONTROLLER
8051

MAX
232

GAS
VALVE
GSM
MODEM

POWER
SUPPLY

BUZZER
JRELAY BOARD

WATER
VALVE

EXHAUST
FAN

VIBRATOR

ELECTRIC
LOCK

APPLIANCES

MAINS
SUPPLY

Fig. 2.1 block diagram of the 8051 Microcontroller based gas & fire alarm system.

DEPT. OF ECE

Page 3

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig. 2.2 GSM device.

2.1 BLOCK DIAGRAM DESCRIPTION:


The block diagram represents the basic working blocks of the proposed manumatic gas
and smoke monitoring system. The basic principle of operation is prevention of fire
hazard using a manumatic system.The system is powered by a 12v dc adapter.
The system performs four major operations,which can be classified in their order of
occourance as,
1. Sensing.
2. Alerting.
3. Automatic safety precautions.
4. Manual control.

2.1.1 SENSING :
In this system we are using two sensors, a gas sensor and a smoke sensor.
Whenever there is leakage of gas or fire breaks out, the gas particles or the smoke
particles reacts with the semiconductor inside the sensor and the sensor converts
the respective physical quantity into an electrical signal, which can be read by an
observer.
DEPT. OF ECE

Page 4

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

The sensitivity of the sensors can be controlled and set to a desired


range to get the optimum conversion of physical quantity. Here the output signal
of the sensor will make the corresponding microcontroller pin as high.

2.1.2 ALERTING :
The microcontroller forms the heart of the proposed embedded system.
The microcontroller will be continuously monitoring the two sensors and
whenever the either of the sensors gets triggered the microcontroller gets the
information about what type of accident has occured. Once the microcontroller
gets the information, it alerts the users and people in the surrounding environment
using four methods namely,

1. AUDIO SIGNALLING
2. VISUAL DISPLAY
3. ALERTING SMS
4. VIBRATOR

1. AUDIO SIGNALLING :
Here we are using a piezoelectric buzzer as an audio signalling device. A
piezoelectric element may be driven by an electronic circuit or any other audio
signal source, driven with a piezoelectric audio amplifier. Sounds commonly used
to indicate that a button has been pressed are a click, a ring or a beep.
In case of any accidents the microcontroller turns on the buzzer
which produces audible sound signals, alerting the nearby people about the
possible hazard by grabbing their attention.

DEPT. OF ECE

Page 5

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

2. VISUAL DISPLAY :
The system uses a 16*2 lcd to display a warning message about the
possible accident that has occured and allows the user to take the necessary safety
precautions and control the hazard.
The microcontroller will be programmed to display two separate
messages one for the gas leakage and the other for the fire breakout. In the idle
state it will display a message indicating display a monitoring message indicating
normal condition.

3. ALERTING MESSAGE :
A gsm modem interfaced with the microcontroller gets the
required command from the microcontroller to send an predefined message in the
form of an alerting sms to a single or multiple users. A sim will be inserted into
the gsm modem which operates anywhere where the mobile network is available,
which gives the necessary information about the type of accident has happened
and the user can take the necessary actions to control the hazard.
The microcontroller has been programmed to send three commands to the GSM
modem. In case of any hazards first, it will send a command to the modem to
transmit a message. Secondly, if the user wants to turn off any appliance or the
mains itself he can send a predefined message to the modem. The microcontroller
sends a separate command to read the received message. Finally, if the user sends
multiple messages to the modem then the microcontroller sends a command to
delete the previous received message. This deletion of message is necessary
because the average memory storing capacity of a SIM is limited.

4. VIBRATOR :
A vibrator is the unique feature of our system. This is used to alert special
group people, such as deaf, elderly people and people with other disability, people
suffering from Narcolepsy and also for people who are working in isolated

DEPT. OF ECE

Page 6

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

environment, who are occupied in any works or in sleep. These vibrators can be
installed inside pillows, beds and chairs.

2.1.3 AUTOMATIC SAFETY PRECAUTIONS :


This operation works on the principle of prevention of fire hazard by
detecting the gas leakage and taking out the fire in its early stages. The automatic
safety precautions help in both prevention and control of fire.
These safety precautions include controlling several
unique components which performs simultaneous operations for different hazards.
The microcontroller is programmed to prevent and control the hazard for two
different cases.
Firstly, in case of gas leakage the microcontroller takes the following steps,

1. STEPPER MOTOR CONTROL :


A stepper motor is a brushless, synchronous electric motor
that can divide a full rotation into a large number of steps. The motor's
position can be controlled precisely, as long as the motor is carefully sized
to the application. We are using a stepper motor to simulate the working of
a gas valve. The stepper motor used is a bipolar stepper motor. The
rotation of the stepper motor indicates the closing of the gas valve.

2. EXHAUST FAN :
A exhaust fan is a type of fan, designed to pull hot air out of
the building. An exhaust fan pulls hot air out of a building and forces it
into the outside space. This causes a positive pressure in the outside area
forcing air out through the vents, while at the same time producing a
negative pressure inside the living areas which draws cool air in through
open windows.
Whenever gas leaks inside an enclosure like a building, it is
important to remove the gas from the inside of the building to the outside
environment. And this has to be done in quick time so we are using an
exhaust fan in this system to remove the hazardous gas
DEPT. OF ECE

Page 7

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

3. ELECTRIC LOCK :
An electric lock also called as an electronic lock is a locking device
which operates by means of electric current. Electric locks are sometimes
stand-alone with an electronic control assembly mounted directly to the
lock. In case of any gas leakage, the electric lock is opened automatically.
These locks are installed to doors and windows; it enables the opening and
closing of the doors and windows which helps in evacuation process. The
operation of the electric lock is simulated using an led. The glowing of the
LED bulb indicates the opening of the lock.

4. MAINS SUPPLY :
Mains supply is the general-purpose alternating current (AC)
electric power supply. Here the supplied voltage is 230 volts AC. If there
is any leakage of combustible gas there may be possibilities of fire break
out due to the sparks produced by turning on and off of the switches to
avoid this mishap we program the microcontroller to turn off the mains
supply.

Secondly, if smoke is detected the microcontroller takes the following steps,

5. WATER VALVE :
A valve is a device that regulates the flow of a fluid (gases,
liquids, fluidized solids,) by opening, closing, or partially obstructing various
passageways. Valves are technically pipe fittings, In an open valve, fluid flows
in a direction from higher pressure to lower pressure. Here the water valve is
used to take out the fire if any by sprinkling water over it.

6. STEPPER MOTOR CONTROL :


A stepper motor is a brushless, synchronous electric motor
that can divide a full rotation into a large number of steps. The motor's
DEPT. OF ECE

Page 8

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

position can be controlled precisely, as long as the motor is carefully sized


to the application. Stepper motors are similar to switched reluctance
motors. We are using a stepper motor to simulate the working of a gas
valve. The stepper motor used is a bipolar stepper motor. The rotation of
the stepper motor indicates the closing of the gas valve. Since, there is a
possibility of the gas catching the fire we turn off the gas valve.

7. ELECTRIC LOCK :
An electric lock also called as an electronic lock is a locking device
which operates by means of electric current. Electric locks are sometimes
stand-alone with an electronic control assembly mounted directly to the
lock. During fire emergencies, the electric lock is opened automatically.
These locks are installed to doors and windows, it enables the opening and
closing of the doors and windows which helps in evacuation process. The
operation of the electric lock is simulated using an led. The glowing of the
LED bulb indicates the opening of the lock.

2.1.4 MANUAL CONTROL :


This system also works as an home automation system. Home
automation is automation of the home, housework or household activity. Home
automation may include centralized control of lighting, HVAC (heating,
ventilation and air conditioning), appliances, and other systems, to provide
improved convenience, comfort, energy efficiency and security. Home automation
for the elderly and disabled can provide increased quality of life for persons who
might otherwise require caregivers or institutional care.

DEPT. OF ECE

Page 9

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

A home automation system integrates electrical devices in a house with


each other. The user can control any electronic appliance interfaced with the system. User
can open the doors of the house or any other enclosures for the guests even if he or she is
not present at the spot. The user can alert the people inside the home using the vibrator
and can turn off the mains supply just in case if he feels unsafe. Since , fire accidents
occur at unanticipated magnitudes and condition it is better to have human control over
the system.

DEPT. OF ECE

Page 10

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 3

MICROCONTROLLER (P89V51RD2):
3.1. Features
3.1.1. Criteria for choosing:
The basic criteria for choosing a microcontroller suitable for the application are:
The first and foremost criterion is that it must meet the task at hand efficiently and
cost effectively. In analyzing the needs of a microcontroller-based project, it is seen
whether an 8- bit, 16-bit or 32-bit microcontroller can best handle the computing
needs of the task most effectively. Among the other considerations in this category
are:
(a)Speed: The highest speed that the microcontroller supports.
(b)Packaging: It may be a 40-pin DIP (dual inline package) or a QFP (quad
flat package), or some other packaging format. This is important in terms of
space, assembling, and prototyping the end product.
(c)Power consumption: This is especially critical for battery-powered
products.
(d) The number of I/O pins and the timer on the chip.
(e) How easy it is to upgrade to higher performance or lower consumption
versions.
(f) Cost per unit: This is important in terms of the final cost of the product in
which a microcontroller is used.
The second criterion in choosing a microcontroller is how easy it is to develop
products around it. Key considerations include the availability of an assembler,
debugger, compiler, technical support.

The third criterion in choosing a microcontroller is its ready availability in


DEPT. OF ECE

Page 11

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

needed quantities both now and in the future. Currently of the leading 8-bit
microcontrollers, the 8051 family has the largest number of diversified suppliers. By
supplier is meant a producer besides the originator of the microcontroller. In the case
of the 8051, this has originated by Intel several companies also currently producing
the 8051.

Thus the microcontroller p89v51rd2, satisfying the criterion necessary for the
proposed application is chosen for the task.

Further more the A P89V51RD2 has 64KB and 1024 Bytes of Data Ram.
P89V51RD2 is an 80C51 microcontroller with 64 kB Flash and 1024 bytes of data
RAM. A key feature of the P89v51rd2 is its X2 mode option. The design engineer
can choose to run the application with the conventional 80C51 clock rate (12 clocks per
machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the
throughput at the same clock frequency. Another way to benefit from this feature is to
keep the same performance by reducing the clock frequency by half, thus dramatically
reducing the EMI. The Flash program memory supports both parallel programming and
in serial In-System Programming (ISP). Parallel programming mode offers gangprogramming at high speed, reducing programming costs and time to market. ISP allows
a device to be reprogrammed in the end product under software control. The capability
to field/update the application firmware makes a wide range of applications possible.
The P89V51RD2 is also In-Application Programmable (IAP), allowing the Flash program
memory to be reconfigured even while the application is running.

3.1.2. Description:
The 8051 family of microcontrollers is based on an architecture which is highly
optimized for embedded control systems. It is used in a wide variety of applications
from military equipment to automobiles to the keyboard. Second only to the Motorola
68HC11 in eight bit processors sales, the 8051 family of microcontrollers is available in a
DEPT. OF ECE

Page 12

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

wide array of variations from manufacturers such as Intel, Philips, and Siemens. These
manufacturers have added numerous features and peripherals to the 8051 such as I2C
interfaces, analog to digital converters, watchdog timers, and pulse width modulated
outputs. Variations of the 8051 with clock speeds up to 40MHz and voltage
requirements down to 1.5 volts are available. This wide range of parts based on one
core makes the 8051 family an excellent choice as the base architecture for a
company's entire line of products since it can perform many functions and developers
will only have to learn this one platform.

The

P89V51RD2

is

low-power,

high-performance

CMOS

8-bit

microcontroller with 8K bytes of in-system programmable Flash memory. The device


is manufactured using high-density nonvolatile memory technology and is compatible
with the industry- standard 80C51 instruction set and pinout. The on-chip Flash allows
the program memory to be reprogrammed in-system or by a conventional nonvolatile
memory programmer. By combining
programmable

versatile

8-bit

CPU with

in-system

Flash on a monolithic chip, the P89V51RD2 is a powerful

microcontroller which provides a highly-flexible and cost- effective solution to many


embedded control applications. In addition, the P89V51RD2 is designed with static
logic for operation down to zero frequency and supports two software selectable power
saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters,
serial port, and interrupt system to continue functioning. The Power-down mode
saves the RAM con-tents but freezes the oscillator, disabling all other chip functions
until the next interrupt or hardware reset.

3.1.3 Features:

80C51 Central Processing Unit

5 V Operating voltage from 0 to 40 MHz


DEPT. OF ECE

Page 13

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

64 kB of on-chip Flash program memory with ISP (In-System Programming) and


IAP (In-Application Programming)
Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART

PCA (Programmable Counter Array) with PWM and Capture/Compare functions

Four 8-bit I/O ports with three high-current Port 1 pins (16 mA each)

Three 16-bit timers/counters

Programmable Watchdog timer (WDT)

Eight interrupt sources with four priority levels

DEPT. OF ECE

Page 14

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig-3.1: Block diagram.

DEPT. OF ECE

Page 15

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig-3.2: Pin Configuration.

DEPT. OF ECE

Page 16

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig-3.3: Pin description.

DEPT. OF ECE

Page 17

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig-3.4: Pin description.

DEPT. OF ECE

Page 18

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig-3.5: Pin description.

DEPT. OF ECE

Page 19

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

3.2 Special function Registers:


Remark: Special Function Registers (SFRs) accesses are restricted in the following ways:
User must not attempt to access any SFR locations not defined.
Accesses to any defined SFR locations must be strictly for the functions for the
SFRs.
SFR bits labeled -, 0 or 1 can only be written and read as follows:

- Unless otherwise specified, must be written with 0, but can return


any value when read (even if it was written with 0). It is a reserved bit
and may be used in future derivatives.

0 must be written with 0, and will return a 0 when read.

1 must be written with 1, and will return a 1 when read.

Functional Description:

Memory organization:
The device has separate address spaces for program and data memory.

Flash program memory:


There are two internal flash memory blocks in the device. Block 0 has 64 kbytes and
contains the users code. Block 1 contains the Philips-provided ISP/IAP routines and may
be enabled such that it overlays the first 8 kbytes of the user code memory. The 64 kB
Block 0 is organized as 512 sectors, each sector consists of 128 bytes. Access to the IAP
routines may be enabled by clearing the BSEL bit in the FCF register. However, caution
must be taken when dynamically changing the BSEL bit. Since this will cause different
physical memory to be mapped to the logical program address space, the user must
avoid clearing the BSEL bit when executing user code within the address range 0000H to
1FFFH.

DEPT. OF ECE

Page 20

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Data RAM memory:

The data RAM has 1024 bytes of internal memory. The device can also address
up to 64 kB for external data memory.

Expanded data RAM addressing:


The P89V51RD2 has 1 kB of RAM. See Figure 5 Internal and external data
memory structure.
The device has four sections of internal data memory:
1. The lower 128 bytes of RAM (00H to 7FH) are directly and indirectly addressable.
2. The higher 128 bytes of RAM (80H to FFH) are indirectly addressable.
3. The special function registers (80H to FFH) are directly addressable only.
4. The expanded RAM of 768 bytes (00H to 2FFH) is indirectly addressable by the move
external instruction (MOVX) and clearing the EXTRAM bit. Since the upper 128 bytes
occupy the same addresses as the SFRs, the RAM must be accessed indirectly. The RAM
and SFRs space are physically separate even though they have the same addresses.

AUXR - Auxiliary register (address 8EH) bit allocation:

DEPT. OF ECE

Page 21

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 4

LIQUID CRYSTAL DISPLAY ( LCD )

A liquid crystal display (LCD) is a thin, flat display device made up of any
number of color or monochrome pixels arrayed in front of a light source or reflector. Each
pixel consists of a column of liquid crystal molecules suspended between two transparent
electrodes, and two polarizing filters, the axes of polarity of which are perpendicular to
each other. Without the liquid crystals between them, light passing through one would be
blocked by the other. The liquid crystal twists the polarization of light entering one filter
to allow it to pass through the other.
Many microcontroller devices use 'smart LCD' displays to output visual
information. LCD displays designed around Hitachi's LCD HD44780 module, are
inexpensive, easy to use, and it is even possible to produce a readout using the 8x80
pixels of the display. They have a standard ASCII set of characters and mathematical
symbols.
For an 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4bit data bus it only requires the supply lines plus seven extra lines. When the LCD display
is not enabled, data lines are tri-state and they do not interfere with the operation of the
microcontroller.

Fig.4.1: A typical LCD

DEPT. OF ECE

Page 22

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

4.1 Signals to the LCD


The LCD also requires 3 control lines from the microcontroller:
Enable (E)
This line allows access to the display through R/W and RS lines. When this line is
low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is high,
the LCD checks the state of the two control lines and responds accordingly.
Read/Write (R/W)
This line determines the direction of data between the LCD and microcontroller.
When it is low, data is written to the LCD. When it is high, data is read from the LCD.
Register select (RS)
With the help of this line, the LCD interprets the type of data on data lines. When
it is low, an instruction is being written to the LCD. When it is high, a character is being
written to the LCD.

4.2 Logic status on control lines


E

-0 Access to LCD disabled


-1 Access to LCD enabled

R/W - 0 Writing data to LCD


- 1 Reading data from LCD
RS

- 0 Instruction
- 1 Character

DEPT. OF ECE

Page 23

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

4.3 Writing and reading the data from the LCD


4.3.1 Writing data to the LCD is done in several steps:
1) Set R/W bit to low
2) Set RS bit to logic 0 or 1 (instruction or character)
3) Set data to data lines (if it is writing)
4) Set E line to high
5) Set E line to low

4.3.2 Read data from data lines (if it is reading):


1) Set R/W bit to high
2) Set RS bit to logic 0 or 1 (instruction or character)
3) Set data to data lines (if it is writing)
4) Set E line to high
5) Set E line to low

4.4 Pin description


Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins
(two pins are extra in both for back-light LED connections)

DEPT. OF ECE

Page 24

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig.4.2 Pin diagramof 2x16lineLCD

4.5 Pin Details

Table: 4.1

DEPT. OF ECE

Page 25

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 5

POWERSUPPLY & REGULATOR


5.1 POWER SUPPLY
Main building block of any electronic system is the power supply to provide
required power for their operation. For the microcontroller, audio amplifier, keyboard,
edge connector +5V, required the power supply provides regulated output voltage of
+5V, three terminal IC 7805 meets the requirement of +5V regulated. The secondary
voltage from the main transformer is rectified by diodes D1-D4 and is filtered by
capacitor C1. This unregulated dc voltage is supplied to input pin of regulator IC. C2 is an
input bypass capacitor and C3 is to improve ripple rejection. The IC used are fixed
regulator with internal short circuit current limiting and thermal shut down capability

Fig:5.1 Power supply using 7805 regulator IC for Digital circuits


DEPT. OF ECE

Page 26

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

5.2 7805 REGULATOR IC:


This circuit is a small +5V power supply, which is useful when experimenting with
digital electronics. Small inexpensive wall transformers with variable output voltage are
available from any electronics shop and supermarket. Those transformers are easily
available, but usually their voltage regulation is very poor, which makes then not very
usable for digital circuit experimenter unless a better regulation can be achieved in some
way. The following circuit is the answer to the problem.
This circuit can give +5V output at about 150 mA current, but it can be increased
to 1 A when good cooling is added to 7805 regulator chip. The circuit has over overload
and terminal protection.

(a)

(b)

Fig. 5.2 7805 regulator IC

Fig:5.3 Connection diagram

DEPT. OF ECE

Page 27

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Pinout of the 7805 regulator IC:

Unregulated voltage in

Ground

Regulated voltage out

Component list:

7805 regulator IC

100 uF electrolytic capacitor, at least 25V voltage rating

10 uF electrolytic capacitor, at least 6V voltage rating

100 nF ceramic or polyester capacitor

DEPT. OF ECE

Page 28

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 6

SENSORS
6.1

Operation Principle
The sensing material in MQ gas sensors is metal oxide, most typically SnO2.

When a metal oxide crystal such as SnO2 is heated at a certain high temperature in air,
oxygen is adsorbed on the crystal surface with a negative charge. Then donor electrons in
the crystal surface are transferred to the adsorbed Oxygen, resulting in leaving positive
charges in a space charge layer. Thus, surface potential is formed to serve as a potential
barrier against electron flow.
Inside the sensor, electric current flows through the conjunction parts (grain
boundary) of SnO2 microcrystal. At grain boundaries, adsorbed oxygen forms a potential
barrier which prevents carriers from moving freely. The electrical resistance of the sensor
is attributed to this potential barrier. In the presence of a deoxidizing gas, the surface
density of the negatively charged oxygen decreases, so the barrier height in the grain
boundary is reduced. The reduced barrier height decreases sensor resistance.
The relationship between sensor resistance and the concentration of deoxidizing gas can
be expressed by the following equation over a certain range of gas concentration:
Rs = A[C] ^ (-a)
Where: Rs = electrical resistance of the sensor
A = constant
[C] = gas concentration
a = slope of Rs curve

DEPT. OF ECE

Page 29

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Fig. 6.1 Model of inter-grain potential barrier


(in the absence of gases)

Fig. 6.2 Model of inter-grain potential barrier


(in the presence of gases)

DEPT. OF ECE

Page 30

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

EQUATIONS:

6.2 BASIC TEST LOOP

Fig. 6.3 Basic test circuit.


The above is basic test circuit of the sensor. The sensor need to be given 2
voltages, heater voltageVH and test voltageVC.VH used to supply certified
working temperature to the sensor, while VC used
to detect voltage (VRL) on load resistanceRLwhom is in series with sensor. The
sensor has light polarity, Vc need DC power. VC and VH could use same power circuit
with precondition to assure performance of sensor. In order to make the sensor with better
performance, suitable RL value is needed:
Power of Sensitivity body (Ps):
Ps=Vc2Rs/ (Rs+RL)^(2)

Sensitivity to gas
The relationship of MQ sensor resistance to gas concentration is linear on a
logarithmic scale within a practical range of gas concentration (from several ppm to
DEPT. OF ECE

Page 31

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

several thousand ppm).. The sensor will show sensitivity to a variety of deoxidizing
gases, with relative sensitivity to certain gases optimized by the formulation of sensing
materials and operating temperature. Since actual sensor resistance values vary from
sensor to sensor, typical sensitivity characteristics are expressed as a ratio of sensor
resistance in various concentrations of gases (Rs) over resistance in a certain
concentration of a target gas (Ro).
Dependency on temperature and humidity
The detection principle of sensors is based on chemical adsorption and desorption
of gases on the sensors surface. As a result, ambient temperature will affect sensitivity
characteristics by changing the rate of chemical reaction. In addition, humidity causes a
decrease in Rs as water vapor adsorbs on the sensors surface.
6.3 GRAPHS EXPLANATION
The first graph shows the typical sensitivity characteristics of the MQ-2, ordinate
means resistance ratio of the sensor (Rs/Ro), abscissa is concentration of gases. Rs means
resistance in different gases, Ro means resistance of sensor in 1000ppm Hydrogen. All
tests are under standard

test conditions.

The second graph shows the typical temperature and humidity characteristics.
Ordinate means resistance ratio of the sensor (Rs/Ro), Rs means resistance of sensor in
1000ppm Butane under different tem. and humidity. Ro means resistance of the sensor in
environment of 1000ppm Methane, 20C/65%RH
The third graph shows the typical sensitivity characteristics of
the MQ-6, Ordinate means resistance ratio (Rs/Ro), abscissa is concentration of gases. Rs
means of the sensor (Rs/Ro), Rs means resistance of sensor resistance in different gases,
Ro means resistance of sensor in 1000ppm LPG. All tests are under standard test
conditions.
The fourth graph shows the typical temperature and humidity characteristics. .
Ordinate means resistance ratio of the sensor (Rs/Ro), Rs means resistance of sensor in
1000ppm Methane under different tem. and humidity. Ro means resistance of the sensor
in environment of 1000ppm Propane, 20C/65%RH.

DEPT. OF ECE

Page 32

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

MQ2

Relationship between resistance ratio of the sensor and concentration

Relationship between resistance ratio and Temperature/Humidit

DEPT. OF ECE

Page 33

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

MQ6

Relationship between resistance ratio of the sensor and concentration

Relationship between resistance ratio and Temperature/Humidity

DEPT. OF ECE

Page 34

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

6.4 Following conditions must be prohibited


1. Exposed to organic silicon steam
Organic silicon steam cause sensors invalid, sensors must be avoid exposing to
silicon bond, fixture, silicon latex, putty or plastic contain silicon environment
2. High Corrosive gas
If the sensors exposed to high concentration corrosive gas (such as H2Sz,
SOXCl2HCl etc), it will not only result in corrosion of sensors structure, also it
cause sincere sensitivity attenuation.
3. Alkali, Alkali metals salt, halogen pollution
The sensors performance will be changed badly if sensors be sprayed polluted by
alkali metals salt especially brine, or be exposed to halogen such as fluorine.
4. Touch water
Sensitivity of the sensors will be reduced when spattered or dipped in water.
5. Freezing
Do avoid icing on sensor surface, otherwise sensor would lose sensitivity.
6. Applied voltage higher
Applied voltage on sensor should not be higher than stipulated value, otherwise it
cause down-line or heater damaged, and brings on sensors sensitivity characteristic
changed badly.

6.5 Following conditions must be avoided


1. Water Condensation
Indoor conditions, slight water condensation will affect sensors performance
lightly. However, if water condensation on sensors surface and keep a certain period,
sensor sensitivity will be decreased.

2. Used in high gas concentration


No matter the sensor is electrified or not, if long time placed in high gas
concentration, if will affect sensors characteristic.

DEPT. OF ECE

Page 35

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

3. Long time storage


The sensors resistance produce reversible drift if its stored for long time without
electrify, this drift is related with storage conditions. Sensors should be stored in airproof
without silicon gel bag with clean air.
For the sensors with long time storage but no electrify, they need long aging time
for stability before using.
4. Long time exposed to adverse environment
No matter the sensors electrified or not, if exposed to adverse environment for
long time, such as high humidity, high temperature, or high pollution etc, it will affect the
sensors performance badly.
5. Vibration
Continual vibration will result in sensors down-lead response then rupture. In
transportation or assembling line, pneumatic screwdriver/ultrasonic welding machine can
lead this vibration.
6. Concussion
If sensors meet strong concussion, it may lead its lead wire disconnected.

7. Usage
For sensor, handmade welding is optimal way. If use wave crest welding should
meet the following conditions:
a) Soldering flux: Rosin soldering flux contains least chlorine
b) Speed: 1-2 Meter/ Minute
c) Warm-up temperature10020C
d) Welding temperature25010C
e) 1 time pass wave crest welding machine
If disobey the above using terms, sensors sensitivity will be reduced

DEPT. OF ECE

Page 36

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 7

BUZZER AND BUTTON INTERFACE

7.1 Buzzer
This is a small 12mm round buzzer that operates around the audible 2kHz range.
We drove it directly from a 5V Controller to generate the tones for our Simon
demonstration game. Use buzzers to create simple music or user interfaces.

Fig:.1 HDX

DEPT. OF ECE

Page 37

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

7.2 Button interface:

The Button Interface module provides you with a set of programmable buttons
that can be made to create and reset variables when clicked.
There is a Push button used in our project which basically used to reset the
Microcontroller. A push-button is a simple switch mechanism for controlling some aspect
of a machine or a process. The surface is usually flat or shaped to accommodate the
human finger or hand, so as to be easily depressed or pushed.

Fig:.2 Button

DEPT. OF ECE

Page 38

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 8

GSM
Global System for Mobile Communications, or GSM (originally from Groupe
Spcial Mobile), is the world's most popular standard for mobile telephone systems. The
GSM Association estimates that 80% of the global mobile market uses the standard. GSM
is used by over 1.5 billion people across more than 212 countries and territories. This
ubiquity means that subscribers can use their phones throughout the world, enabled by
international roaming arrangements between mobile network operators. GSM differs from
its predecessor technologies in that both signaling and speech channels are digital, and
thus GSM is considered a second generation (2G) mobile phone system. This also
facilitates the wide-spread implementation of data communication applications into the
system.
The GSM standard has been an advantage to both consumers, who may benefit
from the ability to roam and switch carriers without replacing phones, and also to network
operators, who can choose equipment from many GSM equipment vendors. GSM also
pioneered low-cost implementation of the short message service (SMS), also called text
messaging, which has since been supported on other mobile phone standards as well. The
standard includes a worldwide emergency telephone number feature (112).
Newer versions of the standard were backward-compatible with the original GSM
system. For example, added packet data capabilities by means of General Packet Radio
Service (GPRS). Also higher speed data transmission using Enhanced Data Rates for
GSM Evolution (EDGE).

8.1 History
In 1982, the European Conference of Postal and Telecommunications
Administrations (CEPT) created the Groupe Spcial Mobile (GSM) to develop a standard
for a mobile telephone system that could be used across Europe. In 1987, a memorandum
of understanding was signed by 13 countries to develop a common cellular telephone
system across Europe. In 1989, GSM responsibility was transferred to the European
Telecommunications Standards Institute (ETSI) and phase I of the GSM specifications
DEPT. OF ECE

Page 39

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

were published in 1990. The first GSM network was launched in 1991 by Radiolinja in
Finland with network infrastructure provided by Telenokia and Siemens Networks which
later on merged as Nokia Siemens Networks. By the end of 1993, over a million
subscribers were using GSM phone networks being operated by 70 carriers across 48
countries.

8.2 Technical details


GSM is a cellular network, which means that mobile phones connect to it by
searching for cells in the immediate vicinity. There are five different cell sizes in a GSM
networkmacro, 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 roof top
level. Micro cells are cells whose antenna height is under average roof top level; they are
typically used in urban areas. Picocells are small cells whose coverage diameter is a few
dozen metres; they are mainly used indoors. Femtocells are cells designed for use in
residential or small business environments and connect to the service providers 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 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 picocell 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 a lot of
call capacity is needed indoors; for example, 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.
DEPT. OF ECE

Page 40

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

The modulation used in GSM is Gaussian minimum-shift keying (GMSK), a kind


of continuous-phase frequency shift keying. In GMSK, the signal to be modulated onto
the carrier is first smoothed with a Gaussian low-pass filter prior to being fed to a
frequency modulator, which greatly reduces the interference to neighbouring channels
(adjacent-channel interference).

8.3 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 firstgeneration systems.
Most 3G networks in Europe operate in the 2100 MHz frequency band. The transmission
power in the handset is limited to a maximum of 2 watts in GSM850/900 and 1 watt in
GSM1800/1900.

8.4 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.
We can control any appliance using GSM by sending AT commands via its serial
interface.

DEPT. OF ECE

Page 41

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

8.5 AT Command Syntax:


The AT or at prefix must be set at the beginning of each command line. To
terminate a line enter <CR>.
The AT commands set implemented by SIM300 is a combination of GSM and ITU-T
recommendation and AT commands developed by SIMCOM. The GSM engine is
generally referred to as the following term:
a. Mobile Equipment (ME).
b. Mobile Station (MS).
c. Terminal Adapter (TA).
d. Data Communication equipment (DCE) or facsimile DCE (FAC modem, FAX
board);
The controlling device at the other end of the serial line is referred to as following term:
a. Terminal Equipment (TE).
b. Data Terminal Equipment (DTE) or plainly the application which is running on
an embedded system.
Some of the most commonly used AT commands

COMMAND

DESCRIPTION

AT+CMGD

DELETE SMS MESSAGE

AT+CMGF

SELECT SMS MESSAGE FORMAT

AT+CMGL

LIST SMS MESSAGE FROM PREFERRED STORE

AT+CMGR

READ SMS MESSAGE

AT+CMGS

SEND SMS MESSAGE

AT+CMGW

WRITE SMS MESSAGE TO MEMORY

AT+CMSS

SEND SMS FROM STORAGE

AT+CNMI

NEW MESSAGE INDICATIONS

DEPT. OF ECE

Page 42

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

8.6.1 Detailed description of AT commands


1. AT+CMGD

DELETE SMS MESSAGE

2. AT+CMGF

SELECT SMS MESSAGE FORMAT

DEPT. OF ECE

Page 43

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

3. AT+CMGL

LIST SMS MESSAGES FROM PREFFERED STORE

4. AT+CMGR

READ SMS MESSAGE

DEPT. OF ECE

Page 44

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

5. AT+CMGS

SEND SMS MESSAGE

6. AT+CMGW

WRITE SMS MESSAGE TO MEMORY

DEPT. OF ECE

Page 45

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

7. AT+CNMI

NEW SMS MESSAGE INDICATIONS

Here in our project we are using GSM to send the alerting message to the concerned
person during emergency situation and providing him the power to control the different
devices (which are connected to the relay board).

DEPT. OF ECE

Page 46

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 9

APPLICATIONS
In high rise buildings or in multi storied buildings like apartments where
evacuation process can be relatively slow, this system can be used to alert people
during emergencies.
It can be used in institutions like old age homes or hospitals, where a large number
of people belonging to high risk groups are present.
Such systems are extensively used in places like LPG distribution units, petrol
bunks, textile industries where LPG leakage and fire accidents can cause
devastating effects and damage to life and property.
It is also suitable for single houses, schools and small industrial units.

DEPT. OF ECE

Page 47

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 10

ADVANTAGES & LIMITATIONS


10.1 Advantages
The system is easy to design because several components are interfaced to the
microcontroller through the relay
It can be manually operated. The sensors automatically detect the presence of
smoke or LPG and trigger the alarming and controlling mechanism. But at a later
stage, the devices connected to the relay can be operated manually.
A simple low cost 8051 microcontroller can be selected as the core component for
this system.
The system can be used to control several appliances in a building using GSM.
The system has multiple functions like alerting, controlling devices during
emergencies
This system combines the concept of home automation and alarm systems. So, it
has many additional features. A vibrator is used in the system, which can be
placed in a bed or a pillow pad which helps in alerting sleeping individuals
belonging to high risk groups.

10.2 Limitations
The success of delivery of alert message to the user and controlling of devices
depends on the GSM signal strength.
Strategic placement of the system is very much necessary.

DEPT. OF ECE

Page 48

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 11

SOFTWARE REQUIREMENTS
11.1 INTRODUCTION TO KEIL SOFTWARE
The KEIL is a software package, which is a part of an Embedded C. This is
used to program the microcontroller. The KEIL program which executed will generate
.hex file that is used to program the microcontroller. The starting address from which the
code has to be transferred can be changed and selected by the user.
The KEIL software helps to make the programming easy. The hex-codes can be
transferred into the microcontroller by using a serial bus RS-232. The microcontroller has
a program in its internal ROM and when executed will receive the data from the RS-232
that is connected to the serial port or mouse port of a computer.
The MicroVision4 IDE from KEIL software, combines project management,
make facilities, source code editing, program debugging and complete simulation in one
power environment. MicroVision2 helps you get program work faster than while
providing an easy use development platform. The editor and debugger are integrated into
a single application and provide a flawless embedded project development environment.
The microcontroller has been programmed using KEIL software. The program is
written in the KEIL software and then executed. The software will provide .hex file. The
.hex file will consist of hexadecimal codes, which are the op-codes that have to be coded
into the microcontroller. By interfacing the computer and the microcontroller with RS232 bus, we can download, the hex codes into the microcontroller from away address.
This codes when executed provides the output, which is required by the programmer.
Hence the difficulty of the assembly language programming has been replaced
with KEIL high-level-language, which is easy to program.

DEPT. OF ECE

Page 49

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

11.2 SOURCE CODE


//xxxxxxxxxxxxxxxxxxxxxxxxxxxx " SMS CONTROLLED HOME AUTOMATION
(WaveCom))" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
#include < reg51.h >
#include < string.h >
sbit RS = P2^2;
sbit RW = P2^1;
sbit EN = P2^0;

//LCD's Control bits setting

sbit WaterValve =P1^0;


// port1's 4 bits are
used here..all 8 pins can be used depending on application
sbit DCMotor =P1^1;
sbit FAN
=P1^2;
sbit LOCK
=P1^3;
//Assigning them to
corresponding out put ie RELAY1,2,3....ETC
sbit RELAY1
=P1^4;
sbit RELAY2
=P1^5;
sbit RELAY3
=P1^6;
sbit MAINS
=P1^7;
sbit
sbit
sbit
sbit

D0=P3^4;
D1=P3^5;
D2=P3^6;
D3=P3^7;

sbit Buzzer
#define
#define

= P2^3;

ON
OFF

unsigned char

1
0
text, ch ;

#define
#define

MHZ
KHZ

#define

XTAL_FREQ

#define

DelayUs(x) { unsigned char _dcnt; \


_dcnt = (x)*((XTAL_FREQ)/(11.0592MHZ)); \
while(--_dcnt != 0) \

DEPT. OF ECE

*1000L
*1

/* number of kHz in a MHz */


/* number of kHz in a kHz */

11.0592MHZ

Page 50

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

continue; }
/*******************************************************************
/
void Delayms ( unsigned char cnt )
{
unsigned char i ;
do
{
i = 4 ;
do {
DelayUs ( 250 ) ;
} while ( --i ) ;
} while ( --cnt ) ;
}
/********************************Prototypes of the functions which
are used in the program ************************/
void Serial_Init ( );
void lcd_init( ) ;
void lcd_cmd(unsigned char ch ) ;
void Delay( );
unsigned char receive ( );
void receive_str ( ) ;
void Transmit( unsigned char text ) ;
void Transmit_Str ( unsigned char *s ) ;
void write_lcd ( unsigned char text ) ;
void write_str ( unsigned char *s )
;
unsigned char relay_no_fn ( unsigned char *msg )
void relay_cntrl ( unsigned char relay_no ) ;
xdata unsigned char relay1_on[12]
xdata unsigned char relay2_on[12]
xdata unsigned char relay3_on[12]
xdata unsigned char relay1_off[12]
','O','F','F','\0'};
xdata unsigned char relay2_off[12]
','O','F','F','\0'};
xdata unsigned char relay3_off[12]
','O','F','F','\0'};

={'R','L','1',' ','O','N','\0'};
={'R','L','2',' ','O','N','\0'};
={'R','L','3',' ','O','N','\0'};
={'R','L','1','
={'R','L','2','
={'R','L','3','

xdata unsigned char valve_open[12] ={'W','a','V','


xdata unsigned char valve_close[12]={'W','a','V','
','O','F','F','\0'};
xdata unsigned char DCmotor_on[12] ={'D','C','M','
xdata unsigned char DCmotor_off[12]={'D','C','M','
','O','F','F','\0'};
xdata unsigned char fan_on[12]
={'F','A','N','
xdata unsigned char fan_off[12]
={'F','A','N','
','O','F','F','\0'};
xdata unsigned char lock_on[12]
={'L','C','K','
xdata unsigned char lock_off[12]
={'L','C','K','
','O','F','F','\0'};
xdata unsigned char mains_on[12]
={'M','N','S','
DEPT. OF ECE

Page 51

','O','N','\0'};
','O','N','\0'};
','O','N','\0'};
','O','N','\0'};
','O','N','\0'};

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

xdata unsigned char mains_off[12] ={'M','N','S','


','O','F','F','\0'};
xdata unsigned char Stepper_on[12] ={'S','T','P',' ','O','N','\0'};
xdata unsigned char Stepper_off[12]={'S','T','P','
','O','F','F','\0'};

/*********************************** UART intialization


***************************************************************
/
void Serial_Init ( )
{
TMOD = 0X20 ;
auto reload mode
SCON = 0X50 ;
TH1 = 0XFD ;
setting
TR1 = 1 ;
}

// Timer1 8 bit
//9600 baud rate

/*********************************LCD Initialisation
****************************************************************/
void lcd_init( )
{
lcd_cmd ( 0x38
lcd_cmd ( 0x0e
lcd_cmd ( 0x01
lcd_cmd ( 0x06
lcd_cmd ( 0x80

);
);
);
);
);

}
void lcd_cmd(unsigned char ch)
{
RS = 0;
RW = 0;
P0 = ch;
EN = 1;
Delay();
EN = 0;
}
/*************************************** Display function for LCD
*****************************************************/
void write_lcd ( unsigned char text)
{
RS = 1;
RW = 0;
P0 = text ;
DEPT. OF ECE

Page 52

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

EN = 1;
Delay ();
EN = 0;
}
/************************************** time delay function upto
count ************************************************/
void Delay ( )
{
int i = 0 ;
for (i = 0 ; i < 10000 ; i++ )
;
}
/************************************* function for transmitting
commands to GSM modem* ***************************/

AT

void Transmit_Str ( unsigned char *AT_Cmds)


{
int i = 0 ;
while ( *(AT_Cmds+i) != '\0' )
{
Transmit ( *(AT_Cmds+i) ) ;
i++ ;
}
}
/************************************* Receiving from SBUF
returning it *****************************************/

and

unsigned char receive ( )


{
while (!RI ) ;
RI = 0;
return ( SBUF );
}
/************************************ Transmit to SBUF
***************************************************************
/
void Transmit( unsigned char text
{
SBUF = text ;
while ( !TI ) ;
TI = 0 ;
}

/*********************************** function to write array of


charecter into LCD ***********************************/
void write_str ( unsigned char *s )
{
int i = 0 ;
while ( *(s+i) != '\0' )
DEPT. OF ECE

Page 53

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

{
write_lcd ( *(s+i) ) ;
i++ ;
}
}
/************************************Function to receive string aftr
AT+CMGR=StoredMsgLoc******************************/
unsigned char a[ 12 ];
void receive_str ( )
{
int i = 0 ;
int count = 0 ;
unsigned char text , relay_no ,a[ 11 ] ,temp ;
//After doing AT+CMGR=1 ,now search for message which is valid
while ( 1 )
{
text = receive ( ) ; // keep on putting all value until
desired to text ie neglecting the values which are not neccessary
if ( text == '\n' )
// when it reaches the first "\n'
ie ENTER operation, then look for second ENTER operation
{
count++ ;
//when both the ENTERS were done
now the avilable charecters are message chars which are sent.
if(count == 3)
{
for ( i = 0 ; i < 7 ; i++ ) //take 7
charecters in an array , check with desired string which are
declared in array
{
a[ i ] = receive ( ) ;
}
temp = a [ 6 ] ;
if ( temp == 0x46 )
{
a [ 7 ] = '\0' ;
relay_no = relay_no_fn ( a ) ;
//function to get the information on which relay to be ON.
relay_cntrl ( relay_no ) ;
// do ON/OFF
break ;
}
else
{
a[ 6 ] = '\0' ;
relay_no = relay_no_fn ( a ) ;
//function to get the information on which relay to be ON.
relay_cntrl ( relay_no ) ;
// do ON/OFF
break ;
}
}
}
}
DEPT. OF ECE

Page 54

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

}
/*************************** function to get the information on
which relay to be on.***********************/
unsigned char relay_no_fn ( unsigned char *msg )
{
if( strcmp (relay1_on , msg ) == 0 )
return (1) ;
else
{
if
( strcmp (relay2_on , msg ) == 0 )
return ( 2 ) ;
else
{
if
( strcmp (relay3_on , msg ) == 0 )
return ( 3 ) ;
else
{
if
( strcmp (relay1_off , msg ) == 0
)
return ( 4 ) ;
else
{
if
== 0

( strcmp (relay2_off , msg )

)
return ( 5 ) ;
else
{
if

msg ) == 0

( strcmp (relay3_off ,

)
return ( 6 ) ;
else
{
if

(valve_open , msg ) == 0

( strcmp

)
return ( 7) ;
else
{
if

(valve_close , msg ) == 0

( strcmp

)
return ( 8

) ;
else
{
if
strcmp (DCmotor_on , msg ) == 0

return ( 9 ) ;
else
{
if
( strcmp (DCmotor_off , msg ) == 0

return ( 10 ) ;
DEPT. OF ECE

Page 55

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

else
{
if

( strcmp (fan_on , msg ) == 0

return ( 11 ) ;
else
{
if

( strcmp (fan_off , msg ) == 0

return ( 12 ) ;
else
{
if

( strcmp (lock_on , msg ) == 0

return ( 13 ) ;
else
{
if

( strcmp (lock_off , msg ) == 0

return ( 14 ) ;
//
else
//
{
//
if

( strcmp (mains_on , msg ) == 0

//
return ( 15 ) ;
else
{
if

( strcmp (mains_on , msg ) == 0

return ( 15 ) ;
else
{
if

( strcmp (mains_off , msg ) == 0

)
return ( 16 ) ;
DEPT. OF ECE

Page 56

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

else
{
if

( strcmp (Stepper_on , msg ) == 0

)
return ( 17) ;
else
{
if( strcmp (Stepper_off , msg ) ==
0

)
return ( 18 ) ;
else
return (0);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

}
void StepperMotorON()
{
int i ;
for( i = 0 ; i<12 ; i++)
{
D0 = 1; D1=0; D2=0; D3=1;
Delayms(10) ;
DEPT. OF ECE

Page 57

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

D0 = 1; D1=1; D2=0; D3=0;


Delayms(10 ) ;
D0 = 0; D1=1; D2=1; D3=0;
Delayms(10 ) ;
D0 = 0; D1=0; D2=1; D3=1;
Delayms(10 ) ;
}
}
void StepperMotorOFF()
{
int i ;
for( i = 0 ; i<12 ; i++)
{
D0 = 0; D1=0; D2=1;
Delayms(10 ) ;
D0 = 0; D1=1; D2=1;
Delayms(10 ) ;
D0 = 1; D1=1; D2=0;
Delayms(10 ) ;
D0 = 1; D1=0; D2=0;
Delayms(10 ) ;
}

D3=1;
D3=0;
D3=0;
D3=1;

}
/******************************RELAY ON/OFF Operation
*******************************************************/
void relay_cntrl ( unsigned char relay_no )
{
lcd_cmd( 0xc0 ) ;
switch ( relay_no)
{
case 1 :
lcd_cmd(0x01);
write_str ( " RELAY1 ON " );
RELAY1 = ON ;
Transmit_Str("AT+CMGD=1\r\n") ;
break ;
case 2 :
lcd_cmd(0x01);
write_str ( " RELAY2 ON " );
RELAY2 = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 3 :
lcd_cmd(0x01);
write_str ( " RELAY3 ON " );
RELAY3 = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 4 :
lcd_cmd(0x01);
write_str ( " RELAY1 OFF " );
DEPT. OF ECE

Page 58

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

RELAY1 = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 5 :
lcd_cmd(0x01);
write_str ( " RELAY2 OFF " );
RELAY2 = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 6 :
lcd_cmd(0x01);
write_str ( " RELAY3 OFF " );
RELAY3 = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 7 :
lcd_cmd(0x01);
write_str ( " Water Valve open " );
WaterValve = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 8 :
lcd_cmd(0x01);
write_str ( " Water Valve Close " );
WaterValve = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 9 :
lcd_cmd(0x01);
write_str ( " DCMotor ON " );
DCMotor = ON ;
Transmit_Str("AT+CMGD=1\r\n") ;
break ;
case 10 :
lcd_cmd(0x01);
write_str ( " DCMotor OFF " );
DCMotor = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 11 :
lcd_cmd(0x01);
write_str ( " Fan ON " );
FAN = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 12 :
lcd_cmd(0x01);
write_str ( " Fan OFF " );
FAN = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 13 :
lcd_cmd(0x01);
write_str ( " Lock ON " );
DEPT. OF ECE

Page 59

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

LOCK = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 14 :
lcd_cmd(0x01);
write_str ( " Lock OFF " );
LOCK = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 15 :
lcd_cmd(0x01);
write_str ( " Mains ON " );
MAINS = ON ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 16 :
lcd_cmd(0x01);
write_str ( " Mains OFF " );
MAINS = OFF ;
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 17 :
lcd_cmd(0x01);
write_str ( "StepperMotor ON" );
StepperMotorON();
Transmit_Str("AT+CMGD=1\r\n");
break ;
case 18 :
lcd_cmd(0x01);
write_str ( "StepperMotor OFF" );
StepperMotorOFF();
Transmit_Str("AT+CMGD=1\r\n");
break ;

case 0 :
lcd_cmd(0x01);
write_str ( "ERROR MESSAGE " );
Transmit_Str("AT+CMGD=1\r\n") ;
break ;
}
}

void LPGPrecautions( )
{
WaterValve= OFF;
Buzzer = ON;
DEPT. OF ECE

Page 60

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

FAN
= ON;
LOCK
= ON;
DCMotor = ON;
RELAY1 = OFF;
RELAY2 = OFF;
RELAY3 = OFF;
MAINS
= OFF;
StepperMotorON( );
}
void FIREPrecautions( )
{
WaterValve= ON;
Buzzer = ON;
FAN
= OFF;
LOCK
= ON;
DCMotor = ON;
RELAY1 = OFF;
RELAY2 = OFF;
RELAY3 = OFF;
StepperMotorON( );
}
/************************************* main( ) Strats here
***************************************************/
void Ext_INT1_ISR(void) interrupt 2
{
lcd_cmd( 0x01 );
write_str("...!DANGER......");
lcd_cmd( 0xc0 );
write_str("Gas leaking......");
LPGPrecautions( );
Transmit_Str("AT+CMGS=\"9916948112\"\r\n" ) ;
// cahnge no if u want
Transmit_Str("!!!!!!!!!Gas Leaking take neccesary
action!!!!!!!!!!\r\n");
Transmit(0x1A);
Delayms(10000);
Transmit_Str("AT+CMGS=\"9686258840\"\r\n" ) ;
Transmit_Str("!!!!!!!!!Gas Leaking take neccesary
action!!!!!!!!!!\r\n");
Transmit(0x1A);
Delayms(10000);
}
void Ext_INT0_ISR(void) interrupt 0
{
lcd_cmd( 0x01 );
write_str("...!DANGER......");
lcd_cmd( 0xc0 );
write_str("Fire..Fire....");
FIREPrecautions( );
Transmit_Str("AT+CMGS=\"9916948112\"\r\n" ) ;
// change no if u want
Transmit_Str("!Fire Alert!!Smoke at Home take
neccesary action!!!!!!!!\r\n");
DEPT. OF ECE

Page 61

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Transmit(0x1A);
Delayms(10000);
Transmit_Str("AT+CMGS=\"9686258840\"\r\n" ) ;
Transmit_Str("!Fire Alert!!Smoke at Home take
neccesary action!!!!!!!!\r\n");
Transmit(0x1A);
Delayms(10000);
}
void main( )
{
unsigned char StoredMsgLoc ,sbuf_text[15];
P1 = 0X00 ;
P3|= 0xF0 ;
Buzzer=OFF;
EA = 1;
Interrupts
IT1 = 1;
interrupt 0 for falling edge on /INT1 (P3.3)
EX1 = 1;
External Interrupt 1
IT0 = 1;
interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1;
External Interrupt 0
Serial_Init( );
lcd_init( ) ;

// Enable all
// Configure
// Enable
// Configure
// Enable

Transmit_Str("AT+CMGD=1\r\n");
Transmit_Str("AT+CMGD=1\r\n");
write_str("GasLeak......");
lcd_cmd( 0xc0 );
write_str("Detector......");
lcd_cmd( 0x80 );
//Command to display on
LCD's First line
while( 1 )
{
//
Transmit_Str("AT+CMGD=1\r\n");
sbuf_text[0] = receive ( );
//checking
for new message indication ie +CMTI: "SM",1
sbuf_text[1] = '\0';
if( strcmp ( sbuf_text, "+" )== 0 )
'1' says that the received message is in location 1
{
sbuf_text[1] = receive ( );
sbuf_text[2] = '\0';
if( strcmp ( sbuf_text, "+C" )== 0 )
{
sbuf_text[2] = receive ( ) ;
DEPT. OF ECE

Page 62

//he digit

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

sbuf_text[3] = '\0' ;
if( strcmp ( sbuf_text, "+CM" )== 0 )
{
sbuf_text[3] = receive ( ) ;
sbuf_text[4] = '\0'
;
if( strcmp ( sbuf_text, "+CMT" )== 0 )
{
sbuf_text[4] = receive ( ) ;
sbuf_text[5] = '\0' ;
if( strcmp ( sbuf_text, "+CMTI"
)== 0 )
{
sbuf_text[5] = receive ( ) ;
sbuf_text[6] = '\0' ;
if( strcmp ( sbuf_text,
"+CMTI:" )== 0 )
{
sbuf_text[6] = receive
( ) ;
sbuf_text[7] = '\0' ;
if( strcmp ( sbuf_text,
"+CMTI: " )== 0 )
{
//
write_str(sbuf_text);
//

while(1);
sbuf_text[7] =

receive ( ) ;

//"

receive ( ) ;

//S

receive ( ) ;

//M

sbuf_text[8]

sbuf_text[9]

sbuf_text[10] =
receive ( ) ;

//"
sbuf_text[11] =

receive ( ) ;

//,

receive ( ) ;

// msg serial no in inbox

StoredMsgLoc
sbuf_text[12] =

'\0'

;
Transmit_Str("AT+CMGR=");
message by using AT+CMGR=1

//after receiving read the


Transmit (

StoredMsgLoc ) ;
lcd_cmd(0x8a);
Transmit_Str("\r\n");
receive_str ( ) ;
}
}
}
}
DEPT. OF ECE

Page 63

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

}
}}}}

Chapter 12

FUTURE ENHANCEMENTS:
A MIC can be connected which can be used to give voice commands and
directions for evacuations during emergencies.
The module can be connected to more complex equipments, depending on the
building or industry in which it is used.
A remote warning handset or a vibrating pad can be developed which is always in

contact with the person whom we want to alert during emergency situations.

DEPT. OF ECE

Page 64

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

Chapter 13

CONCLUSION
Large number of LPG leakage and fire accidents has occurred because of the
negligence shown in installing or maintaining alarm systems. In our project we have
combined the concept of home automation and alarm systems. This project is user
friendly, as the user needs to have a basic knowledge of mobile operation. Our project is
efficient one as we can monitor the devices from far off places using GSM with the help
of a low cost circuit. The user can control a number of devices during such emergencies.
The main objective of this project is to alert people and take safety measures
during LPG leakage and fire emergencies. Our project has a vibrating mechanism which
is used to alert people belonging to high risk groups, along with normal buzzer alarm.
Finally as engineers we are committed to create innovative solutions for the use of
people from all strata of the society; hence we have designed an alarm system which is
useful in high risk situations, for high risk group people also.

DEPT. OF ECE

Page 65

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

BIBLIOGRAPHY
BOOKS

Ayala- The 8051 microcontroller

8051 microcontroller and Embedded System by Mazidi

An Embedded Software Primer by David E Simon

Embedded system design by Frank Vahid / Tony Givargis

DATASHEETS

GSM modem SIM300

P89V51RD2 8051 based microcontroller

SC1602 16X2 characters serial LCD module datasheet

MQ2 smoke sensor datasheet

MQ6 gas sensor datasheet

WEBSITES

www.wikipedia.com

www.webopedia.com

www.usfa.com

www.scribd.com

www.ask.com

www.electronicsforu.com

www.microcontroller.com/embeddedsystems

www.ieee.com

DEPT. OF ECE

Page 66

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

www.datasheets4u.com

APPENDIX

DEPT. OF ECE

Page 67

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 68

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 69

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 70

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 71

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 72

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 73

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 74

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 75

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 76

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 77

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 78

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 79

APSCE, 2011

8051 Microcontroller based gas & smoke alarm system

DEPT. OF ECE

Page 80

APSCE, 2011

Potrebbero piacerti anche