Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
.
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.
DEPT. OF ECE
Page 1
APSCE, 2011
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.
The user can control any of the devices connected to the relay using GSM.
DEPT. OF ECE
Page 2
APSCE, 2011
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
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
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
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
environment, who are occupied in any works or in sleep. These vibrators can be
installed inside pillows, beds and chairs.
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
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.
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.
Page 8
APSCE, 2011
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.
DEPT. OF ECE
Page 9
APSCE, 2011
DEPT. OF ECE
Page 10
APSCE, 2011
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.
Page 11
APSCE, 2011
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
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
versatile
8-bit
CPU with
in-system
3.1.3 Features:
Page 13
APSCE, 2011
Four 8-bit I/O ports with three high-current Port 1 pins (16 mA each)
DEPT. OF ECE
Page 14
APSCE, 2011
DEPT. OF ECE
Page 15
APSCE, 2011
DEPT. OF ECE
Page 16
APSCE, 2011
DEPT. OF ECE
Page 17
APSCE, 2011
DEPT. OF ECE
Page 18
APSCE, 2011
DEPT. OF ECE
Page 19
APSCE, 2011
Functional Description:
Memory organization:
The device has separate address spaces for program and data memory.
DEPT. OF ECE
Page 20
APSCE, 2011
The data RAM has 1024 bytes of internal memory. The device can also address
up to 64 kB for external data memory.
DEPT. OF ECE
Page 21
APSCE, 2011
Chapter 4
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.
DEPT. OF ECE
Page 22
APSCE, 2011
- 0 Instruction
- 1 Character
DEPT. OF ECE
Page 23
APSCE, 2011
DEPT. OF ECE
Page 24
APSCE, 2011
Table: 4.1
DEPT. OF ECE
Page 25
APSCE, 2011
Chapter 5
Page 26
APSCE, 2011
(a)
(b)
DEPT. OF ECE
Page 27
APSCE, 2011
Unregulated voltage in
Ground
Component list:
7805 regulator IC
DEPT. OF ECE
Page 28
APSCE, 2011
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
DEPT. OF ECE
Page 30
APSCE, 2011
EQUATIONS:
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
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
MQ2
DEPT. OF ECE
Page 33
APSCE, 2011
MQ6
DEPT. OF ECE
Page 34
APSCE, 2011
DEPT. OF ECE
Page 35
APSCE, 2011
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
Chapter 7
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
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
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
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.
Page 40
APSCE, 2011
DEPT. OF ECE
Page 41
APSCE, 2011
COMMAND
DESCRIPTION
AT+CMGD
AT+CMGF
AT+CMGL
AT+CMGR
AT+CMGS
AT+CMGW
AT+CMSS
AT+CNMI
DEPT. OF ECE
Page 42
APSCE, 2011
2. AT+CMGF
DEPT. OF ECE
Page 43
APSCE, 2011
3. AT+CMGL
4. AT+CMGR
DEPT. OF ECE
Page 44
APSCE, 2011
5. AT+CMGS
6. AT+CMGW
DEPT. OF ECE
Page 45
APSCE, 2011
7. AT+CNMI
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
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
Chapter 10
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
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
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
DEPT. OF ECE
*1000L
*1
11.0592MHZ
Page 50
APSCE, 2011
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','
Page 51
','O','N','\0'};
','O','N','\0'};
','O','N','\0'};
','O','N','\0'};
','O','N','\0'};
APSCE, 2011
// 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
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
and
Page 53
APSCE, 2011
{
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
}
/*************************** 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
)
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
else
{
if
return ( 11 ) ;
else
{
if
return ( 12 ) ;
else
{
if
return ( 13 ) ;
else
{
if
return ( 14 ) ;
//
else
//
{
//
if
//
return ( 15 ) ;
else
{
if
return ( 15 ) ;
else
{
if
)
return ( 16 ) ;
DEPT. OF ECE
Page 56
APSCE, 2011
else
{
if
)
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
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
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
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
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
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
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 ( ) ;
StoredMsgLoc
sbuf_text[12] =
'\0'
;
Transmit_Str("AT+CMGR=");
message by using AT+CMGR=1
StoredMsgLoc ) ;
lcd_cmd(0x8a);
Transmit_Str("\r\n");
receive_str ( ) ;
}
}
}
}
DEPT. OF ECE
Page 63
APSCE, 2011
}
}}}}
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
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
BIBLIOGRAPHY
BOOKS
DATASHEETS
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
www.datasheets4u.com
APPENDIX
DEPT. OF ECE
Page 67
APSCE, 2011
DEPT. OF ECE
Page 68
APSCE, 2011
DEPT. OF ECE
Page 69
APSCE, 2011
DEPT. OF ECE
Page 70
APSCE, 2011
DEPT. OF ECE
Page 71
APSCE, 2011
DEPT. OF ECE
Page 72
APSCE, 2011
DEPT. OF ECE
Page 73
APSCE, 2011
DEPT. OF ECE
Page 74
APSCE, 2011
DEPT. OF ECE
Page 75
APSCE, 2011
DEPT. OF ECE
Page 76
APSCE, 2011
DEPT. OF ECE
Page 77
APSCE, 2011
DEPT. OF ECE
Page 78
APSCE, 2011
DEPT. OF ECE
Page 79
APSCE, 2011
DEPT. OF ECE
Page 80
APSCE, 2011