You are on page 1of 53

1

CHAPTER 1
INTRODUCTION
1.1 Introduction
In many works of life people make use of gas as a generic term thou the purpose to which it
serves each individual and chemical composition may vary. For example In homes as cooking
gas, to power some generators in industries, as a tool in generating welding flame and in
chemical laboratories. The usefulness of gas cannot be overemphasized and as such it has
become quite indispensable in our society today.
Everything in this world that has an advantage equally has disadvantages also and so is the
situation with gas. Many a times due to human carelessness, forgetfulness or due to wear out of
mechanical parts a leakage might occur. Gas leakages are difficult to detect until it too late and
this might lead to catastrophic damages and loss of lives and property if the gas meets with a
naked flame and ignites.
The best approach in which this situation can be prevented is if the leakage can be quickly
detected and immediately contained. This challenge has been solved in different ways in the past
each of them having their varying pitfalls. This project is aimed at taking advantage of those
weaknesses and developing them into strengths by application of the knowledge of embedded
systems.
The design will be simple and portable within the confines of an undergraduate student. The
system will help notify in case of a leakage by giving an alarm once a gas leakage is detected or

2
printing a message to a liquid crystal display or by employing both methods for effectiveness
thereby helping to save lives.

1.2 Statement of the Problem
One of the properties of gas is the ability to fill the surrounding space and do it quickly. The
molecules of a gas move chaotically colliding with themselves and the walls of the container.
There are three basic hazards that gases possess, flammable, toxic and asphyxiant Honeywell
Analytics (2009). So due to the fact that a gas quickly fills up a space it could pose a danger to
humans in the surrounding area, so a system that quickly detects the leakage of gas and warns the
residents will be instrumental in safeguarding the lives and properties of the people in that area.
1.3 Background and History of study
The word gas comes from the word chaos. Gas is a swarm of molecules moving randomly and
constantly colliding with themselves and the walls of the container; while a detector is a device
used for sensing the presence of changes in something. So a gas sensor is a device that spots the
existence of gas contained in vicinity in order to alert observers of a potentially dangerous
situation through audible and visual indicators such as light or alarms or the combination of both.
Gas detectors are usually installed as fixed (stationery) or portable unit depending on the
application.
Before the advent of modern electronic sensors, early means of gas detection relied on less
precise methods. Coal miners would bring canaries down to the tunnels as an early gas detection
system against life threating gases.

3
The canary is usually a very songful bird and would stop singing and eventually die
indicating the presence of life threating gases to the miners, a sign that they should
quickly exit the vicinity. The major step in the development of gas detection technology
was the use of a chemically infused paper that turned brown when exposed to carbon
monoxide (Wikipedia, 2012, Gas leak detection).
Since then many advance technologies have been developed to detect gas leakages effectively
and indicate the type of gas detected on a display.
Gas detectors are broadly divided into two categories by the type of gas they detect either
combustible or toxic; this is further divided by the technology used. Catalytic and
infrared sensors detect combustible gases and electrochemical and metal oxide
semiconductor technologies are used to detect toxic gases. (Thomas, 2012, how gas
detectors work).
Catalytic sensors represent a large number of gas detector devices that are manufactured today.
This technology is used to detect combustible gases such as hydrocarbon, and works via catalytic
oxidation. The sensors of this type of detector are typically constructed from a platinum treated
wire coil. As a combustible gas comes into contact with the catalytic surface, it is oxidized and
the wiring resistance is changed by heat that is released. A bridge circuit is typically used to
indicate the resistance change.
Infrared sensors or IR detectors work via a system of transmitters and receivers to detect
combustible gases, specifically hydrocarbon vapors. Typically, the transmitters are light sources
and receivers are light detectors. If a gas is present in the optical path, it will interfere with the

4
power of the light transmission between the transmitter and receiver. The altered state of light
determines if and what type of gas is present.
Electrochemical sensors or cells are most commonly used in the detection of toxic gases like
carbon monoxide, chlorine and nitrogen oxides. They function via electrodes signals when a gas
is detected. Generally, these types of detectors are highly sensitive and give off warning signals
via electrical currents. Various manufacturers produce these detectors with a digital display.
Metal Oxide Semiconductors, or MOS, are also used for detecting toxic gases (commonly carbon
monoxide) and work via a gas sensitive film that is composed of tin or tungsten oxides. The
sensitive film reacts with gases, triggering the device when toxic levels are present. Generally,
metal oxide sensors are considered efficient due their ability to operate in low-humidity ranges.
In addition, they are able to detect a range of gases, including combustibles.
1.4 Application of Gas Detection Systems
1. In the oil and gas industry they are quite indispensible because they handle a large
amount of highly flammable hydrocarbons. They are used in exploration drilling rigs,
production platforms, onshore oil and gas terminals and refineries.
2. In manufacturing semi-conductors highly toxic and flammable materials are used
phosphorus, arsenic, and boron are used as doping agents. Typical applications are close
to the wafer reactors, wafer dryers, gas cabinets, and chemical vapor deposition.
3. In chemical plants in their raw materials storage, process areas, laboratories, pump rows,
compressor stations and loading and unloading areas.

5
4. In power stations where coal and oil are used as fuels and nowadays natural gas. It is used
around the boiler pipe work and burners, in and around the turbine packages, in coal silos
and conveyor belts in coal and oil fired stations.
5. In hospitals in their laboratories, refrigeration plants and boiler rooms.
6. In welding shops where oxyacetylene flame is being used.
7. In homes where liquefied petroleum gas is used as a fuel for cooking.
8. In enclosed areas used as car parks or underground parking lots, to detect the presence of
toxic fumes produced by the exhaust the vehicles. The output may then be used to drive a
ventilation fan in modern parking lots.
1.5 Aims and Objectives of the project
The aim of the project is to design and fabricate a gas detection system for domestic
purposes.
The objectives of the project are to:
a) Design a compact and portable gas leakage detector
b) Evaluate the performance of the designed equipment





6
CHAPTER TWO
LITERATURE REVIEW
This chapter will attempt to discuss the related literature under the following topics:
i) Microcontrollers
ii) Gas sensors
iii) Liquid crystal display
iv) Light emitting diode
v) Buzzer
vi) Power supply

2.1 Microcontrollers
A microcontroller is a single chip, self-contained computer which incorporates all the basic
components of a personal computer on a much smaller scale (Byte Craft Limited, 2002, Pg. 5).
Microcontrollers are often referred to as single chip devices or single chip computers. The main
consequence of the microcontrollers small size is that its resources are far more limited than
those of a desktop personal computer. In functional terms, a microcontroller is a programmable
single chip which controls a process or system. Microcontrollers are typically used as embedded
controllers where they control part of a larger system such as an appliance, automobile, scientific
instrument or a computer peripheral.
Microcontrollers are designed to be low cost solutions; therefore using them can drastically
reduce part and design costs for the project. Physically, a microcontroller is an integrated circuit
with pins along each side. The pins presented by a microcontroller are used for power, ground,
oscillator, I/O ports, interrupt request signals, reset and control.

7
You can find microcontrollers in all kinds of things these days. Any device that measures, stores,
controls, calculates, or displays information is a candidate for putting a microcontroller inside.
There are a variety of microcontrollers depending on the different architectures and the
manufacturers such as PIC, ATMEL and MOTOROLA to mention a few. This write-up however
will be concentrating on the PIC microcontrollers.

PIC stands for peripheral interface controller, it is made by Microchip Technology, and its
architecture is based on the reduced instruction set computers (RISC). It has a wide range of
microcontrollers broadly divided into the low end, mid-range and the high end microcontrollers.
Table 2.1 shows the various classes of PIC microcontrollers highlighting their key features.

MCU PINS DATA
WORD
(BITS)
PROGRAM
MEMORY
(BYTES)
TYPICAL
INSTRUCTIONS
SET
SPEED
MIPS
DESCRIPTION
10FXXX =6 8 <=512 33 X 12 BITS <=2 Low pin count, small
Form factor, cheap, no
EEPROM, no low power,
Assembler program
12FXXX =8 8 <=2KB 12/14 BITS <=0.5 Low pin count, small form
Factor, cheap, EEPROM,
10-bit ADC, some low
Power,assembler
16FXXX <=64 8 <=14KB 35 X 14 BITS <=5 Mid-range,UART,I2C,
SPI,MANY LOW POWER, C OR
ASSEMBLER PROGRAM
18FXXX <=100 8 <=128KB 75 X 16 BITS <=16 HIGH RANGE, CAN, USB
J SERIES 3V SUPPLY, C
PROGRAM
24FXXX <=100 16 <=128KB 76 X 24 BITS <=16 POWER RANGE,3V SUPPLY,
NO EEPROM, DATA RAM <=
8KB, C PROGRAM



TABLE 2.1 CLASSES OF PIC Microcontrollers
Source: Programming and Customizing PIC micro Microcontrollers

8
2.1.1 PIC 18F2550
The 18F2550 is a member of the PIC18 family; it has an operation range of between 4.2 to 5V. It
has an enhanced flash program memory, meaning it can be reprogrammed about 100,000times
successfully and has a retention capability of 40years. It is economical in price and size. It has 28
pins, offers an ADC of 10bits, it also a program memory up to 32kbytes and a RAM of 2kbytes.
It is designed with a USB module, it has four timers and a total of 19 interrupt sources. It
operates with 75 standard instruction set also extendible to 83 if enabled. An internal oscillator
block that provides an 8MHz clock is available.

Lastly, the 18F2550 can run in several modes, one of which is the idle mode where the CPU core
is turned off and only the peripherals are still active this reduces power consumption to about 4%
of normal consumption.



FIG 2.1 PIC 18F2550 PIN SUMMARY
Source: PIC18F2550 Datasheet

9
2.1.2 Pin description
a) Port A
PORTA is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISA.
Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input. Clearing a TRISA
bit (= 0) will make the corresponding PORTA pin an output. The RA4 pin is multiplexed with
the Timer0 module clock input to become the RA4/T0CKI pin. The RA6 pin is multiplexed with
the main oscillator pin; RA4 is also multiplexed with the USB module; it serves as a receiver
input from an external USB transceiver. Several PORTA pins are multiplexed with analog
inputs, the analog VREF+ and VREF- inputs and the comparator voltage reference output. The
operation of pins RA3:RA0 and RA5 as A/D converter inputs are selected by clearing/setting the
control bits in the ADCON1 register (A/D Control Register 1).

b) Port B
PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB.
Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input. Clearing a TRISB
bit (= 0) will make the corresponding PORTB pin an output.

c) Port C
PORTC is a 7-bit wide, bidirectional port. The corresponding data direction register is TRISC.
Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input. Clearing a TRISC
bit (= 0) will make the corresponding PORTC pin an output In PIC18F2550 the RC3 pin is not
implemented. PORTC is primarily multiplexed with serial communications modules, including
the EUSART, MSSP module and the USB module. Except for RC4 and RC5, PORTC uses

10
Schmitt Trigger input buffers. Pins RC4 and RC5 are multiplexed with the USB module.
Depending on the configuration of the module, they can serve as the differential data lines for the
on chip USB transceiver, or the data inputs from an external USB transceiver. Both RC4 and
RC5 have TTL input buffers instead of the Schmitt Trigger buffers on the other pins. Unlike
other PORTC pins, RC4 and RC5 do not have TRISC bits associated with them. As digital ports,
they can only function as digital inputs.

d) Port E
PORTE is a 4-bit wide port. Three pins (RE0/AN5/CK1SPP, RE1/AN6/CK2SPP and
RE2/AN7/OESPP) are individually configurable as inputs or outputs. These pins have Schmitt
Trigger input buffers. When selected as an analog input, these pins will read as 0s.
The corresponding data direction register is TRISE. Setting a TRISE bit (= 1) will make the
corresponding PORTE pin an input. Clearing a TRISE bit (= 0) will make the corresponding
PORTE pin an output. The fourth pin of PORTE (MCLR/VPP/RE3) is an input only pin. Its
operation is controlled by the MCLRE configuration bit. When selected as a port pin (MCLRE =
0), it functions as a digital input only pin; as such, it does not have TRIS or LAT bits associated
with its operation.

e) VDD
Supply voltage

f) VSS
Ground

11
g) MCLR
The MCLR pin provides a method for triggering an external Reset of the device. A Reset is
generated by holding the pin low. These devices have a noise filter in the MCLR Reset path
which detects and ignores small pulses.

h) OSC1 and OSC2
These are the input when an external crystal or ceramic oscillator is used.

i) VUSB
Supplies the internal transceiver power when its connected. It has a voltage regulator that limits
supply to 3.3V

2.1.3 Additional Features of PIC18F2550
DC to 40MHz operation
8x8 hardware multiplier
Interrupt priority levels
16-bit-wide instructions, 8-bit-wide data path
High current (25mA) sink/source capability
Two capture/compare/PWM modules
Master synchronous serial port module (SPI and I2C modes)
Parallel slave port (PSP)
Programmable low-voltage detection (LVD) module
Power-on reset (POR), power-up timer (PWRT), and oscillator start-up timer (OST)

12
Watchdog timer (WDT) with on-chip RC oscillator
Direct CAN 2.0 bus interface
Direct USB 2.0 bus interface
Direct LCD control interface
TCP/IP interface
ZigBee interface
Direct motor control interface
The MCU is powered by an oscillator to provide the required clocking signal to drive it. The
MCU has an internal oscillator but this is limited in the speed it can provide. External oscillators
are more commonly used. The oscillator that was used in this project is a quartz crystal oscillator
because of its stability; as it operates at constant frequency as the load is varied over a period of
time. It is connected to the MCU through and interfacing circuit consisting of two ceramic
capacitors connected in parallel to the crystal oscillator. The ceramic capacitors are used because
they do not have polarity.

AS SENSOR




FIG 2.2 CRYSTAL OSCILLATOR FIG 2.3 CONNECTION OF A CRYSTAL OSCILLATOR
Source: www.electronics-
tutorial.ws
Source: www.electronics-tutorial.ws

13
2.2 Gas sensor
A gas sensor is an electronic device that detects an increase in the concentration of a gas in the
surrounding environment and gives out a signal to warn occupants before it reaches a harmful
level. Gas sensors do not work in isolation; they are usually combined with other components to
give out an alarm to warn occupants once the gas is detected. A gas sensor is basically a
transducer, so whenever a gas is sensed there is a voltage change, this change is passed to a
system that will interpret the signal and give out appropriate output

There are various techniques of gas detection, depending on the underlying technology used to
detect the gas. A few of which are:
i) Catalytic sensors
ii) Semiconductor sensors
iii) Thermal conductivity
iv) Point infrared gas detectors
v) Open path infrared detectors
vi) Electrochemical sensors
vii) Chemcassette
viii) Ultrasonic gas detectors

But regardless of the underlying technology, the gas sensor should be located close to any point
of possible leakage. The reason for this is so the gas sensor will work efficiently and as soon as
there is a leakage it will be detected.
The name of gas sensor that is used to carry out this project is the MQ-6 gas sensor.

14
2.2.1 MQ-6
The MQ-6 is an electro catalytic gas sensor. It consists of a very small sensing element
sometimes called a bead, it are made of an electrically heated platinum wire coil, covered first
with a ceramic base such as alumina and then with a final outer coating of rhodium catalyst
dispersed in a substrate of thoria.








i.) Principle of operation
The MQ-6 gas sensor operates on the principle that when a combustible gas/air mixture passes
over the hot catalyst surface, combustion occurs and the heat evolved increases the temperature
of the bead. This in turn alters the resistance of the platinum coil and can be measured by using
the coil as a temperature thermometer in a standard electrical bridge circuit. The resistance
change is then directly related to the gas concentration in the surrounding atmosphere and can be
displayed on a meter or some similar indicating device.



FIG 2.4 MQ-6
Source: www.netab.fi

15
ii.) Features of MQ-6
Power supply is 5V AC or DC
Long work period stability
High sensitivity to isobutene, propane, alcohol, hydrogen
Fast detection time between 20 to 30 seconds
Wide detection scope

iii.) Applications
They are used in gas leakage detecting equipment in family and industry, are suitable for
detecting of LPG, natural gas, town gas, avoid the noise of alcohol and cooking fumes and
cigarette smoke.

2.3 Liquid crystal display
Liquid Crystal Display is an electronic display module that is used for communicating messages
by displaying them on its screen. It consists of liquid crystals (rod-shaped like molecules that
flow like a liquid and bend light like a crystal) sandwiched between polarizing filters and glass
panels. When an electric current is passed through the liquid the crystals are energized causing
them to align so that light cannot pass through them.

16



A 16x2 LCD display is very basic module and is very commonly used in various devices and
circuits to display messages. These modules are preferred over seven segments and other multi
segment LEDs because LCDs are economical; easily programmable; have no limitation of
displaying special & even custom characters (unlike in seven segments) and animations.
FIG 2.5 PRINCIPLE OF OPERATION OF A LIQUID CRYSTAL DISPLAY
Source: computer.yourdictionary.com

17


A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD
each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command
and Data.

The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the
cursor position, controlling display etc. The data register stores the data to be displayed on the
LCD. The data is the ASCII value of the character to be displayed on the LCD.

The LCD can be connected in two modes, either in 8pin or 4pins data mode. The 4 data pin
connection is more commonly used because the LCD is fully controllable in this mode and it
maximizes the pins of the microcontroller.
FIG 2.6 PIN CONFIGURATION OF A 16 x 2 LCD
Source: www.enginnersgarage.com

18
PIN NO FUNCTION NAME
1 Ground (0V) Ground
2 Supply Voltage; 5V (4.7 5.3V) V
CC

3 Contrast adjustment; through a variable resistor V
EE

4 Selects command register when low; and data register when high Register select
5 Low to write to the register; High to read from the register Read/Write
6 Sends data to data pins when a high to low pulse is given Enable
7


8-bit data pins
DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight V
CC
(5V) Led +
16 Backlight Ground (0V) Led -
www.newnespress.com

2.4 Light emitting diode
A Light-Emitting Diode (LED) in essence is a P-N junction solid-state semiconductor diode that
emits light when a current is applied though the device. A typical LED consists of two terminals
that are connected to a power source. The positive terminal on the power source is connected to
one side of the LED semiconductor through the anode and a whisker and the other side of the
semiconductor is attached to the top of the anvil or the negative power lead (cathode). It is the
chemical composition or makeup of the LED semiconductor that determines the color of the light
that the LED produces as well as the intensity level. The epoxy resin enclosure allows most of
the light to escape from the elements and protects the LED making it virtually indestructible.
Furthermore, a light-emitting diode does not have any moving parts, which makes the device
extremely resistant to damage due to vibration and shocks. These characteristics make it ideal for
TABLE 2.2 PIN DESCRIPTION OF THE LCD
Source: www.engineersgarage.com

19
purposes that demand reliability and strength. LEDs therefore can be deemed invulnerable to
catastrophic failure when operated within design
LEDs are highly monochromatic, only emitting a single pure color in a narrow frequency
range. The color emitted from an LED is identified by peak wavelength (lpk) which is
measured in nanometers (nm). The peak wavelength is a function of the material that is
used in the manufacturing of the semiconductor. Most LEDs are produced using gallium-
based crystals that differ in one or more additional materials such as phosphorous to
produce distinct colors. Different LED chip technologies enable manufacturers to
produce LEDs that emit light in a specific region of the visible light spectrum and
replicate different intensity levels (D. K. Seling, 2002, Pg. 2).




2.4.1 Principle of operation
The essential portion of the Light Emitting Diode is the semiconductor chip.
FIG 2.7 LIGHT EMITTING DIODE
Source: en.wikipedia.org

20
Semiconductors can be either intrinsic or extrinsic. Intrinsic semiconductors are those in which
the electrical behavior is based on the electronic structure inherent to the pure material. When the
electrical characteristics are dictated by impurity atoms, the semiconductor is said to be extrinsic.
This chip is further divided into two parts or regions which are separated by a boundary called a
junction. The p-region is dominated by positive electric charges (holes) and the n-region is
dominated by negative electric charges (electrons). The junction serves as a barrier to the flow of
the electrons between the p and the n-regions. This is somewhat similar to the role of the band-
gap because it determines how much voltage is needed to be applied to the semiconductor chip
before the current can flow and the electrons pass the junction into the p-region



In general, to achieve higher momentum states (with higher velocities), there must be an empty
energy state into which the electron may be excited. Band-gaps determine how much energy is
needed for the electron to jump from the valence band to the conduction band. As an electron in
the conduction band recombines with a hole in the valence band, the electron makes a transition
to a lower-lying energy state and releases energy in an amount equal to the band-gap energy.
FIG 2.8 PRINCIPLE OF OPERATION OF LEDS
Source: Light emitting Diodes, D. K. Seling

21
This energy is released in photons. Normally the energy heats the material. In an LED this
energy goes into emitted infrared or visible light.

2.4.2 Applications
LEDs are used for both general and special-purpose lighting. They find their applications in
floodlights, railway signals, traffic lights, domestic lights, billboard display etc. The reason why
LED was chosen for this project is because they offer high energy efficiency and they have long
life spans. White LEDs ordinarily need 3.6 Volts of Direct Current (DC) and use approximately
30 milliamps (mA) of current and has a power dissipation of approximately 100 milliwatts
(mW).

2.5 Buzzer
Buzzer or beeper is an audio signaling device. It is an electronic device that makes a buzzing
sound when activated. There are different types of buzzers depending on the type of technology
employed in the design; we have the mechanical, electromechanical and piezoelectric types of
buzzers (Wikipedia, 2001, Buzzers). The type of buzzer that will be used in this project is an
electromechanical buzzer. The buzzers draw a considerable amount of current so when used with
the microcontroller they will be interfaced with the microcontroller with a transistor. When the
output from the pin of the microcontroller is pin high the buzzer will sound and when the output
is low the buzzer will remain silent.

22



2.6 Power supply
Power supply is very essential in the design of any electronic circuit. Practically, most electronic
systems require a dc source for their operation. The simplest forms being dry cells and batteries
which have the advantage of being portable and ripple free, however their voltages are low, they
need frequent replacement and are expensive when compared to conventional dc power supplies.
Since the most convenient and economical source of power is the domestic ac supply, it can be
highly advantageous to convert this alternating voltage to DC voltage. In summary, rectification
is the process employed to convert ac voltage into dc voltage and is accomplished with the help
of a rectifier and filtering circuit.

In an unregulated power supply, dc terminal voltage I affected significantly by the amount of
load and the AC supply voltage, such that the dc terminal voltage becomes less as the load draws
more current. An AC powered unregulated supply usually uses transformer to convert the
voltage from the mains to a different voltage that will be best for the application. If it used to
produce DC, a rectifier is used to convert alternating voltage to a pulsating direct voltage,
FIG 2.9 BUZZER FIG 2.10 INTERFACING CIRCUIT OF A BUZZER
Source: Interfacing with microcontrollers

23
followed by a filter, comprising one or more capacitors, resistors, and sometimes inductors, to
filter out (smooth) most of the pulsation.

2.6.1 Regulated power supply
A regulated power supply is one that controls the output voltage or current to a specific value;
the controlled value is held nearly constant despite variations in either load current or the voltage
supplied by power supply's energy source. An unregulated power supply can be converted into a
regulated power supply by adding a voltage regulating circuit to it. The regulator also greatly
reduces the ripple and noise in the output direct current. Linear regulators often provide current
limiting, protecting the power supply and attached circuit from overcurrent. A voltage divider is
used if the loads to be powered require different voltages and it is optional.

2.6.2 Transformer
Transformers transfers AC power from point to another with little losses. Transformers work
only with AC and this is one of the reasons why the mains supply is AC. Its function is to step
down or step up the ac supply voltage to suit the requirement. It also provides isolation from the
supply line. However, for the purpose of this project, the step-down transformer is used to reduce
the dangerously high mains voltage to a safer low voltage. The input coil is called the primary
and output coil is called the secondary. There is no electrical connection between the two coils;
instead they are linked by an alternating magnetic field created in the soft-iron core of the
transformer. Transformers perform at very high efficiencies limiting losses to the minimum so
that the power out is (almost) equal to the power in. It is also important to note that as voltage is
stepped down current is stepped up. The ratio of the number of turns on each coil, called turns

24
ratio, determines the ratio of the voltages. A step-down transformer has a large number of turns
on its primary (input) coil which is connected to the high voltage mains supply, and a small
number of turns on its secondary (output) coil to give a low output voltage.

2.6.3 Full wave rectifier
Among the several ways of connecting diodes to make a rectifier to convert AC to DC, the
bridge rectifier is the most important because it uses all the AC wave (both positive and negative
sections), thereby producing full-wave varying DC. A full rectification is achieved when four
diodes are arranged as shown in the Fig 2.11 usually called a diode bridge or bridge rectifier
It should be noted that 2.4V is used up in the bridge rectifier because each diode uses 0.6V when
conducting and there are always the diodes conducting (i.e. alternated pairs) changing over the
connections so that the alternating directions of AC are converted to one direction of DC.


FIG 2.11 BRIDGE RECTIFIER
FIG 2.12 WAVEFORM OF A BRIDGE RECTIFIER
Source: en.wikipedia.org
Source: www.electronics-tutorials.ws

25
2.6.4 Filter circuit
The filter circuit is the circuit element that removes the pulsations (ripples) present in the output
voltage supplied by the rectifier. The pulsations in the dc voltage form the rectifier is
significantly reduced by adding a filter between the rectifier and the load. The filter smoothings
the pulsations to give a dc load voltage with minimal fluctuation. Smoothing is performed by a
large value electrolytic capacitor connected across the DC supply to act as a reservoir, supplying
current to the output when the varying DC voltage from the rectifier is falling. The capacitor
charges quickly near the peak of the varying DC, and then discharges as it supplies current to the
output from no-load to full-load voltage. The aim of a voltage regulator circuit is to reduce these
variations to zero or at least to the minimum possible value. In an ideal or perfectly regulated dc
power supply, the percentage voltage regulation is zero. For critical electronics applications a
linear regulator may be used to set the voltage to precise values stabilized against fluctuations in
input voltage and load. The regulator also greatly reduces the ripple and noise in the output direct
current. Linear regulators often provide current limiting, protecting the power supply and
attached circuit from over current. They are rated by the maximum current they can pass. In this
project, the LM 7805 voltage regulator is used.






FIG 2.12 VOLTAGE REGULATOR SYMBOL
Source: www.ecawa.ans.au

26
Selecting the best regulator for an application
The best choice for a specific application can be determined by evaluating the requirements such
as:
Maximum load current
Type of input voltage source (battery or AC)
Output voltage precision (tolerance)
Quiescent (idling) Current
Special features (Shutdown Pin, Error Flag, etc.)
















27
CHAPTER THREE
METHODOLOGY
The design of a gas leakage detector is centered on interpreting the output from a gas sensor and
using the output to trigger an alarm and similar devices. A gas sensor basically is a transducer
which senses a gas and outputs a change in potential difference. The level of voltage is directly
proportional to the volume of gas detected in the surrounding. The voltage generated as output
by the gas sensor is fed to the microcontroller as input, the microcontroller then samples the
voltage at regular intervals using its inbuilt analogue-to-digital converter so that any variation in
the voltage levels can be immediately detected.
A threshold is set for the level of gas at the desired PPM (parts per million) at which the alarm
will be triggered. On the detection of the gas the microcontroller sends a signal (voltage) to the
appropriate pins to trigger the alarm, which consequently causes the led to flash intermittently
with the buzzer sounding simultaneously. The alarm will remain in the same ON state until the
gas is restored back to safe operating levels which will cause the alarm to switch OFF
automatically. The circuit also consists of an LCD which will show the status of the
microcontroller at all times to enable the unit to be monitored effectively. When a gas is
detected it indicates at the same time with the alarm unit with a message gas detected and once
the gas is removed it returns to the normal state indicating no gas. The circuit design is first
implemented using PROTEUS simulation software, the motive for this is to test the preliminary
designs and improve on it towards the final circuit. It also helps to predict with a certain degree
of accuracy how the circuit will perform in real life situations. The compiler used was the CCS
compiler and the microcontroller program was written in C. The program was then transferred to

28
the microcontroller using the MPLAB software with the programmer hardware to burn the code
into the microcontroller.





















MCU
PIC 18F2550
POWER SUPPLY
5.0V
GAS SENSOR
MQ-6
SENSING UNIT
CONTROL UNIT
ALARM UNIT
LED
BUZZER
LCD
POWER SUPPLY SIGNAL FLOW
FIG 3.1 A BLOCK DIAGRAM OF THE GAS DETECTION SYSTEM

29
The whole systems can be broken into four functional parts which work together to
achieve the overall goal. The four sections are:
i) the sensing unit
ii) the control unit
iii) the alarm unit
iv) the power supply
Figure 3.1 is a block diagram depicting the functional parts and how they interact.

3.1 Sensing unit
The sensing unit consists of the gas detector and its interfacing circuit. The gas detector used is
the MQ-6. It has six pins; four of the six pins are used for sensing while the remaining two are
used for electrical heating of the platinum wire coil in the sensor. The gas sensor requires 5V to
function (AC or DC); it is connected to the power supply of 5V directly. The gas detector is
interfaced to the microcontroller using a BC337 transistor and a 1K resistor, the transistor is an
NPN transistor. The purpose of the interfacing circuit is to provide the required voltage levels for
the signals coming from the MCU. The gas sensor is connected through the interfacing circuit to
PIN 2 of the MCU.

30


3.2 Control unit
The control unit consists of the microcontroller loaded with the program and the crystal
oscillator. The code is written In C language and is compiled using the CCS compiler. The
process of compiling and debugging is a continuous one and it is done until a successful build is
achieved. The program is then imported to PROTEUS to observe the performance of the code
and to get an idea of how it will function in real life situations. After the code has been tested
satisfactorily it is then burnt to the microcontroller using a device called a PROGRAMMER.
The programming phase is achieved in two phases
i) successful connection of the programmer to the PC
ii) the actual programming of the microcontroller
The microcontroller is placed on the programmer with the edge having a little semi-circle as the
leading edge, burning the program to the microcontroller placed incorrectly can cause damage to
the microcontroller. After the MCU has been well placed connection is then attempted from the
software interface. Once the connection is achieved successfully the software will automatically
FIG 3.2 THE CIRCUIT DIAGRAM OF THE GAS SENSOR
Source: Datasheet MQ-6

31
detect the microcontroller being used using the auto detect feature and the programming can
commence. The code being sent to the microcontroller is in HEX format; after the program has
been successfully burnt to the MCU it is disconnected and can then be placed in the real life
circuit.
The MCU is powered using an external oscillator. The oscillator commonly used is a crystal
oscillator. The oscillator is connected to the points labeled on as OSC1 and OSC2 on the data
sheet of the MCU; it is interfaced to the MCU with two capacitors connected in parallel to
provide the MCU with the required clocking. The crystal oscillator used is an 8 MHz crystal
oscillator and it is coupled using two 22pf capacitors. The MCLR from the microcontroller is
connected to a push button that resets the circuit once the logic state goes low. The MCLR is
held in high permanently and if the push button is pressed the program currently running is
interrupted and execution of the programs restarts from the beginning.
The flow and logic of the program is shown in the flowchart in FIG 3.3.








32


















START
ARRANGE THE CIRCUIT AS
IN THE BLOCK DIAGRAM
POWER UP
INITIALIZE LCD
WAIT FOR
INTERRUPTS
MICROCONTROLLER SEND
SIGNAL TO ALARM UNIT
LEAKAGE
RESOLVED
NO
YES
YES
NO
STOP
FIG3.3 THE FLOWCHART OF THE DETECTION SYSTEM

33
3.3 Alarm unit
An alarm is a signal warning of an imminent danger. The purpose of the alarm is to warn the
residents as quickly as possible to the presence of a leakage so that appropriate measure can be
taken to prevent loss of life and property.
The alarm unit consists of three component parts, namely:
i) the light emitting diode
ii) the buzzer
iii) the liquid crystal display
3.3.1 Light emitting diode
There are two LEDs in the full circuit. The first one is a green LED that switches on once the
circuit is powered on. The function is to show that the entire system is being actively supplied
power and is functional. This LED switches off once the system power is cut off or switched off.
The second LED is a tri-colour LED; it is a tri-colour led which consists of red and green led
connected in one package with three leads. It has the ability to display green, red or both green
and red together which will give a yellowish display. This LED is to show the state of the gas
sensor. During normal operation of the gas leakage detector, the LED displays green, indicating
that everything is normal. When a gas is detected however, the LED changes colour and displays
red instead, indicating danger.
The LED is connected to two pins on the MCU (PIN 4 and PIN 5) and the last PIN to ground.


34
3.3.2 Buzzer
The buzzer is an electronic device that gives off audio signals when activated. The buzzer gives
off only one type of sound unlike the piezoelectric sounder. The buzzer is interfaced to the MCU
through a transistor in order to drive it effectively because it has a higher voltage requirement
than the MCU pin can supply. The buzzer is connected to PIN 3 of the MCU, so when a gas is
detected the MCU sends the signal and activates the buzzer. The buzzer sounds until the gas
leakage is removed then it is restored to its normal state when it is silent.
3.3.3 Liquid crystal display
The LCD is to communicate a message to the occupants to let them know the status of the
system. Its first message is when the system is working normally and continually sampling the
input. It displays a message sensing to make the occupants aware that the system is working.
The second message is when a gas has been detected; it attempts to get the attention of the
occupants by printing a message on the screen gas detected, the message clears when the gas
leakage is removed. It is connected in the six pin mode, the pins are connected in this order the
first PIN representing the pins on the LCD and the next representing the respective connection
on the MCU. The connection was as follows:
a. LCD_DB4: PIN_B0
b. LCD_DB5: PIN_B1
c. LCD_DB6: PIN_B2
d. LCD_DB7: PIN_B3
e. LCD_E:PIN_C0
f. LCD_RS:PIN_C1

35
3.4 Power supply
The function of the power supply is to provide the power that will drive the whole system. The
power supply is in three stages; the rectification stage, the filtering stage and the voltage
regulation stage. The rectification stage is made up of a bridge rectifier which converts the AC
supply to DC, the bridge rectifier used is 2W005G and it allows an average forward current of
2.0A. Each diode chops off 0.6V each so collectively the bridge rectifier chops off 2.4V. The
filtering stage consists of 220F capacitor its job is to smoothing the pulsating DC coming from
the bridge rectifier and finally the voltage regulation consists of a voltage regulator LM7805.
The rating of the transformer used is 220/9, 500mA.


Each of the individual units are connected together to form the whole gas detection system. The
complete circuit can be viewed in FIG 3.9.


FIG 3.4 THE POWER SUPPLY CIRCUIT

36
3.5 Design of the PCB
After the circuit was designed on PROTEUS and successful tested the next step was to
implement a physical design. The physical design of the circuit was to be done with a
printed circuit board (PCB) design software that comes alongside PROTEUS called ARES.
The reason for using a PCB is because of the advantages of neat and compact designs.
The design of the PCB can be broken into three phases:
i) Design of the board
ii) Placing of the components
iii) Routing

3.5.1 Design of the PCB
The size of the PCB board has to be designed that it will accommodate all the components
securely. The component should not be too choked together and at the same time should not be
too far apart. The dimension of the board was 6.6cm x 11.7cm; it was drawn in the ARES work
environment. The board is a single layer PCB so the outline was first drawn with the board
edge option. The dimensions are then placed in the design using the dimensioning tool box; this
is done for clarity and is not compulsory.

3.5.2 Placing of the components
This involves the arrangement of the components in the best possible way so that they can be
connected with not so much effort. The components are imported from PROTEUS to the ARES

37
environment. The Auto Placer is a tool used to place the components on the board so they will sit
comfortably. From the auto placer menu all the components are selected and they are placed on
the board, this completes the component placing phase.


3.5.3 Routing
Routing involves selection of the best path for the all the wire connections to be made so there is
no obstruction to any of the individual paths. The design rule manager tool is first selected,
from the display menu the net classes option selected. Under the net classes sub-menu the
routing technique is chosen for power and the signals. For the power routing option the trace
style and neck style are both left on default mode. The layer assignment is changed to bottom
copper for both the horizontal and vertical pair. For the signal routing option the trace and neck
style are also left in the default mode. The layer assignment for both the horizontal and vertical
FIG 3.5 AUTO PLACER MENU

38
pair is changed to bottom copper respectively. Finally, the auto-router tool is chosen and it
calculates the best path for routing and it adopts it.


FIG 3.6 THE LAYER ASSIGNMENT SELECTION FOR AUTOROUTING

39



After completion of the three phases the PCB design was completed and ready to be etched to a
real board.
FIG 3.7 THE ROUTING MAIN MENU
FIG 3.8 THE COMPLETE DESIGN OF THE PCB

40



FIG 3.9 THE COMPLETE CIRCUIT DIAGRAM OF THE GAS DETECTION SYSTEM

41

CHAPTER FOUR
CONSTRUCTION AND TESTING
This chapter aims at discussing the results of obtained from testing of the design and the practical
steps taken in to successfully completion of the project.

4.1 Layout Drawing
The circuit diagram drawn in the PROTEUS environment is printed on paper to act as a
guideline for the connection of the circuit on breadboard. The circuit from ARES showing the
PCB layout is printed unto a glossy paper. The reason for the glossy paper is for effective
transfer of the PCB layout unto the copper sheet because the copper sheet is going to be ironed
unto the copper sheet, so for it to be properly imprinted unto the copper sheet glossy paper is
used.
4.2 Bread Boarding
A breadboard is a construction base for prototyping of electronics. It provides a temporary means
to build and test circuits quickly before finalizing the design. The circuit is arranged on the
breadboard using Fig 3.8 as a connection guide; jumper wires are used to connect the various
sections of the entire system together. The breadboard is used to observe properties of the circuit
that were not apparent using the simulation model and to correct any hidden errors. Simulation
model produces results assuming everything is ideal and not taking into consideration
environmental factors like heating and the materials used. The circuit was then tested

42
accordingly using liquefied petroleum gas (LPG) and the circuit produced desirable results
detecting the gas when it was intentionally leaked.


4.3 Circuit Fabrication
The circuit fabrication can be divided into two stages:
i) The fabrication of the PCB
ii) Assembly of the circuit.
Picture 4.1 The breadboard arrangement of the gas leakage detector

43
4.3.1 The Fabrication of the PCB
The PCB was etched unto the copper sheet using hydrogen chloride and hydrogen peroxide. The
first step was to clean the PCB using a piece of fine sand paper, the sandpaper used was the type
that can be wetted and it was used while the sandpaper was wet. The next step was to wash using
soap and water, after which the copper sheet is dried. The final step of cleaning is to wipe down
both sides of the PCB using acetone.
After the board has been cleaned, the PCB model designed with ARES is printed out unto a
glossy photo paper and it is cut out carefully so the two edges can align of the PCB. A clothing-
iron set to its maximum temperature is used to preheat the board for about two minutes. The
glossy paper is then placed with the printed side facing the PCB board using the edges to align it
properly; the printed pattern will stick to the surface of the PCB like applying a sticker. The iron
is now taken a placed at the back of the photo paper and allowed to get hot. Once the pattern has
been successfully transferred it is run under water to help to remove the paper from the surface
without forcing it off. Now that the PCB pattern has been printed the next step is to etch out the
pattern.
The circuit is cut out into shape using a fine tooth hacksaw and a hole is filled in the PCB board
to hang the circuit by when the etching process is taking place. An aqueous mixture of hydrogen
peroxide (H
2
O
2
) and hydrochloric acid (HCL) is prepared to etch the pattern out. First enough
water is placed in a container to cover the board, next the acid is added to the water and next the
hydrogen peroxide. Once the acidic solution is formed the PCB is then attached to a string
through the previously drilled hole and placed in the solution for three to four minutes. The acid
eats off the copper from the board through the chemical reaction

44
2HCL + H
2
O
2
+ Cu + H
2
O CuCl
2
+ 3H
2
O
The board is then taken out of the solution after the reaction has been completed and then rinsed
thoroughly in water. The board is then dried off and that completes the PCB design stage.
4.3.2 Assembly of the circuit
After the board has been printed successfully, holes are drilled in it at points where the
component pins will sit and then placed in water for then board to cool down from the heat of
drilling. The board is then wiped clean and the components are places on the board and soldered
section by section.
4.4 Circuit Testing
The circuit is testing is divided into two parts:
i) Test for presence of gas
ii) Speed of response

4.4.1 Test for the presence of gas
The source of gas is a portable lighter used in the kitchen to light gas cookers manually. The gas
detector is connected to power and switched on and is given sometime to fully initialize. The
portable lighter is then switched on and the flame is blown off while the gas still is allowed to
diffuse close to the gas sensor. The presence of the gas triggers alarm, the led flashes and the
buzzer sounds simultaneously also the LCD prints a message which reads gas detected. The

45
gas detector has to be located close to the source of gas for it to be able to detect gas leakages
effectively. The gas detector detects the presence of LPG successfully.
4.4.2 Speed of response
The speed of response is how quickly the gas detector can detect the presence of a gas and give
off warning signals. The apparatus for this test where the gas detector itself, a stopwatch and a
portable lighter. The system is powered up and allowed to fully initialize, the gas is then released
using the portable lighter and the stopwatch is started. The stopwatch used was a digital
stopwatch on a mobile phone. The stopwatch is started from the moment the gas is released and
is stopped as soon as the gas has been successfully detected. The process is repeated three times
so the readings can be obtained. The reading obtained are represented in Table 4.1
S/N Speed of Response
(S)
Average Response Time
(S)
1 4 -
2 5 4.5
3 5 5

The original intention at the on-set of this project was to use a battery as the source of power but
this has to be changed to AC power because it was discovered that the particular sensor used was
drawing excessive current and running the battery down in the shortest time possible.


TABLE 4.1 THE SPEED OF RESPONSE OF THE GAS DETECTOR

46


Picture 4.2 The gas detector circuit during normal operation

47


4.5 System Casing
The system casing is comprised of a single plastic container that houses all the components. The
plastic housing has a vent to allow the gas diffuse through it to reach the gas sensor and for the
proper ventilation of the other components. The casing is rounded in shape, it also has a groove
drilled for the led so it can sit firmly and be visible from outside. Since AC is the power source
used a path is provided for the wire out of the casing to point where connection to the mains is to
be made. Plastic is used for the casing as it reduces the net weight of the system to the minimum.

Picture 4.3 The gas detector detecting gas

48



Picture 4.4 The complete system during normal operation
Picture 4.5 The gas leakage detector sensing gas

49
CHAPTER FIVE
CONCLUSION AND RECOMMENDATION
5.1 Conclusion
The gas leakage detector system designed has applied embedded systems to accurately detect a
gas leakage so the right steps can be taken to prevent any damage.
The design is compact and energy consumption is efficient. The installation of the system will
not require any technical know-how; all that will be required is to locate the detector at a
favourable position preferably close to the gas installation at room temperature.
Safety is of paramount importance when dealing with lives therefore wherever gas is to be used
for whatever purposes it should be installed along with a gas leakage detection system as a
standard, so it will act as a safety switch.
5.2 Recommendations
I recommend that:
A gas leakage detector should be used anywhere gas is being used to safeguard lives and
property.
A GSM module could be used to build upon this project so it can send a message to the
designated authority in case of a gas leakage.
The gas leakage detector can be used to control a valve, so it cuts-off supply once a gas leakage
is detected.


50
REFRENCES
1. Dogan Ibrahim, 2008, Advanced PIC Microcontroller Projects in C, Burlington:
Elsevier.
2. Martin P. Bates, 2006, Programming 8-bit Microcontrollers, USA: Newnes press.
3. Byte Craft Limited, 2002, First Steps with Embedded Systems, Ontario: Byte Craft
Limited.
4. Myke Predko, 2000, Programming and Customizing PICmicro Microcontrollers,
Toronto: McGraw-Hill.
5. Nigel Gardner, 2002, PICmicro MCU C, USA: Elsevier.
6. Duan Kelvin Seling, 2002, Light Emitting Diodes, San Jose State University,
California.
7. Jan Alexson, 1997, The Microcontroller Idea book, Winnebago: Lakeview Research.
8. Honeywell Analytics (2012), Gas Detection Principles.
//http:www.jjtech.com/gasmonitors/gasdetectionprinciple.html
9. Engineers garage (2011), LCD. //http:wwwengineersgarage.com/articles/LCD.html
10. Thomas Publishing Company (2012). How Gas Detectors Work.
//http:www.thomasnet.com/products/gas-detectors.html







51
APPENDIX
int i;
float sample, gasPPM;


void main()
{
setup_adc(ADC_CLOCK_INTERNAL); // ADC clock
setup_adc_ports(AN0); // Input combination

buzzer_on;
redLed_on;
delay_ms(1000);
buzzer_off;
biColourLed_off;

lcd_init();
delay_ms(500);
lcd_putc("\f ....................");
lcd_putc("\n Automatic Gas Sensor");
for(i = 0; i < 31;i++)
{
lcd_scroll_right();
delay_ms(200); // This sets the scroll speed
}

52
lcd_putc("\f Fagbamiye Segun --EEE/07/0409--");
lcd_putc("\n Dept. of Elect&Elect Engineering");
for(i=0; i<33; i++)
{
lcd_scroll_right();
delay_ms(200); // This sets the scroll speed
}

delay_ms(2000);
lcd_putc("\f"); //clears the lcd screen
delay_ms(500);

while(true)
{
set_adc_channel(0); // Select channel
delay_ms(100); // Wait
sample = read_adc(); // Get input
gasPPM =((sample)*0.0048828125f); // Scale input, 5/1024

if(gasPPM < 3.0)
{
lcd_putc("\f Gas dectector ");
lcd_putc("\nSensing: No Gas");
buzzer_off;
greenLed_on;

53
}
else if(gasPPM > 2.0)
{
lcd_putc("\f ATTENTION!!! ");
lcd_putc("\n**Gas Detected**");
buzzer_on;
redLed_on;
}
else{}
}
}

You might also like