Sunteți pe pagina 1din 66

Intelligent Fire Alarm

with
Bluetooth

By
Chew Hong Eng

Department of Information Technology and Electrical Engineering


University of Queensland

Submitted for the degree of


Bachelor of Engineering (Honours)
in the division of
Electrical Engineering

October 2001
St John“s College
College Road
St Lucia
QLD 4067
Tel(07) 3842 6645

October 19,2001

The Dean
Faculty of Engineering,
Physical Sciences and Architecture
The University of Queensland
St Lucia, QLD 4072

Dear Professor Lister,

In accordance with the requirements of the degree of Bachelor of Engineering (Honours)


in the division of Electrical Engineering, I present the following thesis entitled
” Intelligent Fire Alarm with Bluetooth„. This work was performed under the supervision
of Dr Adam Postula.

I declare that the work submitted in this thesis is my own, except as acknowledged in the
text and footnotes, and has not been previously submitted for a degree at the University
of Queensland or any other institution.

Yours Sincerely

Chew Hong Eng


Intelligent Fire Alarm with Bluetooth

Abstract

The Bluetooth technology has created a notion for Personal Area Network. The thesis
implements a Fire Alarm System using Bluetooth communication. The close range
wireless technology offers the advantage to operate within a distance of 10m without
having to depend on line of sight. It allows the communication to take place even with
obstacles in between. This offers the flexibility to mount the product anywhere and the
convenience to relocate it. Hence, the system offers many advantages over the traditional
hardwired system

The product consists of a Fire Alarm Unit (FAU) that performs the function of a sensor
and a PC that monitors the status of the FAU. Once the PC and FAU are setup, the FAU
is ready to send data upon request from the PC. The PC can request for data as and when
it requires. The FAU displays the temperature and alarm message on a LCD. In addition,
the design incorporates the feature that allows a logic sensor such as a smoke detector to
be implemented. The product is designed to be low cost and operates with low power
consumption allowing it to be powered using battery.

The system can be developed into a Home Security System. The Bluetooth technology
offers the convenience for the implementation of a Personal Area Network. The PC can
serve as a master control panel and make use of the data received to perform certain tasks
such as activating an alarm, dialing a number, paging, etc.

The thesis report provides an introductory background on the Bluetooth technology and
an introduction on the thesis objective and the products available in the market. It further
elaborates the design and implementation of the product. It reports the result of the
product evaluation and makes recommendation for improvement. Finally, it concludes
the thesis.
Intelligent Fire Alarm with Bluetooth

Acknowlegements

This thesis would not be successful without the help of the help of many people. I would
like take this opportunity to thank the following people:

Dr Adam Postula, for his guidance.

Naveenan, a student working on another Bluetooth thesis, for providing the support with
his HCI PC code.

Mr Keith Bell and all the other people in the Electronic workshop, for helping me in my
hardware.

Mr Len Payne, for his help in the thesis lab.


Intelligent Fire Alarm with Bluetooth

Table of Content
Pg
1. Introduction 1

2. Technology Background 2
2.1 The Bluetooth Technology
2.1.1 Master and Slave 2
2.1.2 Bluetooth Hierarchy
2.1.2.1 Radio Interface 3
2.1.2.2 Baseband 4
2.1.2.3 Link Manager
2.1.2.4 Host Controller Interface 5
2.1.2.5 Logical Link Control and Application Protocol 5
2.1.2.6 RFCOMM 5
2.1.2.7 Service Discovery 6
2.1.2.8 HCI Driver 6
2.1.2.9 Stack Connection Manager 6
2.1.2.10 Application Peripheral Interface 6

3. Product and Technology in the Market 7


3.1 Application of Fire Detectors 7
3.2 Product available in the Market 8

4. System Design 12
4.2 Hardware Design 13
4.2.1 Microcontroller 13
4.2.2 Temperature Sensor 14
4.2.3 Smoke Detector Unit 17
4.2.3.1 Photodiode 18
4.2.4 LCD Display 19
4.3 Software Selection 20
4.4 The Bluetooth Communication Interface 20
4.4.1 Setting Up a Bluetooth Point-to-Point Connection 21
4.4.1.1 Standby 23
4.4.1.2 Inquiry 23
4.4.1.3 Inquiry Scan 23
4.4.1.4 Page 23
4.4.1.5 Page Scan 24
4.4.1.6 Connection ‘ Active 24
4.4.2 Host Setup via UART 24
4.4.2.1 Soft Reset 25
4.4.2.2 Buffer Information 25
4.4.2.3 Timers 26
4.4.2.4 Event Filters 26
4.4.2.5 Bluetooth Address 26
4.4.2.6 Page Scan Mode 26
Intelligent Fire Alarm with Bluetooth

4.4.3 Data and parameter formats 26


4.3.3.1 HCI Command Packet 26
4.3.3.2 HCI Event Packet 27
4.3.3.3 HCI Data Packet 28

5. Implementation 29
5.1 Overview 29
5.1.1 Implementation of Sensors 30
5.1.1.1 Temperature Sensors 30
5.1.1.2 Smoke Detector 33
5.1.2 Implementation of Serial Communication on Microcontroller 35
5.1.2.1 High Error Rate in Communication 36
5.1.2.2 UART Interrupt Service Routine 36
5.1.2.3 Communication of Temperature Sensor with PC 36
5.1.3 Implementation of the HCI 39
5.1.3.1 HCI Master and Slave 39
5.1.3.2 Communication between Master and Slave 46

6. Product Evaluation 48
6.1 Product Description 48
6.2 Operation Procedure 48
6.3 Product Testing 49
6.3.1 Temperature Sensor 49
6.3.2 Connectivity 50
6.4 Power Consumption 51
6.5 Budget 52
6.6 Performance Evaluation 52

7. Recommendation 54

8. Personal Evaluation 55

9. Conclusion 56

10. Reference 57

Appendix A: STK200 Schematic 58

Appendix B: Programe ‘ C Code Listing 59


Intelligent Fire Alarm with Bluetooth
Intelligent Fire Alarm with Bluetooth

List of Figure
Pg
Fig 2.1 Piconet 3
Fig 2.2 Different Layers in the Bluetooth Hierarchy 4
Fig 2.3 HCI Architecture 5
Fig 3.1 Dongbang DIM2-02 Ionization Smoke Detector 10
Fig 3.2 Simplex 4020 Fire Alarm System 10
Fig 3.3 Simplex 4120/4100 Fire Alarm System 11
Fig 3.4 Dongbang D-Mux 300 Fire Alarm System 11
Fig 4.1 Block Diagram of Fire Alarm System 12
Fig 4.2 Block Diagram of the 1-Wire Bus Interface 16
Fig 4.3 Smoke Detector Unit 18
Fig 4.4 OPT101 Photodiode 19
Fig 4.5 Layout of BT Application Tool kit 20
Fig 4.6 BT Application Tool kit 20
Fig 4.7 Schematic of Bluetooth Application Tool kit with DB9 Connector 21
Fig 4.8 State Transition from Standby into Connection 22
Fig 5.1 Layout of the Fire Alarm Unit of the Slave 29
Fig 5.2 DS1820 Temperature Sensor 31
Fig 5.3 Reset Circuit for Smoke Detector 33
Fig 5.4 Output of Photodiode Inverted 33
Fig 5.5 Read and Check Sensors 34
Fig 5.6 Interrupt Service Routine for Mircrocontroller(Slave) 37
Fig 5.7 Interrupt Service Routine for PC(Master) 38
Fig 5.8 Main Flow Chart for Slave 40
Fig 5.9 Main Flow Chart for Master 41
Fig 5.10 Slave Initializing Connection 42
Fig 5.11 Master Initializing Connection 43
Fig 5.12 Communication between Master and Slave displayed on PC 47
Intelligent Fire Alarm with Bluetooth

List of Table
Pg
Table 3.1 Dongbang Smoke Detectors 9
Table 3.2 Dongbang Heat Detectors 9
Table 4.1 Microcontroller Specification 14
Table 4.2 Specification of Temperature Sensors 15
Table 4.3 1-Wire Protocol 17
Table 4.4 LCD Pin Function 19
Table 4.5 RS232 Settings 25
Table 4.6 HCI Packet Type 25
Table 4.7 HCI Command Packet 27
Table 4.8 HCI Event Packet 27
Table 4.9 HCI Data Packet 28
Table 5.1 LCD Pin Mapping 32
Table 5.2 Temperature Readings 33
Table 6.1 Result of the Temperature Test 50
Table 6.2 Connectivity Test 51
Table 6.3 Price of Major Components 52
Intelligent Fire Alarm with Bluetooth

1. Introduction

Home Security System is gaining its importance in many modern homes. With a personal
computer available in many households today, home security system has found its
application practical in Personal Area Network (PAN). PAN offers users the advantage to
personalize the network according to their needs instead of linking to public network.
Fire alarm system is becoming essential in any home security system. Users are no longer
satisfied with a simple fire alarm detector that just senses and sounds the alarm. Many
would like to have a security system that monitors and alert them in case of emergency
especially when they are away. Many products in the market are expensive, complicated
and require the system to be linked to a public emergency system. However, people are
looking for a low cost and simpler solution.

Traditional fire alarm systems are hardwired. Users find it cumbersome to handle wires
and many face the inconvenience in installation with wires. The user may want to mount
the fire detector and the control panel in a separate room. We need a product that is
wireless and allows the signal to penetrate walls. Low power consumption is essential in
any alarm system that is battery powered. Power consumption has to be kept low to
maintain battery life. Does today“s technology offer a good solution to all these
problems? Bluetooth offers the solution and the convenience to implement the system in
Personal Areas Network as well.

The objective of this thesis is to develop a Fire Alarm Unit that communicates with the
PC using Bluetooth technology. The idea is to build a Fire Alarm Unit that is capable of
performing the function of a fire alarm and make use of the PC as a master control panel
to monitor the alarm status.

1
Intelligent Fire Alarm with Bluetooth

2. Technology Background

2.1 The Bluetooth Technology


Bluetooth is a low power, short-range radio wireless technology. Recognizing the literal
jungle of connectivity options as an impediment to the ability to allow different gadgets
to interoperate was more likely one of the reasons for the development of Bluetooth. It is
designed to support communications at distances up to approximately 10m for devices
that operate using a limited amount of power. Its design for low power consumption
makes the technology well suited for use with small, portable devices that typically are
powered by battery. The Bluetooth technology has created a notion for Personal Area
Network, a kind of close range wireless network that look set to revolutionize the way
people interact with information technology around them. It allows PDAs to connect to
cell phones and cell phones to connect to notebooks, the potential use of Bluetooth is
only limited by one“s imagination. Printers, fax machines, keyboards, even toaster, as
well as home and office alarm systems, all eventually could be Bluetooth-compliant.

2.1.2 Master and Slave


Bluetooth operates in the unlicensed ISM band at 2.4GHz. As this frequency is not
reserved for Bluetooth, a frequency-hopping scheme with 79 sub-frequencies is used to
combat interference and fading. The frequency-hopping scheme also enables Bluetooth to
work not only in point-to-point connections but also in point to multi-point connections.
Each Bluetooth device may be a Master or a Slave at any one time, though not
simultaneously. Two or more units share the same channel forming a piconet, consisting
of one master an up to seven slaves. When more than one master is involved in piconet,
they form a scatternet. Fig 2.1 shows a piconet.

Every Bluetooth device has a unique Bluetooth device address, and a Bluetooth clock.
When Slaves connect to a Master, they are told of the Bluetooth address and clock of the
Master. The Master controls when devices are allowed to transmit.

2
Intelligent Fire Alarm with Bluetooth

Fig 2.1. Piconet

2.1.2 Bluetooth Hierarchy


Bluetooth is based on a stacked protocol model, where the communication is divided into
several layers. The lower layers consist of the Radio interface, Baseband and the Link
Manager and the Host Control Interface (HCI) and the audio. The higer layers are the
Bluetooth standardized part of the stack. These consist of the Logical Link Control and
Adaptation Protocol (L2CAP), serial port emulator (RFCOMM) and Service Discovery
Protocol (SDP). Besides these parts, there is a Stack Connection Manager (SCM) which
handles and administers the Bluetooth connection. Fig 2.2 shows the Bluetooth hierarchy.

2.1.2.1 Radio Interface


The Bluetooth module is a class 2 device with no power control. Norminal ranges of the
modules with antennas are up to 10m (at 0dB) which complies with the regulation in the
ISM band. Modulation technique is a binary Gaussian frequency shift keying. The
channel bandwidth is 1MHz. The Bluetooth specification gives minimum performance
parameters for the RF system. It is specified to operate with a maximum Bit Error Rate of
0.1%.

3
Intelligent Fire Alarm with Bluetooth

Fig 2.2 Different Layers in the Bluetooth Hierarchy

2.1.2.2 Baseband
The baseband is responsisble for channel coding and decoding and low level timing
control and management of the link within the domain of a single data packet transfer.
Bluetooth is a Time Division Multiplexed (TDM) system, where the basic operation is a
slot of 625us duration. Hopping frequency is determined by a pseudo-random hopping
sequence, which is unique for each piconet. During each transmission the frequency of
the sending device is fixed and a priority scheme is used where the Master uses the even
numbered timeslots and the receiving Slave the odd numbered timeslots.

4
Intelligent Fire Alarm with Bluetooth

2.2.2.3 Link Manager


The link manager in each Bluetooth module can communicate with another link manager
by using the Link Manager Protocol (LMP) which is a peer-to-peer protocol. The LMP
messages have the highest priority for link-setup, security, control and power saving
modes. The LMP messages are sent in the payload and need not to acknowledge due to
the reliable link provided by Baseband and radio.

2.2.2.4 Host Controller Interface (HCI)


The HCI-firmware implements HCI commands for the Bluetooth hardware by accessing
Baseband commands, Link manager commands, hardware status registers, control
registers and event registers. Fig 2.3 shows the HCI architecture.

Fig 2.3. HCI Architecture

2.2.2.5 Logical Link Control and Adaptation Protocol (L2CAP)


Provides connection-oriented and connectionless data service to upper layer protocols
with multiplexing capability, segmentation and reassemble operation. L2CAP permits
higher level protocols and applications to transmit and receive L2CAP data packets up to
64K bytes in length.

2.2.2.6 RFCOMM
RFCOMM is used as a transport protocol and emulation of the RS-232 serial port. It
supports up to 60 simultaneous connections between 2 Bluetooth devices and is able to
transmit and receive data up to 32K bytes.

5
Intelligent Fire Alarm with Bluetooth

2.2.2.7 Service Discovery Protocol (SDP)


SDP is a crucial part of the Bluetooth framework. It provides the means for applications
to discover which services are available and to determine the characteristic of those
services using an existing L2CAP connection. Thereafter, a connection can be established
using information obtained via SDP.

2.2.2.8 HCI Driver


The HCI driver establishes the communication between the stack and HCI firmware in
the hardware. HCI interface also ensure that the stack can run over a generic hardware. It
can be divided into a generic component and an environment dependent component.

2.2.2.9 Stack Connection Manger (SCM)


The SCM is one of the components in the Bluetooth stack which handles and
administrates the Bluetooth Baseband connection an the radio link. The SCM has to be
used for creating data and voice links. It also takes care of link keys that are generated
after pairing. SCM enables multiple applications on top of the Bluetooth stack to setup
independent data and voice links.

2.2.2.10 Application Peripheral Interface (API)


The interface to the stack is Ericsson propriety API, designed as environment
independent and flexible. It allows the establishment and tear down of data voice
connections, sending and receiving of data, as well as other Bluetooth functions such as
performing inquires and page function. Dynamically loading profile and adding own API
compliments suitable for the selected environment. One other important feature is the
ability to access the L2CAP layer directly in order to implement new protocols on top of
the L2CAP by the user.

6
Intelligent Fire Alarm with Bluetooth

3. Product and Technology in the Market

3.1 Application of Fire Detectors


Thermal detectors and smoke detectors are the sensors commonly used in fire alarm.
Some sensors are built with a combination of both types of detector. There are two types
of smoke detectors in common use. The ionization or radioactive type, and the
photoelectric type. The ionization type detector is more commonly found in Australian
homes and offices, primarily because it is cheaper and more readily available although
photoelectric detectors are probably more suitable for most homes. Thermal detectors are
more suitable than smoke detectors for bathrooms and kitchen areas. The major types of
sensors used in thermal detectors are infrared sensors, thermisters and bimetallic
elements. Thermisters are most commonly used as it is cheap and offers quick
temperature response.

Thermal detectors do not detect smoke or light, they are not recommended for living
areas of residence. They are used in attics, unheated garages and furnace rooms.

The ionization (radioactive) type detectors contain alpha-emitter, Americium. The alpha
particles ionize the air in a cavity, and when a voltage is applied across the cavity, a small
current is induced. When smoke particles enter this cavity, they absorb most of the alpha
particles, and also increase the resistance of the air. This causes the current to fall,
triggering the alarm.

The most commonly used photoelectric smoke detectors have a detection chamber with a
light source and a photoelectric cell. When smoke particles enter the chamber, the light is
obscured and the current from the photoelectric cell is reduced, triggering an alarm.

Photoelectric smoke detectors will only respond to visible smoke particles with a
diameter down to 0.3 microns. They are therefore less sensitive to flaming fires with little
visible smoke than the ionization type detectors, which can detect invisible combustion
particles with a diameter down to 0.01 microns.

7
Intelligent Fire Alarm with Bluetooth

Ionization type detector, while offering some extra protection in the case of certain kind
of fires, they are also prone to triggering nuisance alarms. In particular, if placed in or
near kitchen or living areas with gas heaters or fireplaces, they will react to the cooking
fumes and invisible combustion particles from the heaters, setting off the alarm.
Photoelectric detectors are therefore recommended for use in such areas, as well as small
home units and open plan houses.

3.2 Product available in the Market


Fire detector is available as standalone unit that is portable and battery powered. The
detector may be connected to a control panel. A simple control panel includes basic
features to display the alarm status and also allow the user to set the alarm conditions.
The display may be a LCD or LED indicator. A more sophisticated fire alarm system
usually make use of the PC as the control panel.

The communication link between the fire detector and the control panel can be
implemented using the following technology:
• Hardwired
• RF signal
• Infrared

Conventional fire detectors or fire alarm networks are hardwired to the control panel.
This technology is still by far the most common in fire alarm application as compared to
the wireless types. Table 3.1 and 3.2 are the description of some the fire detectors from
Dongbang Electronic Industrial. Fig 3.1 shows the DIM2-02 ionization smoke detector
from Dongbang.

8
Intelligent Fire Alarm with Bluetooth

Ionization Smoke Single Station Smoke Photoelectric Smoke


Description Detector Alarm (Ionization) Detector
Model No DIM2 Model No DAG1-01 Model No DPG2-03
Rated
Voltage DC 24V 9V DC battery DC 24V

Ambient
-10 to 50°C -10 to 50°C -10 to 50°C
Condition
up to 85%RH up to 85%RH up 85%RH
Temperature
Features Connect to any Connect to any control
control panel, solid ___ panel, solid state
state electric circuit, electric circuit, non-
non-polarity, two polarity, two wiring
wiring connection. connection.
Table 3.1. Dongbang Smoke Detectors

Temperature Heat Weather Proof Heat


Description Detector Detector
Model No DT06-01 Model No DTW6-A1
Rated
Voltage DC 24V
DC 24V
Ambient
-10 to 50°C -10 to 50°C
Condition
up to 85%RH up to 85%RH
Temperature
Features Connect to any Connect to any control
control panel, solid panel, solid state
state electric circuit, electric circuit, non-
non-polarity, two polarity, two wiring
wiring connection connection

Operating 60°C 60°C


Temperature It will ” anticipate„ a
fire condition by
responding to a lower
set point when the
ambient temperature is
rising rapidly.

Table 3.2 Dongbang Heat Detectors

9
Intelligent Fire Alarm with Bluetooth

Fig 3.1. Dongbang DIM2-02 Ionization Smoke Detector

Fire alarm system may be implemented with multiple sensors using addressable nodes as
shown in Fig 3.2. The system can include features that allow the alarm conditions to
addressed to the fire station as shown in Fig 3.3. Both systems are from Simplex Grinnel.
The fire system in Fig 3.4 from Dongbang has the control panel connected to a PC, the
PC is linked to an ⻦
emergency public addressed system“.

Fig 3.2. Simplex 4020 Fire Alarm System

10
Intelligent Fire Alarm with Bluetooth

Fig 3.3 Simplex 4120/4100 Fire Alarm System

Fig 3.4. Dongbang D-Mux 3000 Fire Alarm System

11
Intelligent Fire Alarm with Bluetooth

4. System Design

4.1 System Overview

Temp
Sensor
BT
Link Micro-
Controller
Smoke
PC BT BT Detector
Module Module

Master LCD
Display

Slave

Fig 4.1. Block Diagram of Fire Alarm System

Fig 4.1 shows the block diagram of the fire alarm system. It consists of 2 units; Master
and Slave. The heart of the Master is the PC (personal computer) and that of the Slave is
the microcontroller. The PC serves as the control panel for the fire alarm system. The
Master is the initiating device that sends out a request to the Slave whenever it requires
the data. Upon receiving the request, the sends out the temperature data and the alarm
status to the Master. The received information is processed at the PC. The PC of the
Master may be linked to a remote PC that performs the actual monitoring or it may be
connected to an auto-dialer that calls the owner. In the case of personal area network, the
fire alarm system may be part of the a home security system. Similarly, the data is used
to monitor the security system and perform certain tasks during emergency.

12
Intelligent Fire Alarm with Bluetooth

The microcontroller performs the routine of reading the temperature data from the
temperature sensor and smoke detector and displays the temperature reading and alarm
status on the LCD. The smoke detector triggers an alarm when the smoke intensity
exceeds the threshold. With the temperature reading displayed, the temperature sensor
serves an additional role of reporting the room temperature

The interface between the Master and the Slave is Bluetooth communication via the
Bluetooth module. The wireless technology has provided the flexibility to mount the
Slave unit anywhere within a distance of 10m. The communication is not affected by
walls or obstacles in between. The Bluetooth module in both the Master and Slave is
physically connected by serial cable to the PC and microcontroller respectively. The PC
communicates with the Bluetooth module via the RS232 serial port while the Slave uses
the UART. The Bluetooth module taps its power supply from the PC. The Slave unit is
designed to be portable, low in power consumption and supports battery operation.

The design ensures that the system is capable of performing its minimum role when a
system fault occurs. Unlike the temperature sensor, smoke detector is designed to be able
to work independently. In the event that the microcontroller or the PC fails, the smoke
detect still functions. This avoids putting the entire fire alarm system into complete
failure. Besides, if the owner decides not to have the smoke detector working as a stand-
alone unit, it can be detached from the Slave.

4.2 Hardware Design


Besides fulfilling the functionality, the other criteria for components selection are low
power consumption and low cost
.
4.2.1 Microcontroller
Table 4.1 shows the specification of the various microcontrollers that were considered
during the selection.

13
Intelligent Fire Alarm with Bluetooth

Microcontroller AT90S8515 AT91R4087 PIC12CE674 PIC16F876


Vcc (V) 2.7 to 6 1.8 to 3.6 2.5 to 5.5 2.0 to 5.5
RAM (byte) 512 136K 128 368
EEPROM data 512 ---- 16 256
memory
(byte)
ROM (byte) 8K x 16 ---- 2K x 14 EPROM 8K x 14 Flash
Flash
Serial I/O UART, SPI 2 USART SPI USART, MSSP
Bi-directional I/O pins Yes Yes Yes Yes
Power consumption 6.4mA @ 4.25mW/MH 2mA @ 5V, 0.6mA @ 3V,
3V, z
4MHz @3.3V 4MHz 4MHz
Table 4.1. Microcontroller Specification

The key selection criteria for the microcontroller are the power consumption, onboard
RAM and programmable ROM or flash memory, UART and the I/O pins. AT90S8515 is
selected due to its low power consumption and the large programmable memory size and
a relatively large RAM size. The flash memory is more than sufficient to accommodate
the code for the fire alarm application. At the point of selection, it was not certain how
large a RAM size is required for the Bluetooth host controller interface (HCI) code.
However, the RAM size of the controller can be extended. The UART is required for the
serial interface with the Bluetooth module. The bi-directional I/O pin is necessary for the
1-wire interface. Another good reason for selecting an Atmel controller is the availability
of the Atmel STK200 evaluation board from the thesis laboratory. The board offers the
convenience of onboard RAM extension using 2 chips; a 32K word RAM and an address
latch.

4.2.2 Temperature Sensor


Table 4.2 shows the specification of the various temperature sensors. The sensor selected
here is DS18S20, a high precision digital temperature sensor. Digital sensors can achieve
the precision that most analog sensors cannot. The DS1820 can achieve an accuracy of
+/-0.5 °C when operating between ‘10 to 85°C . This temperature range is more than
sufficient for fire alarm application. The threshold to trigger a fire alarm is usually set

14
Intelligent Fire Alarm with Bluetooth

between 50 to 60°C. High degree of accuracy is not a very critical requirement as far as
fire alarm application is concern. However, as the sensor can serve its secondary function
of displaying the room temperature, this will be an advantage. The sensor operates at low
voltage and low current consumption. The requires a 5V input will can be easily supplied
using four AA batteries or a 9V battery stepped down to 5V using a voltage regulator.

Sensor DS18S20 Max6577 LM20 DS1621 DS1620


Temp Range -10 to -40 to +125 -55 to +130 -55 to +125 -55 to +125
(°C) +125
Accuracy(°C) +/-0.5 +/- 0.5 typ +/- 2.5 to +/-0.5 +/-0.5
(-10 - 85 +/- 3.5 max +/-5 (0 - 70 °C) (0 - 70 °C)
°C)
Vcc (V) 3 to 5 2.7 to 5.5 2.4 to 5.5 2.7 to 5.5 2.7 to 5.5
Current (mA) 1.5 3.2 16u 1 1
Output Digital Square wave Analog Digital Digital
Interface 1-wire 1-wire 1-wire 2-wire 3-wire
Table 4.2. Specification of Temperature Sensors

Another important criteria is the interface between the microcontroller and the sensor.
There are several types of digital interface that permits communication with a
microcontroller. The interface is usually an I2C, SMBus serial bus, 1-wire, but other
serial interfaces such as SPI are common. One way to cut down on cost is to simplify the
hardware interface between the controller and the sensor. It can be reduced to zero
interface. This, when implemented with the 1-wire interface, makes it the simplest among
the interfaces mentioned above. The interface between DS18S20 and the microcontroller
is 1-wire. Communication is supported by an I/O pin from the controller that is connected
directly to the output pin of the sensor.

Fig 4.2 shows the block of the diagram of the interface between DS1820 and the
microcontroller. The DS1820 uses the 1-wire bus protocol that implements bus
communication using one control signal. The bus system uses single bus master to
control one or more slave devices. The DS1820 is always a slave. The control line
requires a weak pullup resistor since all devices are linked to the bus via an open-drain

15
Intelligent Fire Alarm with Bluetooth

port of the data line (DQ pin). The open drain port allows each device on the bus to
” release„ the data line when it is not transmitting data so the bus is available for use by
another devices.

DS1820
Vcc
Vcc
Micro- GND DQ Vcc
controller 4.7K

1-wire bus

Fig 4.2. Block Diagram of the 1-Wire Bus Interface

The core functionality of the DS1820 is its direct-to-digital sensor. The temperature
sensor output has a 9-bit resolution, which corresponds to 0.5°C steps. The DS1820
powers-up in a low-power idle state; to initiate a temperature measurement and A-to-D
conversion, the master(microncontroller) must issue a Convert T command. Following
the conversion, the resulting thermal data is stored in the 2-byte temperature register in
the scratchpad memory of the DS1820. All transactions on the 1-wire bus begin with an
initialization sequence. The initialization sequence consists of a reset pulse transmitted by
the master followed by presence pulse transmitted by the slave. The presence pulse lets
the master know that slaves devices are on the bus and are ready to operate. After the bus
master has detected a presence pulse, it can issue a ROM command. The master can
make the DS1820 on the bus perform temperature conversion by issuing the Skip Rom
command followed by a Convert T command. To read the temperature, the master then
issues a Read Scratchpad command. Table 4.3 shows the 1-wire protocol. It is important
to follow the sequence in the table every time the DS1820 is accessed, as the sensor will
not respond if any steps are missing or out of order.

16
Intelligent Fire Alarm with Bluetooth

Master Mode Operation/Protocol Comment

TX Reset Reset pulse


RX Presence Presence pulse
TX CCh Skip ROM command
TX 44h Convert T command
TX Reset Reset pulse
RX Presence Presence pulse
TX CCh Skip ROM command
TX BEh Read Scratchpad command
RX <9 data bytes> Read the entire scratchpad until master sends reset
pulse. The master save the temperature value and
stores the contents of the count register and count
per
C register as COUNT_REMAIN and
COUNT_PER_C,
respectively.
TX Reset Reset pulse
RX Presence Presence pulse
--- --- Controller calculates the temperature to get the
actual
result and required resolution.
Table 4.3. 1-Wire Protocol.

4.2.3 Smoke Detector Unit


The smoke detector was difficulty to source as most of the parts are not available locally
and very limited sources overseas as well. Thus, the choices were limited and it was
selected on the basis of availability of as well as the price. The smoke detector unit
consists of a photodiode, an alarm IC and a piezoelectric buzzer. Fig 4.3 shows the
circuit of the smoke detector unit.

The MC14600 is the alarm IC. The output from the photodiode serves as an input to the
alarm IC at pin 15. The comparator at pin 15 determines whether alarm condition exists
and in response drives the buzzer and sets the LED flashing. Alarm condition occurs
when the output voltage of the photodiode exceeds the threshold. The output at the
comparator (pin 1) is a logic 0 under an alarm condition and logic 1 under no alarm
condition. The logic output is sent to the microcontroller to report the status at the smoke
detector. The alarm triggering point (alarm threshold) can be set to the required level by

17
Intelligent Fire Alarm with Bluetooth

adjusting the values of R1 and R2. This a simple voltage divider which sets the voltage at
pin 13 according to the values of R1 and R2.

The PT2735FPL is a self-driven piezoelectric buzzer with a feedback pin that is


connected to a closed loop oscillation circuit. It operates at 3 to 28Vdc with current
consumption of 10mA at 12Vdc.

The MC14600 operates at 6 to 12Vdc with an average supply current of 9uA.With low
current consumption from the components used in the circuit, the smoke detector unit is
ideally suited for battery operation at 9V.

To
Microcontroller
Photodiode

Alarm
IC

Piezoelectric
Buzzer

68pF 10M

Fig 4.3. Smoke Detector Unit

4.2.3.1 Photodiode
The OPT101 is a monolithic photodiode with on-chip transimpedance amplifier. Output
voltage is 7.5mVdc with no light and increases linearly with light intensity. The 0.09 x

18
Intelligent Fire Alarm with Bluetooth

0.09 inch photodiode is operated in the photoconductive mode for excellent linearity and
low dark current. The device operates from +2.7V to +38V supplies and quiescent current
is only 120uA. It operates in the temperature range of 0°C to 70°C. Fig 4.4 is a diagram
of the OPT101.

Fig 4.4 OPT101 Photodiode

4.2.4 LCD Display


The Z-4170 is a 2x16 character alphanumeric dot matrix LCD module. An on-board
controller executes all control, refresh and display function. Data interfacing is via a 4 or
8 bit directional data bus. The operating voltage of the LCD is 4.4 to 5.5V. The operating
temperature is 0 to 50°C. Table 4.4 shows the pin function.

No Function Symbol
1 Ground (0V) Vss
2 Supply Voltage for logic (+5V) Vcc
3 Contrast Adjustment Vo
4 Data/ Instruction Set RS
5 Read/ Write Select R/W
6 Signal Enable E
7-14 Data Bus Line DB0-DB7
15,16 No connection No
Table 4.4. LCD Pin Function

19
Intelligent Fire Alarm with Bluetooth

4.3 Software Selection


CodeVisionAVR (CVAVR) is the C compiler used for programming the AT90S8515
microcontroller. It is selected because it is more user-friendly as compared AVR-GCC
and it has the library function that supports the 1-wire protocol.

4.4 The Bluetooth Communication Interface


The Bluetooth standard defines the Host Controller Interface (HCI) which is the
interface between the host (or device“s processor) and the Bluetooth device. In the case
of the Master, the host is the PC while that of the Slave is the microcontroller
(AT90S8515). They interface with the Bluetooth module residing on the Bluetooth
Application Tool kit (BATK). Fig 4.5 shows the layout of the Bluetooth Application Tool
kit and Fig 4.6 is the diagram of the kit.

Fig 4.5. Layout of BT Application Tool kit Fig 4.6. BT Application Tool kit

The Bluetooth module is connected as a DCE and DTE with a modem and null modem
(cable) used in between the Slave microcontroller and the PC of Master respectively.
Fig 4.7 is the schematic of the kit with DB9 connector for direct DCE connection.

20
Intelligent Fire Alarm with Bluetooth

MAX232E

Fig 4.7. Schematic of Bluetooth Application Tool kit with DB9 Connector
for Direct DCE Connection

4.4.1 Setting Up a Bluetooth Point-To-Point Connection


The Bluetooth standard for HCI defines the following:
• Command packets used by the host to control the module
• Event packet used by the module to inform the host of changes in the lower
layers.
• Data packets to pass voice and data between host and module

The HCI in the module is a command interface. The host presents commands to the HCI
and receives events back from the HCI of the module. The module Link Manager
provides link set up capability to the HCI. Asynchronous Connectionless (ACL) link is
used for data exchanged. Fig 4.8 shows the transition states of the communication
between the Master and Slave form standby to connection. The Master is set in the
paging mode asking for connection to the Slave. The Slave is set in paging scan mode
listening for a connection. This accomplished by first setting up the connection between
the host and the module and thereafter creating the connection between the modules
using HCI commands.

21
Intelligent Fire Alarm with Bluetooth

Standby Standby

Inquiry
Inquiry ID Scan

Inquiry
FHS Response

Standby Standby

Page
Page ID Scan

Master ID Slave
Response
Response
FHS

Connection POLL Connection


(Master) (Slave)
NULL

Fig 4.8. State Transition from Standby into Connection

22
Intelligent Fire Alarm with Bluetooth

4.4.1.1 Standby
In the standby state, the device is inactive, no data is being transferred, and the radio is
not switched on. Thus, the device is unable to detect any access codes. This state is used
normally to enable low power operation.

4.4.1.2 Inquiry
Inquiry is the process whereby a device will attempt to discover all Bluetooth enabled
devices in its local area. The baseband end of the Service Discovery Protocol (SDP), it
allows a device to compile a list of devices which it may want to connect with at later
time. During the inquiry procedure, the inquired upon devices will supply Frequency
Hop Synchronization (FHS) packets to the inquirer. The FHS packets allow the inquirer
to build a table of the essential information required to make a connection, such as
CLKN (native clock of Bluetooth device), which controls the on-air timing and frequency
hop sequence, BD_ADDR, which controls the frequency hop sequence and form part of
the access code.

4.4.1.3 Inquiry Scan


Inquiry scan is the other half of the inquiry procedure. Although scanning is optional and
up to the application, most devices will periodically enter inquiry scan state to make
themselves available to inquiring devices. They listen to an extended time. When they
receive a valid message, they enter the inquiry response substate and respond to the FHS
information. The inquiry and inquiry scan utilize a special hopping sequence (fast for
inquiry and slow for inquiry scan), which is designed to reduce the amount of time before
a frequency match occurs.

4.4.1.4 Page
To establish a connection, the device which is to become the Master is instructed by the
application to carry out the paging procedure. The Master first enters the page state,
where it will transmit paging messages directed at the intended Slave device. The Slave
acknowledges the paging message and the Master enters the master response substate and
responds with its FHS packet.

23
Intelligent Fire Alarm with Bluetooth

4.4.1.5 Page Scan


A device enters a page scan to allow paging devices to establish a connection with it.
Once a device in page scan state has successfully received a paging packet, it will enter
the slave response substate where it acknowledges the packet and awaits the FHS. On
reception of the FHS, it updates its own CLK (the Master clock that defines the timing on
a Bluetooth piconet) timing and sync word/access code reference before entering the
connection state. Again, like the inquiry procedure, the paging procedure uses a special
hopping sequence, which is designed to reduced the amount of time before a frequency
match occurs.

4.4.1.6 Connection ‘ Active


On entry to the connection state, the Slave switches to the Master“s CLK (by applying the
relevant offset to its own CLKN) and thus moves on to the Master“s frequency hop and
timing sequence. The Master transmits a POLL packet to verify that the link has been
successfully set up. The Slave must then respond with any type of packet, typically
NULL. If the connection fails to establish in this way, then after suitable timeouts, both
devices revert to page and page scan respectively and the whole process may restart.

4.4.2 Host Setup via UART


The HCI UART Transport Layer uses the RS2323 settings as shown in Table 4.5. The
default speed of the Bluetooth module is 57.6Kbps.

There are 4 different types of HCI packets accepted on the UART interface. Table 4.6
shows the packet type and indicator.

24
Intelligent Fire Alarm with Bluetooth

Table 4.5. RS232 Settings

Table 4.6. HCI Packet Type

4.4.2.1 Soft Reset

The first HCI command packet to send should be the RESET packet. A
Command_Complete event packet with the status parameter should be returned to the
host.

4.4.2.2 Buffer Information

Buffer information may be exchanged between the module and the respective host by
using HCI commands. Read_Buffer_Size provides the host with information on buffer
size for ACL (data) and SCO(voice) packets for the module returned with a

25
Intelligent Fire Alarm with Bluetooth

Command_Complete_Event packet. Host_Buffer_Size provides the module with


information on buffer size for ACL packets to the host.

4.4.2.3 Timers
It could be necessary to set important timers used by the module for time out handling.
The timers are all set by writing to registers using HCI commands.

4.4.2.4 Event Filter


HCI_Set_Event_Filter command is used to disable reporting of events, but rather than
simply switching events on and off, it uses events filters to specify which modules the
host is interested in inquires and connections.

4.4.2.5 Bluetooth Address


The hosts, using the HCI command Read_BD_ADDR will find the Bluetooth address of
the module by the Command_Complete event with the BD_ADDR as a parameter.

4.4.2.6 Page Scan Mode


Writ_Scan_Enable command with the correct parameter (Scan_Enable = 0x001A) will
set the module in Page Scan mode if the Command_Complete event is successful.

4.4.2 Data and parameter formats


All values are in Binary or Hexadecimal Little Endian format unless otherwise specified.

4.4.3.1 HCI Command Packet


The HCI command packet structure is shown in Table 4.7. It begins with a two byte
OpCode identifying the type of command. The first byte of the OpCode is the OpCode
Group Field (OGF), which identifies a group of commands. The second byte holds the
OpCode Command Field (OCF) and identifies a command within the group. The OpCode
followed by a single byte field giving the length of the following parameters in bytes.
The parameters themselves come next, and each occupies an integral number of bytes.

26
Intelligent Fire Alarm with Bluetooth

Table 4.7. HCI Command Packet

4.4.3.2 HCI Event Packets


The format of the HCI event packet is similar to HCI command packets, as shown in
Table 4.8. They carry the event code identifying the event. This performs a similar
function to the OpCode field, which identifies HCI commands. Like the command
packets, there is a field giving the total length of the parameters, followed by a list of
parameters.

Table 4.8. HCI Event Packet

27
Intelligent Fire Alarm with Bluetooth

4.4.3.3 HCI Data Packet


HCI data packets are used to pass both data (ACL) and voice information across the HCI.
Different packets are used for ACL and voice data. Voice data application is not used in
this thesis.

Table 4.9 shows the HCI data packet used to transfer ACL data. The fields in this packet
are as follows:

• The connection handle identifies the ACL connection for the data

• The Packet Boundary (PB) flag identifies whether the packet data carries the start
of a higher layer L2CAP packet, or is a continuing fragment of an L2CAP
packet.

• The Broadcast (BC) flag identifies point to point data from broadcast data, and
discriminates between active broadcast (for active Slave) and piconet broadcast
(for active and parked Slave)

• Data total length gives the length of data in bytes.

Every Bluetooth module and host is required to support packets with a data length of up
to 255 bytes. This is applicable to both the command and event packets as well.

Table 4.9. HCI Data Packet

28
Intelligent Fire Alarm with Bluetooth

5. Implementation

5.1 Overview
The implementation was carried out with a systematic approach according to the
following sequence:
• Implementation of Sensors with microcontroller
• Implementation of UART Serial Communication on microcontroller with PC
• Implementation of HCI code ‘ Serial Communication of microcontroller with
Bluetooth module and PC with Bluetooth module

Fire Alarm Unit

Temperature Sensor

Vcc DS1820

Vcc DQ GND
4.7K

PB.0

AT90S8515
Micro-
AT90S8515 Simulated
controller Smoke
Micro- Vcc
1K Detector
controller
PB.3
STK200 o
o
PC

GND

STK200
LCD
Display

Fig 5.1 Layout of the Fire Alarm Unit of the Slave

29
Intelligent Fire Alarm with Bluetooth

At every stage the testing was carried out to ensure that the hardware is fully functioning
with the code.

The hardware and software implementation follows closely to Fig 4.1 and 4.8 of chapter
4. However, due to time constraint, some changes in the hardware implementation were
made on the Slave but the Master remains the same. The smoke detector was not
physically implemented in the system even though the circuit was setup and tested on the
breadboard. Instead, a simulation is done by sending a logic 1 or 0 to pin 3 of Port B to
represent the alarm conditions. Fig 5.1 above shows the layout of the fire alarm unit of
the Slave.

The STK200 evaluation board is used to support the functions of the AT90S8515 Slave.
Appendix A shows the schematic of the STK200. The LCD display is implemented
using Port C. The LCD displays the temperature as well as an alarm message in the event
that the temperature sensor or smoke detector triggers an alarm.

5.1.1 Implementation of Sensors


5.1.1.1 Temperature Sensor
Major Issue
• Implementation of the code for timing of 1-wire protocol.
The protocol requires highly accurate timing in milliseconds which is very crucial
in the code. The application note of the DS1820 recommends that code to be
written in assembly language to ensure accurate timing. However, my intention is
to write the code in C. Therefore, the C compiler must be able to support the
timing function.
Approach
• The C compiler (CVAVR) for the Atmel controller comes with the library
functions to support the timing required for 1-wire protocol.

Fig 5.2 shows the flow chart for DS1820 temperature sensor. The implementation is
according to the protocol described in chapter 4.

30
Intelligent Fire Alarm with Bluetooth

Start

DS1820 No
present?

Yes

Skip ROM

Temperature
Conversion

DS1820 No
present?

Yes

Skip ROM Error

Read
temperature
data from
scratchpad

Reset

Calculate
temperatre

Fig 5.2 DS1820 Temperature


End Sensor

31
Intelligent Fire Alarm with Bluetooth

In the DS1820 routine, the microcontroller first sends a reset pulse and check for the
presence pulse returned by the DS1820 using the initialization function of the 1-wire
protocol . An error is displayed if it receives no response. When the presence pulse is
detected, the microcontroller then issues a Skip ROM command in order to access the
Convert T function. After the temperature conversion, the microcontroller then reads the
temperature data from the scratchpad memory of DS1820. It reads the 9 bytes of data
from the scratchpad. The LSB and MSB of the temperature data are stored in byte 0 and
byte 1 respectively. Byte 8 contains the cyclic redundancy check (CRC) code. CRC is
performed in this routine for data validation. However, this function can be optional as no
action is taken by the microcontroller even an error shows up in the CRC and it does not
prevent DS1820 to proceed to the next function. The microcontoller then performs a
temperature calculation. This is done by shifting the 8 bit MSB left and OR them with the
8 bit LSB. The result is multiplied by 5 to obtain a 16 bit data. This is then divided by 10
to obtain a resolution of one decimal place and accuracy of +/-0.5 °C in the temperature
reading. The sensor is designed to operate in the temperature range of 0 to 85°C at this
accuracy. However, it can operate up to 125°C.

To display the temperature reading in order to test the sensor, the LCD was
implemented. The display uses 4 bit data bus via pin 4 thru pin 7 of Port C. Table 5.1
shows the mapping of the pins from the microcontroller to the LCD.

AT90S8515 LCD
GND 1 - GND
Vcc 2 ‘ 5Vcc
PC.0 3 ‘ VLCD contrast
PC.1 4 - RS
PC.2 5 - RD
PC.3 6 - EN
PC.4 11 ‘ D4
PC.5 12 ‘ D5
PC.6 13 ‘ D6
PC.7 14 ‘ D7
Table 5.1. LCD Pin Mapping

32
Intelligent Fire Alarm with Bluetooth

The temperature readings were verified using a Alda 838 which is a K-type
thermocouple. Table 5.2 shows the temperature data. They readings were fairly close.

DS1820(°C) Alda 838(°C)


17.0 17
23.5 23
27.0 27
32.0 33
41.0 42
Table 5.2 Temperature Readings

5.1.1.2 Smoke Detector


The implementation follows that of Fig 4.3 with some with modification. A reset circuit
as shown in Fig 5.3 was added to allow the alarm to be reset. The output from the
photodiode(OPT101) is fed to a hex inverter to match the input requirement of the alarm
condition at the alarm IC (MC14600) as shown in Fig 5.4. The values of Cosc and Rbias
of Fig 4.3 in chapter 4 are 0.1uF and 8.2K respectively. Fig 5.5 shows the flow chart of
the sensors routine, this includes both the temperature sensor and the smoke detector.

Fig 5.3 Reset Circuit for Smoke Detector Fig 5.4 Output of Photodiode Inverted

33
Intelligent Fire Alarm with Bluetooth

Start

Read
temperature
sensor

Display
temperature on
LCD

Read smoke
detector

Smoke Yes
detector
triggered?

No

Temperature > Yes


Set Temp ?

No Display
warning
message on
LCD

End

Fig5.5 Read and Check Sensors

34
Intelligent Fire Alarm with Bluetooth

The temperature sensor, smoke detector (simulated) and LCD tap their power supply
from the 5V source on the STK200 board. The input to Pin 3 of port B switches between
Vcc and ground to produce the effect of the logic output from the smoke detector. The
output from the smoke detector is normally high under no alarm condition. When the
alarm is triggered, the output is set to 0, this turns on LED, PB3 of Port B. The code was
tested using the simulated smoke detector as per the flow chart in Fig 5.5

The circuit of the smoke detector in Fig 4.3 (with the above modification) was setup on
the breadboard and tested to be working. The testing was done by placing the smoke
detector circuit into box under normal lighting condition. When the box is covered, the
alarm sounded and the LED flashed. When the box was opened and the alarm was reset,
no alarm was detected. However, the output under no alarm condition is 9V. This voltage
is too high for the microcontroller which cannot accept any input exceeding 5V. The
voltage can be stepped down before the signal enters the port of the microcontroller using
a voltage divider .

5.1.2 Implementation of the Serial Communication on Microcontroller


Major Issues
• High error rate in data transmission and communication failure at 57.6Kbps
• Difficulty in determining when the receiving of data terminates at the UART.
Approach
• Change the crystal on the STK200 board. OR
Change the baud rate of the Bluetooth module in the HCI code if the first solution
does not work.
• Have the Interrupt service routine handling different data structure.
Make use of the know data structure for each packet type to determine the packet
size received and hence the end of the packet.

At this stage the communication was with the PC. However, the code was written to
handle the HCI packet in the Bluetooth communication via the UART as well. This
allows the code to be implemented later on the HCI without having to modify too much.

35
Intelligent Fire Alarm with Bluetooth

5.1.2.1 High Error Rate in Communication


The communication works perfectly well at 9600bps. However, the Bluetooth module
runs at a default baud rate of 57.6Kbps. To accommodate this, the baud rate was tested at
57.6Kbps. The data transmitted to the PC was observed to have the MSB always set 1.
When more data was sent, lost of data and communication failure occurred. The error rate
of the 4MHz crystal on the STK200 is as high as 7.8% at this baud rate according to the
data sheet of the AT90S8515. The crystal was thus replaced by a 4.608MHz one. This
gives an error of 0% at 57.6Kbps and solved the problem.

5.1.2.2 UART Interrupt Service Routine


Communication at the UART is half-duplex and is implemented with interrupt on
receiving the data. Data transmission is carried out as and when required. Fig 5.6 and 5.7
show the flow chart of the interrupt routine of the microcontroller and PC respectively.

When the UART receives an interrupt, all other interrupts are disabled, giving the
interrupt service routine the highest priority to execute its function. The data is first saved
into the UART buffer. The fist byte of the data determines the packet type. There are 3
packet types in the HCI. They are the Command, Event and ACL packets, each has
packet size of 4,3 and 5 bytes respectively. One of the byte in each packet carries the
information on length of the data. This byte is used to evaluate the size of the ACL
packet. The packet arrived flag is set indicating the arrival of the packet when the packet
is completely received. Interrupt is enabled at the end of each interrupt routine.

5.1.2.3 Communication of Temperature Sensor with PC


This UART interrupt routine was integrated with the DS1820 sensor function. A simple
routine for the PC to receive temperature data from the microcontroller was written to test
the communication. The PC samples the data each time a key is hit. By varying the
temperature at DS1820, different temperature readings were taken. The readings were
verified with the temperature data displayed on the LCD at the microcontroller. The code
was verified to be working.

36
Intelligent Fire Alarm with Bluetooth

Start

Disable UART
interrupt

Save byte
received
into buffer

Determine
packet type

Data Yes
received
complete?

Yes Save data to


No Is event
packet
packet?
structure

No

Yes Send sensors


Is ACL
info to
packet?
Master

No

Set packet
arrived flag

Enable UART
interrupt

Fig5.6 Interrupt Service Routine


End for Microcontroller(Slave)

37
Intelligent Fire Alarm with Bluetooth

Start

Save byte
received
into buffer

Determine
packet type

Data Yes
received
complete?

No

Save data to
packet
structure

Set packet
arrived flag

End

Fig5.7 Interrupt Service


Routine for PC(Master)

38
Intelligent Fire Alarm with Bluetooth

5.1.3 Implementation of the HCI


The wireless communication between the Master and Slave is via the Bluetooth modules.
The implementation follows closely to Fig 4.8 of chapter 4. The Master is the initiating
device searching for the Slave during initialization. The Slave waits for the Master for
connection. Once connection is established between the Master and Slave, the Slave
proceeds to perform its routine of the fire alarm system and sends the data upon request
from the Master. To requests the data from the Slave by hitting the keyboard of the PC.

Major Issue
Implementation of HCI code requires fairly substantial understanding of the Bluetooth
Specification.
• To develop the HCI code
1. From scratch
2. Use existing HCI code written for the PC.
3. Implement my sensor function into another microcontroller with HCI
Approach
• Develop the HCI code for the microcontroller and PC from the existing HCI PC
code and modify accordingly. AND
• Make use of my existing code developed from 5.1.1 and 5.1.2 for the sensors and
serial communication to implement the HCI code.

5.1.3.1 HCI Master and Slave


The HCI consists of 2 sections; the Master and Slave. The Master code runs on the PC.
This is the HCI code for the serial communication with the Bluetooth module of the
Master . The Slave code runs on the microcontroller. In addition to the HCI code for the
Bluetooth communication with the Bluetooth module of the Slave, the Slave code
includes the temperature sensing function of the DS1820 and the smoke detector.
Fig 5.8 and 5.9 show the main flow charts of the code for the Slave and Master
respectively. Fig 5.10 and 5.11 are the flow charts for initializing connection. Both HCI
codes use the interrupt service routine described in 5.1.2 for data receiving.

39
Intelligent Fire Alarm with Bluetooth

Following is the sequence for the of the HCI code:


• Initializing connection
§ Reset
§ Establishing connection
• Sending and Receiving ACL packets

Start

Initialize
Sensors Ports
and LCD

Initialize
Connection

Yes
Disconnect?

Serial Comm
interrupt
No Interrupt
Service
Routine

Read and check


sensors

End

Fig5.8 Main Flow Chart for Slave

40
Intelligent Fire Alarm with Bluetooth

Start

Initialize
Connection

Yes
Quit?

No
Request to
release
connection Send sensors
info request to
Slave Serial Comm
interrupt Interrupt
Service
Routine
Wait for
Disconnection_
Complete event Wait for
packet response from
Slave

Restore serial
comm interrupt
vector Display sensors
info

End

Fig5.9 Main Flow Chart for Master

41
Intelligent Fire Alarm with Bluetooth

Start

Write Connection
Accept Timeout
Initialize UART

Wait for
Command_Complete
event packet
Reset

Write scan Enable


Wait for
Command_Complete
event packet

Wait for
Command_Complete
event packet
Set event filter

Wait for
Wait for Connection_Complete
Command_Complete evetn packet
event packet

Connection
Established

Fig5.10 Slave Initializing


Connection

42
Intelligent Fire Alarm with Bluetooth

Start

Initialize
Serial Comm Inquiry

Wait for
Reset Command_Status
&
Inquiry_Result
event packet
Wait for
Command_Complete
event packet
Create connection

Set event
filter
Wait for
Connection_Complete
event packet
Wait for
Command_Complete
event packet
Connection
Established

Fig5.11 Master Initializing


Connection

In the initialization process, the OGF and OCF fields of the HCI packet identify the HCI
command. For sending and receiving of ACL packets, the connection handle parameters
identify the ACL connection for the data. The HCI codes are attached in Appendix B.

The term host denotes the PC of the Master or the microcontroller of the Slave. Each time
a command is sent to the BT module, the module responds with a Command_Complete
of Command_Status event packet. Command_Complete is used if the command can be

43
Intelligent Fire Alarm with Bluetooth

executed immediately, otherwise Command_Status is used. After issuing a HCI


command, the host waits for the event packet in the receive() function. It waits for a
second packet in the next receive() function if it expects the Command_Complete event
to come next. The communication between the two modules of the Master and Slave is
not visible. In the HCI code, the host issues a command and waits for an expected event
packet from the BT module according to the BT specification.

5.1.3.1.1 Reset
Both the hosts of the Master and Slave start the communication by issuing a Reset
command. This resets the Bluetooth module and the Link Manager. The host sends out a
HCI Command to the BT module and waits for it to return a Command Complete event.

5.1.3.1.2 Establishing Connection


In the following paragraphs, the term host_Master denotes the PC of the Master and the
host_Slave denotes the microcontroller of the Slave.

The host_Master issues a read_buffer_size command to gather the information of the


buffer size of the ACL packet at the module. This command is found to be optional and
was not implemented on the host_Slave. However, the host must ensure that the HCI data
sent does not exceed the buffer size of the module.

Both hosts issue a Set Event Filter command. This allows the hosts to automatically
accepts a connection when a device is found.

The host_Master issues an Inquiry command to discover the BT devices around it. It
gathers information such as Page_Scan_Mode, Page_Scan_Repeatition and
BD_ADDR(BT address) of the devices discovered. These are used later when creating
connection. The BT module of the Slave responds to the inquiry. This will be reported to
the host_Master in an Inquiry Result event. Inquiry scanning is performed automatically
by the BT module of the Slave.

44
Intelligent Fire Alarm with Bluetooth

The host_Master uses Create Connection command to carry out the paging. This
command contains all the information that the BT module requires to establish a
connection. At this point in time, the host_Slave should be performing a page scan using
Write Scan Enable command. This allows both Master and Slave to establish connection.
The BT address of the Slave is fixed in the host_Master code. This is because it would be
of no interest to connect to other slaves devices as far as my application is concern.
Moreover, they may present as nuisance. Therefore, it possible to connect a device just
by entering the BT address without performing an inquiry. However, certain information
may be missing, these parameters again may be fixed.

5.1.3.1.3 Sending and Receiving ACL data


After establishing connection, the host _PC can start to request for data from the
host_Slave by using ACL packet. Upon receiving an ACL packet, the host_Slave will
respond by sending the data in an ACL packet. The data contains the temperature reading
and alarm status of the temperature sensor and smoke detector if an alarm is triggered. At
the host_Master, the temperature data reading is displayed on the PC. It then evaluates
the data of the alarm status and displays the information accordingly

5.1.3.1.4 Synchronization
In the HCI code, the packet arrived flag is use in the receive() function to indicate the
arrival of the packet from the BT module. However, the PC and the microcontroller does
not behave the same way. Practically, the same code that works on the PC may not on the
microcontroller. The position where the packet_arrived flag is inserted is crucial in the
code. The entire code cannot function if this is not correctly done. Following is a section
of the code for the Master and Slave with a difference in the position of the flag. The
explaination that I can provide is probably the difference in the execution speed of the
microcontroller and the PC. This may result in the flag being set at a different timing and
thus affects the synchronization process.

45
Intelligent Fire Alarm with Bluetooth

HCI Master
void receive()
{
struct event_pkt *hc_event_pkt;

pkt_arrived = 0;
while(!pkt_arrived);
switch (flag)
{
case 0x04 :
hc_event_pkt = (struct event_pkt *)rec_buffer;
if (hc_event_pkt->event_code == 0x0F)
{
pkt_arrived = 0;
while(!pkt_arrived);
}

HCI Slave
void receive()
{
struct event_pkt *hc_event_pkt;

while(!pkt_arrived);
pkt_arrived = 0;
switch (flag)
{
case 0x04 :
hc_event_pkt = (struct event_pkt *)rec_buffer;
if (hc_event_pkt->event_code == 0x0F)
{
while(!pkt_arrived);
pkt_arrived = 0;
}

This problem might be solved using flow control as recommended in the Bluetooth
specification. Ready To Send (RTS) and Clear To Send (CTS) is used to flow control the
UART interface. This requires the CTS and RTS pins to be physically connected to the
DB9 connector at the microcontroller which will involve hardware modification on the
board. This is not implemented since the code can handle the problem.

5.1.3.2 Communication between Master and Slave


Fig 5.12 shows the result displayed on the PC with the Master establishing connection
and reading the data from the Slave. The PC is the Master itself. Different temperature
readings were taken to show the response of the temperature sensor.

46
Intelligent Fire Alarm with Bluetooth

Fig 5.12 Communication between Master and Slave displayed on the PC

47
Intelligent Fire Alarm with Bluetooth

6. Product Evaluation

6.1 Product Description


The final product of the fire alarm system consists of a Master and a Slave. The user
operates the Master by running an executable file from the PC of the Master unit. The
display on the PC is in DOS mode. The executable file allows the Master to be run on
any PC. The Slave performs the function of a fire alarm sensor. It displays the
temperature as well as the alarm message on the LCD. Once the Master and Slave are
setup for connection, the user may obtain the temperature data and the alarm message
from the Slave. This is done by hitting a key on the keyboard of the PC. The Master and
Slave can operate within a distance of 10m even when separated by the wall.

The temperature sensor of the fire alarm unit operates at an accuracy of +/-0.5 °C within
the operating range of 0 to 85 °C. The product was tested to ensure it fulfills its intended
functionality.

The Master and Slave, each has Bluetooth module attached. The module taps its power
supply from the USB port of the PC. As the Fire Alarm Unit (FAU) is implemented on
the Atmel evaluation board, the whole unit is powered by the board which draws the
supply from a 12V AC-DC converter. The output from the smoke detector is simulated.

6.2 Operation Procedure


1. At the Master, connect the serial cable of the BT module to a null modem cable.
Connect the null modem cable in the RS232 port of the PC.
2. Connect the USB cable of the BT module to the USB port of the PC of the
Master.
3. At the Slave, connect the STK200 board to an AC-DC converter.
4. Connect the serial cable of the Slave BT module to the serial port of the STK200
board.
5. Connect the USB cable of the Slave BT module to the USB port of any PC.
6. Turn on the power at the STK200 board.

48
Intelligent Fire Alarm with Bluetooth

7. At the Master, run the executable file.


8. Follow the instruction on the PC and hit the Enter key when the first message
appears.
9. Check that both Master and Slave established connection.
After connection is established, the Slave should display temperature reading and
the Master should display a message stating it is ready.
10. Hit the Enter key at the PC to obtain the data from the Slave.
11. Repeat step 10 each to sample for more data.
12. To simulate the smoke detector, use the 2-way switch. When the smoke detector
is triggered, the LED at PB.3 on the STK200 should turn on.
13. If the Master or Slave is disconnected or hangs, reset the power at the Slave and
restart the PC if necessary. Repeat steps 7 to 10.

6.3 Product Testing


6.3.1 Temperature Sensor
The leads of the DS1820 temperature are connected to wires of about 1m long to allow it
to be placed the oven
Equipment
• Alda 838 Digital Thermometer ‘ K type thermocouple
Accuracy: +/-3 °C
Resolution: 1°C
• Simpson Oven
Temperature range: 30 to 300°C

Procedure
1. Heat up the oven to approximately 100°C
2. Turn down the heat slowly.
3. Allow it to stabilize.
4. Place the DS1820 and the thermocouple of the Alda 838 into the oven and close
the oven door.

49
Intelligent Fire Alarm with Bluetooth

5. Start taking the temperature reading of both thermometers when the temperature
reaches 85°C.
6. Turn down the heat of the oven to take the next reading when the temperature
stabilizes. This is repeated until all the readings are taken.

Table 6.1 shows the result.

Fire Alarm Sensor Alda 838


(°C) (°C)
85.0 85
80.5 81
75.0 75
70.0 70
64.5 64
60.5 60
54.5 54
50.5 50
45.5 45
40.0 40
35.5 36
30.0 30
Table 6.1 Result of the Temperature Test

Observation
• The Alda 838 responded very fast to temperature changes. The fire alarm sensor
was relatively slow.
• The readings were taken when the temperature of the fire alarm sensor stabilizes.
The Alda 838 stabilized fast.

6.3.2 Connectivity
Tests were conducted to evaluate the ability of the Master and Slave in establishing
connection as well as to identify the problems that may occur. Table 6.2 shows the tests
carried to test the connection between the Master and Slave.

50
Intelligent Fire Alarm with Bluetooth

Test Condition Connection Established? Master Receive


Master Slave Data?
1. Master a Slave placed 3m apart with
3 computers in between. Y Y Y

2. Master a Slave placed 10m apart


separated by a wall. Y Y Y

3. Master a Slave placed >10m apart


separated by a wall after connection __ __ N
established.
4. Run Master with a different fixed
Slave address. N N __

5. Run Master without Slave address


fixed. Y Y Y

Table 6.2 Connectivity Test

Observation
• In test 3, both the Master and Slave hang when they were separated by more 10m
apart. The BT modules are not intended to function outside the distance. Both
Master and Slave must be re-setup to establish the connection if such problem
occurs.
• The Slave will only start performing it routine of reading and checking the sensor
after it has setup the connection with the Master. If the Master fails to connect, the
Slave will always be waiting.

6.4 Power Consumption


It is difficult to evaluate the power consumption of the whole FAU as it is implemented
on the evaluation board. However, all the components were selected on the basis that are
of low in power consumption and designed for battery operation. The Master and Slave
need only to setup connection once. Thereafter, the Slave need not perform any periodic
page scanning. For the same reason, the Master does not need to perform any periodic
inquiry or paging. This prevents excessive power from being drained off.

51
Intelligent Fire Alarm with Bluetooth

6.5 Budget
Table 6.3 shows the cost of the major components used in the design of the FAU.

Description Part Number Price (A$) Supplier


Microcontroller AT90S8515 22.50 Polykom
Temperature Sensor DS1820 5.57 Arrow Electronics
Smoke Detector
• Photodoide OPT101P 7.72 Arrow Electronics
• Alarm IC MC14600P 2.60 Arrow Electronics
• Buzzer PT-2735FPL 4.82 Arrow Electronics
LCD Z4170 25.12 Dick Smith
Total $68.03
Table 6.3 Price of Major Components

6.6 Performance Evaluation


• Fulfils the functionality of a fire alarm.
• Fulfils the requirement to implement Bluetooth for communication.
The implementation is half-duplex.
• Design for low cost and low power consumption.
• The test in section 6.3.1 shows that the response of the temperature sensor is not
as good as the thermocouple. A thermocouple or a thermister will be a better
choice in the fire alarm application.
• The connectivity test shows that the product has strong ability to establish
connection. However, it may a problem that the Slave responds to any paging BT
device. This is verified in test 5, the result shows the Slave establishing
connection with a Master that does not have the Slave“s address fixed. It makes
sense to fix the Master“s address in the Slave restricting the Slave to connecting
only to the intended Master.
• As mentioned in the observation of the connectivity test, the Slave will not
perform its sensing function unless it has setup its connection with the Master. If
the Master fails to function, the Slave will also not able to function. The HCI does
have certain commands that allow the length of the page scan window to be set.

52
Intelligent Fire Alarm with Bluetooth

This can be implemented to allow the Slave to disconnect when the scanning time
expires and start performing its sensing function instead of waiting infinitely for
the Master.
• Test was also conducted to verify if the FAU triggers the alarm when the
temperature reaches the pre-set value and when the smoke detector is triggered.
The test shows that the alarm message is displayed on both the LCD and PC when
both sensors were triggered.
• Many thermal detectors in the market offer operating temperature up to 60°C. The
FAU performs beyond this, operating up to 85°C at the specified accuracy.

53
Intelligent Fire Alarm with Bluetooth

7. Recommendation

From the product evaluation in chapter 6, we see some limitations in the product
performance. The product can be further improved and the system can be expanded to
include other features to make it more feasible for practical application. Following is the
recommendation:
1. The current implementation requires the user to manually hit the keyboard each
time to retrieve data from the Slave. It may be a better idea to implement the PC
as the Slave and the FAU as the Master. The FAU sends out the data only when
the alarm is triggered and the PC waits to receive the data upon interrupt.
Alternatively, we can look into the role switching function between the Master
and Slave. Bluetooth allows any device to request a switch role with respect to
another device. The aim is to allow the Slave to send out any the data when the
alarm is triggered instead of waiting for the Master to request.
2. The advantage of having a PC in the system allows it to expand beyond the
current capability. The PC is a powerful equipment that can be made to
performance many useful tasks. Functions such dialing a number, paging or
sending a message via the telephone are practically useful when implemented.
3. As mentioned in section 6.3.4 of chapter 6, to overcome some of the limitations in
the product, the following is recommended
• To enhance the response of the temperature sensor.
§ Replace DS1820 with a thermister or thermocouple.
• To prevent the Slave from responding to any BT devices other than the Master
§ Fix the Master“s address in the Slave“s code. The Slave needs to verify
this address during the page scanning.
• To prevent the Slave from waiting infinitely for the Master to connect
§ Set the length of the page scan window to allow the Slave to disconnect
when the scanning time expires. The Slave then starts to perform it
routine sensing function and responds to any request only upon interrupt.
The Write_Page_Scan_Activity of the HCI command allows this to be
done.

54
Intelligent Fire Alarm with Bluetooth

8. Personal Evaluation

The toughest part of the thesis is to get the serial communication working. Due to the
lack in experience in programming serial communication, my learning curve is steep.
Data transmission is not a problem but receiving is not that straight forward. I had a hard
time testing for receiving complete at the UART as the microcontroller does not have a
flag for it. I had to write the code to handle it in the interrupt service routine. The crystal
on the evaluation board generates high error rate when running at 56.7kbps, so much so
that it could not even communicate when the code expands. I spent quite some time
debugging and later realized I could simply replace the crystal to solve the problem. If I
had taken a better approach to carefully analyse the problem and identify the causes first,
it would have saved me the lengthy hours spent in debugging.

The Bluetooth communication is another difficult part. The communication between the
Bluetooth module of the Master and Slave is not visible, this makes the debugging very
difficult. It took me sometime to understand the Bluetooth specification before I can
debug the code.

It was too optimistic of me to plan for full implementation of the smoke detector. I would
like to but I never had enough time. It took me only a couple of days to get the hardware
working on the breadboard including modification. However, I had to re-schedule my
plan to make sure that I got the Bluetooth communication working first.

The thesis had provided the opportunity to improve my programming skill especially in
serial communication. I do gain valuable knowledge in the UART and Bluetooth
communication.

55
Intelligent Fire Alarm with Bluetooth

9. Conclusion

The Fire Alarm Unit (FUA) was designed to communicate using Bluetooth technology. It
is intended for indoor application within the range of 10m. The final product has
demonstrated that it achieved its intended function of a fire alarm sensor. It has the
capability to interface with the PC using Bluetooth communication protocol. The PC
serves its function as a master control panel reading data from the FAU. The product
fulfils the wireless communication requirement within the operating range.

The product can be further improved to make it more feasible for practical application. It
can expand beyond the current application to establish a Personal Area Network for home
security system.

56
Intelligent Fire Alarm with Bluetooth

10. Reference

1. J.Sanger, Security/Fire-alarm Systems, Butterworths, Edinburgh, UK,1994

2. J.E.Cunningham, Understanding Security Electronics, Indianapolis, IN, USD,1990

3. J.Bray and C.Sturman, Bluetooth Connect Without Cables, Prentice Hall, Upper
Saddle River, NJ, 2001

4. Ericsson, Specification of the Bluetooth System 敭 Core and Generic Access Profile
http://www.ericsson.com/bluetooth (2/4/01)

5. Dallas Semiconductor, Thermal Management Products, Quick Guide to 1-Wire Net


using PC and Microcontroller (AN132 敭 11/02/00), Reading and Writing iButton
via serial interface (AN74-26/3/01)

6. Maxim Semiconductor, How to Simplify the Interface between Microcontroller and


Temperature Sensor, http://dbserv.maxim-ic.com (Mar 2001)

7. National Semiconductor, National Semicoductor Temperature Sensor Handbook


(12/8/00), http://www.national.com (Feb 2001)

8. B.A.Miller and C,Bisdikian, Bluetooth Revealed, Prentice Hall, Upper Saddle River,
NJ, 2001

9. Simplex and Grinnell Fire and Protection, Fire Detection and Alarm
http://www.simplexgrinnell.com (Jun 2001)

10. Dongbang Electronic Industrial Co Ltd,


http://www.dbefire.co.kr/e_dbe/e_product.htm (Jul 2001)

11. Playmobil, Connecting two Gameboys over Bluetooth and GSM


http://www.it.lth.se/it/msprojects/ita/past/playmobile (May 2001)

57

S-ar putea să vă placă și