Documente Academic
Documente Profesional
Documente Cultură
with
Bluetooth
By
Chew Hong Eng
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
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
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:
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.
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
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
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
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
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
3
Intelligent Fire Alarm with Bluetooth
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.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
6
Intelligent Fire Alarm with Bluetooth
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.
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
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
9
Intelligent Fire Alarm with Bluetooth
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“.
10
Intelligent Fire Alarm with Bluetooth
11
Intelligent Fire Alarm with Bluetooth
4. System Design
Temp
Sensor
BT
Link Micro-
Controller
Smoke
PC BT BT Detector
Module Module
Master LCD
Display
Slave
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.
13
Intelligent Fire Alarm with Bluetooth
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.
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.
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
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
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 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
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.
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
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
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
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.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
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
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.
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
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.
26
Intelligent Fire Alarm with Bluetooth
27
Intelligent Fire Alarm with Bluetooth
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)
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.
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
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
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.
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
Read
temperature
data from
scratchpad
Reset
Calculate
temperatre
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.
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
No Display
warning
message on
LCD
End
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 .
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
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.
36
Intelligent Fire Alarm with Bluetooth
Start
Disable UART
interrupt
Save byte
received
into buffer
Determine
packet type
Data Yes
received
complete?
No
No
Set packet
arrived flag
Enable UART
interrupt
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
38
Intelligent Fire Alarm with Bluetooth
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.
39
Intelligent Fire Alarm with Bluetooth
Start
Initialize
Sensors Ports
and LCD
Initialize
Connection
Yes
Disconnect?
Serial Comm
interrupt
No Interrupt
Service
Routine
End
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
41
Intelligent Fire Alarm with Bluetooth
Start
Write Connection
Accept Timeout
Initialize UART
Wait for
Command_Complete
event packet
Reset
Wait for
Command_Complete
event packet
Set event filter
Wait for
Wait for Connection_Complete
Command_Complete evetn packet
event packet
Connection
Established
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
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
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.
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.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.
46
Intelligent Fire Alarm with Bluetooth
47
Intelligent Fire Alarm with Bluetooth
6. Product Evaluation
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.
48
Intelligent Fire Alarm with Bluetooth
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.
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
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.
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.
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
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)
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)
57