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.

I would like take this opportunity to thank the following people: Dr Adam Postula. for helping me in my hardware. . Naveenan. Mr Keith Bell and all the other people in the Electronic workshop.Intelligent Fire Alarm with Bluetooth Acknowlegements This thesis would not be successful without the help of the help of many people. for his guidance. for his help in the thesis lab. a student working on another Bluetooth thesis. for providing the support with his HCI PC code. Mr Len Payne.

3 Smoke Detector Unit 4.2.2.1 Microcontroller 4.2.2.3 Inquiry Scan 4.2.4 Host Controller Interface 2.2.1 Standby 4.4.3.4.1.1 Master and Slave 2. Technology Background 2.2 Baseband 2.1.3 Software Selection 4.2 Hardware Design 4.2.4.3 Timers 4.1 Application of Fire Detectors 3.2.2.4.4 LCD Display 4.1.10 Application Peripheral Interface 3.1.4.4.1 Soft Reset 4.4.5 Page Scan 4.4 Page 4. Introduction 2.1 The Bluetooth Technology 2.1.4.1.5 Bluetooth Address 4.1.1 Setting Up a Bluetooth Point-to-Point Connection 4.2 Buffer Information 4.2.6 RFCOMM 2.8 HCI Driver 2. System Design 4.5 Logical Link Control and Application Protocol 2.1.1.4.1 Photodiode 4.2.2 Bluetooth Hierarchy 2.2.4.1.2.2 Product available in the Market 4. Product and Technology in the Market 3.4.4.2 Host Setup via UART 4.6 Page Scan Mode Pg 1 2 2 3 4 5 5 5 6 6 6 6 7 7 8 12 13 13 14 17 18 19 20 20 21 23 23 23 23 24 24 24 25 25 26 26 26 26 .2 Inquiry 4.1.4.1.2 Temperature Sensor 4.2.2.2.1.1.Intelligent Fire Alarm with Bluetooth Table of Content 1.2.3 Link Manager 2.1.1 Radio Interface 2.4 Event Filters 4.6 Connection ‘ Active 4.2.1.2.1.7 Service Discovery 2.9 Stack Connection Manager 2.2.4 The Bluetooth Communication Interface 4.2.4.1.

2 Communication between Master and Slave 6.1.5 Budget 6. Product Evaluation 6.3 Data and parameter formats 4.1 HCI Master and Slave 5.3.1.1.3 HCI Data Packet 5.1.1.3.1 High Error Rate in Communication 5.2 Connectivity 6.4 Power Consumption 6.4.1 Overview 5. Conclusion 10.2.3.3 Communication of Temperature Sensor with PC 5.3.3. Implementation 5.1.1.2 Operation Procedure 6.2 HCI Event Packet 4.3.2 Implementation of Serial Communication on Microcontroller 5.2 UART Interrupt Service Routine 5.3.6 Performance Evaluation 7.2.2 Smoke Detector 5.3 Implementation of the HCI 5.2.Intelligent Fire Alarm with Bluetooth 4.1 Product Description 6.3.1. Reference Appendix A: STK200 Schematic Appendix B: Programe ‘ C Code Listing 26 26 27 28 29 29 30 30 33 35 36 36 36 39 39 46 48 48 48 49 49 50 51 52 52 54 55 56 57 58 59 .1 Temperature Sensor 6.1 HCI Command Packet 4. Recommendation 8. Personal Evaluation 9.1 Temperature Sensors 5.3 Product Testing 6.3.1.1.1.1.1 Implementation of Sensors 5.3.

Intelligent Fire Alarm with Bluetooth .

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

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

We need a product that is wireless and allows the signal to penetrate walls. The objective of this thesis is to develop a Fire Alarm Unit that communicates with the PC using Bluetooth technology. home security system has found its application practical in Personal Area Network (PAN).Intelligent Fire Alarm with Bluetooth 1. PAN offers users the advantage to personalize the network according to their needs instead of linking to public network. Introduction Home Security System is gaining its importance in many modern homes. Low power consumption is essential in any alarm system that is battery powered. 1 . Users find it cumbersome to handle wires and many face the inconvenience in installation with wires. Many would like to have a security system that monitors and alert them in case of emergency especially when they are away. Users are no longer satisfied with a simple fire alarm detector that just senses and sounds the alarm. complicated and require the system to be linked to a public emergency system. However. 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. Power consumption has to be kept low to maintain battery life. people are looking for a low cost and simpler solution. Traditional fire alarm systems are hardwired. The user may want to mount the fire detector and the control panel in a separate room. 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. With a personal computer available in many households today. Many products in the market are expensive. Fire alarm system is becoming essential in any home security system.

Two or more units share the same channel forming a piconet.4GHz. Technology Background 2. Every Bluetooth device has a unique Bluetooth device address. a kind of close range wireless network that look set to revolutionize the way people interact with information technology around them. though not simultaneously. the potential use of Bluetooth is only limited by one“s imagination. Printers.1 The Bluetooth Technology Bluetooth is a low power.1. they are told of the Bluetooth address and clock of the Master. short-range radio wireless technology. keyboards. consisting of one master an up to seven slaves. portable devices that typically are powered by battery. fax machines.Intelligent Fire Alarm with Bluetooth 2. Fig 2.2 Master and Slave Bluetooth operates in the unlicensed ISM band at 2. they form a scatternet. 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. Its design for low power consumption makes the technology well suited for use with small. When more than one master is involved in piconet. as well as home and office alarm systems. When Slaves connect to a Master. 2. It allows PDAs to connect to cell phones and cell phones to connect to notebooks. even toaster. The Master controls when devices are allowed to transmit. Each Bluetooth device may be a Master or a Slave at any one time. all eventually could be Bluetooth-compliant. a frequency-hopping scheme with 79 sub-frequencies is used to combat interference and fading. and a Bluetooth clock. It is designed to support communications at distances up to approximately 10m for devices that operate using a limited amount of power. 2 .1 shows a piconet. As this frequency is not reserved for Bluetooth. The Bluetooth technology has created a notion for Personal Area Network. The frequency-hopping scheme also enables Bluetooth to work not only in point-to-point connections but also in point to multi-point connections.

2. It is specified to operate with a maximum Bit Error Rate of 0. The channel bandwidth is 1MHz. The lower layers consist of the Radio interface. Fig 2.1 Radio Interface The Bluetooth module is a class 2 device with no power control. Baseband and the Link Manager and the Host Control Interface (HCI) and the audio.1. The higer layers are the Bluetooth standardized part of the stack. Piconet 2.2 shows the Bluetooth hierarchy. 3 . Modulation technique is a binary Gaussian frequency shift keying.2 Bluetooth Hierarchy Bluetooth is based on a stacked protocol model.1. The Bluetooth specification gives minimum performance parameters for the RF system. These consist of the Logical Link Control and Adaptation Protocol (L2CAP).1. Besides these parts. Norminal ranges of the modules with antennas are up to 10m (at 0dB) which complies with the regulation in the ISM band. where the communication is divided into several layers. serial port emulator (RFCOMM) and Service Discovery Protocol (SDP).1%.Intelligent Fire Alarm with Bluetooth Fig 2. there is a Stack Connection Manager (SCM) which handles and administers the Bluetooth connection. 2.

Hopping frequency is determined by a pseudo-random hopping sequence.Intelligent Fire Alarm with Bluetooth Fig 2. where the basic operation is a slot of 625us duration. 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.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.2.2 Different Layers in the Bluetooth Hierarchy 2.1. 4 . Bluetooth is a Time Division Multiplexed (TDM) system.

Fig 2. segmentation and reassemble operation. L2CAP permits higher level protocols and applications to transmit and receive L2CAP data packets up to 64K bytes in length. The LMP messages have the highest priority for link-setup. The LMP messages are sent in the payload and need not to acknowledge due to the reliable link provided by Baseband and radio. HCI Architecture 2.2. hardware status registers. 2. Fig 2.Intelligent Fire Alarm with Bluetooth 2.5 Logical Link Control and Adaptation Protocol (L2CAP) Provides connection-oriented and connectionless data service to upper layer protocols with multiplexing capability.6 RFCOMM RFCOMM is used as a transport protocol and emulation of the RS-232 serial port. 2. security. control registers and event registers.2.3.2.2.3 shows the HCI architecture.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.2. 5 .2.2. control and power saving modes.2.4 Host Controller Interface (HCI) The HCI-firmware implements HCI commands for the Bluetooth hardware by accessing Baseband commands. Link manager commands. It supports up to 60 simultaneous connections between 2 Bluetooth devices and is able to transmit and receive data up to 32K bytes.

10 Application Peripheral Interface (API) The interface to the stack is Ericsson propriety API.2. HCI interface also ensure that the stack can run over a generic hardware. 6 . sending and receiving of data. designed as environment independent and flexible.2. as well as other Bluetooth functions such as performing inquires and page function. 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.2.2. It also takes care of link keys that are generated after pairing. Dynamically loading profile and adding own API compliments suitable for the selected environment.Intelligent Fire Alarm with Bluetooth 2. It can be divided into a generic component and an environment dependent component.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.2.2. It allows the establishment and tear down of data voice connections.2. The SCM has to be used for creating data and voice links. 2. 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. a connection can be established using information obtained via SDP. 2.7 Service Discovery Protocol (SDP) SDP is a crucial part of the Bluetooth framework.8 HCI Driver The HCI driver establishes the communication between the stack and HCI firmware in the hardware. Thereafter. 2.2. SCM enables multiple applications on top of the Bluetooth stack to setup independent data and voice links.

which can detect invisible combustion particles with a diameter down to 0. This causes the current to fall. and the photoelectric type. The ionization (radioactive) type detectors contain alpha-emitter. They are therefore less sensitive to flaming fires with little visible smoke than the ionization type detectors. Product and Technology in the Market 3. Photoelectric smoke detectors will only respond to visible smoke particles with a diameter down to 0. Thermisters are most commonly used as it is cheap and offers quick temperature response. Thermal detectors are more suitable than smoke detectors for bathrooms and kitchen areas. triggering an alarm. The ionization type detector is more commonly found in Australian homes and offices. The ionization or radioactive type. they absorb most of the alpha particles. The most commonly used photoelectric smoke detectors have a detection chamber with a light source and a photoelectric cell. There are two types of smoke detectors in common use. primarily because it is cheaper and more readily available although photoelectric detectors are probably more suitable for most homes. Some sensors are built with a combination of both types of detector. The major types of sensors used in thermal detectors are infrared sensors. and when a voltage is applied across the cavity. They are used in attics. and also increase the resistance of the air.Intelligent Fire Alarm with Bluetooth 3. When smoke particles enter the chamber. they are not recommended for living areas of residence. 7 .1 Application of Fire Detectors Thermal detectors and smoke detectors are the sensors commonly used in fire alarm. When smoke particles enter this cavity. triggering the alarm. the light is obscured and the current from the photoelectric cell is reduced.01 microns. unheated garages and furnace rooms. Thermal detectors do not detect smoke or light. Americium. a small current is induced. thermisters and bimetallic elements.3 microns. The alpha particles ionize the air in a cavity.

In particular. A more sophisticated fire alarm system usually make use of the PC as the control panel. The display may be a LCD or LED indicator.1 shows the DIM2-02 ionization smoke detector from Dongbang. 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. setting off the alarm. while offering some extra protection in the case of certain kind of fires. they will react to the cooking fumes and invisible combustion particles from the heaters. if placed in or near kitchen or living areas with gas heaters or fireplaces. they are also prone to triggering nuisance alarms. Fig 3. Photoelectric detectors are therefore recommended for use in such areas. The detector may be connected to a control panel.1 and 3. A simple control panel includes basic features to display the alarm status and also allow the user to set the alarm conditions. 8 .2 are the description of some the fire detectors from Dongbang Electronic Industrial.2 Product available in the Market Fire detector is available as standalone unit that is portable and battery powered. 3. Table 3. as well as small home units and open plan houses. This technology is still by far the most common in fire alarm application as compared to the wireless types.Intelligent Fire Alarm with Bluetooth Ionization type detector.

solid state electric circuit. nonpolarity. Dongbang Smoke Detectors Description Temperature Heat Detector Model No DT06-01 Weather Proof Heat Detector Model No DTW6-A1 Rated Voltage Ambient Condition Temperature Features DC 24V -10 to 50°C up to 85%RH Connect to any control panel. Operating Temperature Table 3. solid state electric circuit. two wiring connection 60°C DC 24V -10 to 50°C up to 85%RH Connect to any control panel. non-polarity.2 Dongbang Heat Detectors 9 . two wiring connection. Table 3. solid state electric circuit. two wiring connection 60°C It will ” anticipate„ a fire condition by responding to a lower set point when the ambient temperature is rising rapidly. non-polarity. two wiring connection.Intelligent Fire Alarm with Bluetooth Description Ionization Smoke Detector Model No DIM2 Single Station Smoke Alarm (Ionization) Model No DAG1-01 Photoelectric Smoke Detector Model No DPG2-03 Rated Voltage Ambient Condition Temperature Features DC 24V -10 to 50°C up to 85%RH Connect to any control panel. solid state electric circuit. 9V DC battery -10 to 50°C up to 85%RH ___ DC 24V -10 to 50°C up 85%RH Connect to any control panel. nonpolarity.1.

Intelligent Fire Alarm with Bluetooth Fig 3.3. Both systems are from Simplex Grinnel. The fire system in Fig 3. The system can include features that allow the alarm conditions to addressed to the fire station as shown in Fig 3. Dongbang DIM2-02 Ionization Smoke Detector Fire alarm system may be implemented with multiple sensors using addressable nodes as shown in Fig 3.2. Fig 3. Simplex 4020 Fire Alarm System 10 .4 from Dongbang has the control panel connected to a PC.2.1. the PC is linked to an ⻦ emergency public addressed system“.

Dongbang D-Mux 3000 Fire Alarm System 11 .3 Simplex 4120/4100 Fire Alarm System Fig 3.Intelligent Fire Alarm with Bluetooth Fig 3.4.

The received information is processed at the PC. In the case of personal area network.1. System Design 4.1 System Overview Temp Sensor BT Link MicroController BT Module PC BT Module Smoke Detector Master LCD Display Slave Fig 4. Similarly. 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. The Master is the initiating device that sends out a request to the Slave whenever it requires the data. Upon receiving the request. the data is used to monitor the security system and perform certain tasks during emergency. the sends out the temperature data and the alarm status to the Master.1 shows the block diagram of the fire alarm system. The PC serves as the control panel for the fire alarm system. the fire alarm system may be part of the a home security system. Master and Slave. Block Diagram of Fire Alarm System Fig 4. It consists of 2 units.Intelligent Fire Alarm with Bluetooth 4. The heart of the Master is the PC (personal computer) and that of the Slave is the microcontroller. 12 .

4.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 other criteria for components selection are low power consumption and low cost . low in power consumption and supports battery operation. the smoke detect still functions. The smoke detector triggers an alarm when the smoke intensity exceeds the threshold. The Slave unit is designed to be portable. 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 Bluetooth module taps its power supply from the PC. The design ensures that the system is capable of performing its minimum role when a system fault occurs.2 Hardware Design Besides fulfilling the functionality. This avoids putting the entire fire alarm system into complete failure. 4. The PC communicates with the Bluetooth module via the RS232 serial port while the Slave uses the UART. it can be detached from the Slave. The communication is not affected by walls or obstacles in between. In the event that the microcontroller or the PC fails.2.1 Microcontroller Table 4.1 shows the specification of the various microcontrollers that were considered during the selection. Besides. The wireless technology has provided the flexibility to mount the Slave unit anywhere within a distance of 10m. The Bluetooth module in both the Master and Slave is physically connected by serial cable to the PC and microcontroller respectively. if the owner decides not to have the smoke detector working as a standalone unit. With the temperature reading displayed. smoke detector is designed to be able to work independently. 13 . Unlike the temperature sensor.

2 shows the specification of the various temperature sensors. Another good reason for selecting an Atmel controller is the availability of the Atmel STK200 evaluation board from the thesis laboratory.7 to 6 512 512 1.Intelligent Fire Alarm with Bluetooth Microcontroller Vcc (V) RAM (byte) EEPROM data memory (byte) ROM (byte) AT90S8515 AT91R4087 2. onboard RAM and programmable ROM or flash memory. This temperature range is more than sufficient for fire alarm application. Digital sensors can achieve the precision that most analog sensors cannot.4mA @ 4. AT90S8515 is selected due to its low power consumption and the large programmable memory size and a relatively large RAM size.5 °C when operating between ‘10 to 85°C .8 to 3. At the point of selection.25mW/MH 2mA @ 5V. The sensor selected here is DS18S20. The DS1820 can achieve an accuracy of +/-0.6mA @ 3V. The threshold to trigger a fire alarm is usually set 14 . 0. UART and the I/O pins. However. The flash memory is more than sufficient to accommodate the code for the fire alarm application. MSSP Bi-directional I/O pins Yes Yes Yes Yes Power consumption 6. a high precision digital temperature sensor.5 368 256 8K x 16 ---2K x 14 EPROM 8K x 14 Flash Flash Serial I/O UART.3V 4MHz 4MHz Table 4.2. z 4MHz @3. The board offers the convenience of onboard RAM extension using 2 chips. 4. Microcontroller Specification The key selection criteria for the microcontroller are the power consumption. 3V.1. SPI 2 USART SPI USART.0 to 5.5 to 5. The bi-directional I/O pin is necessary for the 1-wire interface. a 32K word RAM and an address latch.2 Temperature Sensor Table 4. it was not certain how large a RAM size is required for the Bluetooth host controller interface (HCI) code.5 128 16 PIC16F876 2. The UART is required for the serial interface with the Bluetooth module.6 136K ---- PIC12CE674 2. the RAM size of the controller can be extended.

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 Temp Range (°C) Accuracy(°C)

DS18S20 -10 to +125 +/-0.5 (-10 - 85 °C) 3 to 5 1.5 Digital 1-wire

Max6577 -40 to +125 +/- 0.5 typ +/- 3.5 max 2.7 to 5.5 3.2 Square wave 1-wire

LM20 -55 to +130 +/- 2.5 to +/-5 2.4 to 5.5 16u Analog 1-wire

DS1621 -55 to +125 +/-0.5 (0 - 70 °C) 2.7 to 5.5 1 Digital 2-wire

DS1620 -55 to +125 +/-0.5 (0 - 70 °C) 2.7 to 5.5 1 Digital 3-wire

Vcc (V) Current (mA) Output Interface

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.

Vcc Microcontroller

DS1820 Vcc
GND DQ Vcc

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 RX TX TX TX RX TX TX RX

Reset Presence CCh 44h Reset Presence CCh BEh <9 data bytes>

TX RX ---

Reset Presence ---

Reset pulse Presence pulse Skip ROM command Convert T command Reset pulse Presence pulse Skip ROM command Read Scratchpad command 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. Reset pulse 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. Output voltage is 7. Smoke Detector Unit 4.09 x 18 . The MC14600 operates at 6 to 12Vdc with an average supply current of 9uA. To Microcontroller Photodiode Alarm IC Piezoelectric Buzzer 68pF 10M Fig 4.5mVdc with no light and increases linearly with light intensity. 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 0. the smoke detector unit is ideally suited for battery operation at 9V.2. This a simple voltage divider which sets the voltage at pin 13 according to the values of R1 and R2.1 Photodiode The OPT101 is a monolithic photodiode with on-chip transimpedance amplifier.3.3.With low current consumption from the components used in the circuit.

2. Table 4.4 is a diagram of the OPT101.4 OPT101 Photodiode 4. LCD Pin Function 19 . The operating temperature is 0 to 50°C. refresh and display function.4. The device operates from +2. No Function Symbol Vss Vcc Vo RS R/W E DB0-DB7 No 1 Ground (0V) 2 Supply Voltage for logic (+5V) 3 Contrast Adjustment 4 Data/ Instruction Set 5 Read/ Write Select 6 Signal Enable 7-14 Data Bus Line 15. It operates in the temperature range of 0°C to 70°C.7V to +38V supplies and quiescent current is only 120uA.Intelligent Fire Alarm with Bluetooth 0.5V. Data interfacing is via a 4 or 8 bit directional data bus.4 LCD Display The Z-4170 is a 2x16 character alphanumeric dot matrix LCD module.09 inch photodiode is operated in the photoconductive mode for excellent linearity and low dark current. The operating voltage of the LCD is 4.4 to 5. An on-board controller executes all control.16 No connection Table 4.4 shows the pin function. Fig 4. Fig 4.

6. Fig 4. Fig 4.Intelligent Fire Alarm with Bluetooth 4.5. 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. 20 . 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.5 shows the layout of the Bluetooth Application Tool kit and Fig 4. 4. Layout of BT Application Tool kit Fig 4. the host is the PC while that of the Slave is the microcontroller (AT90S8515). In the case of the Master.7 is the schematic of the kit with DB9 connector for direct DCE connection.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.3 Software Selection CodeVisionAVR (CVAVR) is the C compiler used for programming the AT90S8515 microcontroller. They interface with the Bluetooth module residing on the Bluetooth Application Tool kit (BATK).6 is the diagram of the kit. Fig 4.

The host presents commands to the HCI and receives events back from the HCI of the module.7.Intelligent Fire Alarm with Bluetooth MAX232E Fig 4. Schematic of Bluetooth Application Tool kit with DB9 Connector for Direct DCE Connection 4. The Slave is set in paging scan mode listening for a connection. The module Link Manager provides link set up capability to the HCI. Asynchronous Connectionless (ACL) link is used for data exchanged.8 shows the transition states of the communication between the Master and Slave form standby to connection.4. 21 . Fig 4. 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. Data packets to pass voice and data between host and module The HCI in the module is a command interface. The Master is set in the paging mode asking for connection to the Slave.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.

Intelligent Fire Alarm with Bluetooth Standby Standby Inquiry ID Inquiry Scan FHS Inquiry Response Standby Standby Page ID Page Scan Master Response ID FHS Slave Response Connection (Master) POLL NULL Connection (Slave) Fig 4. State Transition from Standby into Connection 22 .8.

4. no data is being transferred. 4.4 Page To establish a connection. which controls the frequency hop sequence and form part of the access code. When they receive a valid message. the device which is to become the Master is instructed by the application to carry out the paging procedure.1. They listen to an extended time.4. such as CLKN (native clock of Bluetooth device). they enter the inquiry response substate and respond to the FHS information.1 Standby In the standby state. 23 .4. which controls the on-air timing and frequency hop sequence. The FHS packets allow the inquirer to build a table of the essential information required to make a connection. and the radio is not switched on. the device is unable to detect any access codes. BD_ADDR. 4. Although scanning is optional and up to the application. 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. the inquired upon devices will supply Frequency Hop Synchronization (FHS) packets to the inquirer. most devices will periodically enter inquiry scan state to make themselves available to inquiring devices. which is designed to reduce the amount of time before a frequency match occurs. During the inquiry procedure.4. Thus. This state is used normally to enable low power operation. The Slave acknowledges the paging message and the Master enters the master response substate and responds with its FHS packet.Intelligent Fire Alarm with Bluetooth 4. where it will transmit paging messages directed at the intended Slave device. The Master first enters the page state.3 Inquiry Scan Inquiry scan is the other half of the inquiry procedure. The inquiry and inquiry scan utilize a special hopping sequence (fast for inquiry and slow for inquiry scan).4.1.1.2 Inquiry Inquiry is the process whereby a device will attempt to discover all Bluetooth enabled devices in its local area. the device is inactive.1.

4.Intelligent Fire Alarm with Bluetooth 4. like the inquiry procedure.2 Host Setup via UART The HCI UART Transport Layer uses the RS2323 settings as shown in Table 4. typically NULL. 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. On reception of the FHS.4. the paging procedure uses a special hopping sequence. There are 4 different types of HCI packets accepted on the UART interface. Once a device in page scan state has successfully received a paging packet.1. The default speed of the Bluetooth module is 57.4. 24 . The Slave must then respond with any type of packet. 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. which is designed to reduced the amount of time before a frequency match occurs.1. If the connection fails to establish in this way. Again.6Kbps.4. 4.6 shows the packet type and indicator.6 Connection ‘ Active On entry to the connection state. both devices revert to page and page scan respectively and the whole process may restart.5. it will enter the slave response substate where it acknowledges the packet and awaits the FHS. Table 4. then after suitable timeouts. The Master transmits a POLL packet to verify that the link has been successfully set up.5 Page Scan A device enters a page scan to allow paging devices to establish a connection with it.

HCI Packet Type 4.2. A Command_Complete event packet with the status parameter should be returned to the host. 4.6.5. RS232 Settings Table 4.1 Soft Reset The first HCI command packet to send should be the RESET packet.2.4.4.2 Buffer Information Buffer information may be exchanged between the module and the respective host by using HCI commands.Intelligent Fire Alarm with Bluetooth Table 4. 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 .

It begins with a two byte OpCode identifying the type of command. The OpCode followed by a single byte field giving the length of the following parameters in bytes. which identifies a group of commands. 4. 26 . The second byte holds the OpCode Command Field (OCF) and identifies a command within the group. The timers are all set by writing to registers using HCI commands.4.2.2.1 HCI Command Packet The HCI command packet structure is shown in Table 4.4. 4. and each occupies an integral number of bytes. 4. 4.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. 4.4 Event Filter HCI_Set_Event_Filter command is used to disable reporting of events. The first byte of the OpCode is the OpCode Group Field (OGF).3. but rather than simply switching events on and off.4. 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.Intelligent Fire Alarm with Bluetooth Command_Complete_Event packet.2 Data and parameter formats All values are in Binary or Hexadecimal Little Endian format unless otherwise specified. it uses events filters to specify which modules the host is interested in inquires and connections. The parameters themselves come next.3 Timers It could be necessary to set important timers used by the module for time out handling.2.5 Bluetooth Address The hosts. Host_Buffer_Size provides the module with information on buffer size for ACL packets to the host.2.4.4.7.

8. Like the command packets. which identifies HCI commands. Table 4.2 HCI Event Packets The format of the HCI event packet is similar to HCI command packets. HCI Event Packet 27 .3.Intelligent Fire Alarm with Bluetooth Table 4. there is a field giving the total length of the parameters. They carry the event code identifying the event.4. This performs a similar function to the OpCode field. followed by a list of parameters.8. HCI Command Packet 4.7. as shown in Table 4.

The Broadcast (BC) flag identifies point to point data from broadcast 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. Different packets are used for ACL and voice data. or is a continuing fragment of an L2CAP packet. • • Every Bluetooth module and host is required to support packets with a data length of up to 255 bytes. Voice data application is not used in this thesis.4.9 shows the HCI data packet used to transfer ACL data.3 HCI Data Packet HCI data packets are used to pass both data (ACL) and voice information across the HCI. Table 4. HCI Data Packet 28 .9.Intelligent Fire Alarm with Bluetooth 4. 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. This is applicable to both the command and event packets as well. Table 4.3.

7K DS1820 Vcc DQ GND PB. 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 4.3 STK200 PC o o GND STK200 LCD Display Fig 5.Intelligent Fire Alarm with Bluetooth 5.0 AT90S8515 MicroAT90S8515 controller Microcontroller Vcc 1K Simulated Smoke Detector PB.1 Layout of the Fire Alarm Unit of the Slave 29 .

Therefore.1.Intelligent Fire Alarm with Bluetooth At every stage the testing was carried out to ensure that the hardware is fully functioning with the code.1. 5. However.1. The LCD display is implemented using Port C.1 and 4. The LCD displays the temperature as well as an alarm message in the event that the temperature sensor or smoke detector triggers an alarm. my intention is to write the code in C. Appendix A shows the schematic of the STK200. 30 . Fig 5.1 above shows the layout of the fire alarm unit of the Slave. The hardware and software implementation follows closely to Fig 4. The implementation is according to the protocol described in chapter 4. Approach • The C compiler (CVAVR) for the Atmel controller comes with the library functions to support the timing required for 1-wire protocol.1 Temperature Sensor Major Issue • Implementation of the code for timing of 1-wire protocol. a simulation is done by sending a logic 1 or 0 to pin 3 of Port B to represent the alarm conditions. The application note of the DS1820 recommends that code to be written in assembly language to ensure accurate timing. The STK200 evaluation board is used to support the functions of the AT90S8515 Slave.1 Implementation of Sensors 5. Fig 5. The protocol requires highly accurate timing in milliseconds which is very crucial in the code. the C compiler must be able to support the timing function.8 of chapter 4. Instead. 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. However. due to time constraint.2 shows the flow chart for DS1820 temperature sensor.

Intelligent Fire Alarm with Bluetooth Start DS1820 present? No Yes Skip ROM Temperature Conversion DS1820 present? No Yes Skip ROM Error Read temperature data from scratchpad Reset Calculate temperatre End Fig 5.2 DS1820 Temperature Sensor 31 .

6 PC. 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 . Byte 8 contains the cyclic redundancy check (CRC) code. It reads the 9 bytes of data from the scratchpad. However.4 PC.RS 5 . 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. CRC is performed in this routine for data validation.5 °C in the temperature reading.Intelligent Fire Alarm with Bluetooth In the DS1820 routine. The LSB and MSB of the temperature data are stored in byte 0 and byte 1 respectively. the microcontroller then issues a Skip ROM command in order to access the Convert T function. AT90S8515 GND Vcc PC. To display the temperature reading in order to test the sensor. the LCD was implemented. The result is multiplied by 5 to obtain a 16 bit data. The display uses 4 bit data bus via pin 4 thru pin 7 of Port C. The sensor is designed to operate in the temperature range of 0 to 85°C at this accuracy.1. This is done by shifting the 8 bit MSB left and OR them with the 8 bit LSB.5 PC. After the temperature conversion.3 PC. This is then divided by 10 to obtain a resolution of one decimal place and accuracy of +/-0. Table 5.2 PC. it can operate up to 125°C.7 LCD 1 . the microcontroller then reads the temperature data from the scratchpad memory of DS1820. LCD Pin Mapping 32 . When the presence pulse is detected.GND 2 ‘ 5Vcc 3 ‘ VLCD contrast 4 .1 PC.EN 11 ‘ D4 12 ‘ D5 13 ‘ D6 14 ‘ D7 Table 5.1 shows the mapping of the pins from the microcontroller to the LCD. The microcontoller then performs a temperature calculation.0 PC. An error is displayed if it receives no response. However.RD 6 .

A reset circuit as shown in Fig 5. DS1820(°C) 17. The values of Cosc and Rbias of Fig 4.1.0 32. Fig 5.Intelligent Fire Alarm with Bluetooth The temperature readings were verified using a Alda 838 which is a K-type thermocouple.2 Temperature Readings 5.0 Alda 838(°C) 17 23 27 33 42 Table 5.2 shows the temperature data.3 with some with modification.2K respectively.1uF and 8.3 in chapter 4 are 0. Table 5.1.5 shows the flow chart of the sensors routine.2 Smoke Detector The implementation follows that of Fig 4.4. Fig 5.3 Reset Circuit for Smoke Detector Fig 5.0 23.3 was added to allow the alarm to be reset.4 Output of Photodiode Inverted 33 . They readings were fairly close.5 27. 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.0 41. this includes both the temperature sensor and the smoke detector.

Intelligent Fire Alarm with Bluetooth Start Read temperature sensor Display temperature on LCD Read smoke detector Smoke detector triggered? Yes No Temperature > Set Temp ? Yes No Display warning message on LCD End Fig5.5 Read and Check Sensors 34 .

no alarm was detected. 5.1. The code was tested using the simulated smoke detector as per the flow chart in Fig 5. The testing was done by placing the smoke detector circuit into box under normal lighting condition. This voltage is too high for the microcontroller which cannot accept any input exceeding 5V. the output is set to 0. The output from the smoke detector is normally high under no alarm condition. Approach Change the crystal on the STK200 board. this turns on LED. the alarm sounded and the LED flashed. the code was written to handle the HCI packet in the Bluetooth communication via the UART as well.Intelligent Fire Alarm with Bluetooth The temperature sensor. The voltage can be stepped down before the signal enters the port of the microcontroller using a voltage divider . OR Change the baud rate of the Bluetooth module in the HCI code if the first solution does not work.2 Implementation of the Serial Communication on Microcontroller Major Issues • • • High error rate in data transmission and communication failure at 57. Make use of the know data structure for each packet type to determine the packet size received and hence the end of the packet. 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.6Kbps Difficulty in determining when the receiving of data terminates at the UART. PB3 of Port B. However. At this stage the communication was with the PC.5 The circuit of the smoke detector in Fig 4. smoke detector (simulated) and LCD tap their power supply from the 5V source on the STK200 board. 35 . • Have the Interrupt service routine handling different data structure. This allows the code to be implemented later on the HCI without having to modify too much. When the box was opened and the alarm was reset.3 (with the above modification) was setup on the breadboard and tested to be working. When the alarm is triggered. the output under no alarm condition is 9V. When the box is covered. However.

giving the interrupt service routine the highest priority to execute its function. The crystal was thus replaced by a 4.2 UART Interrupt Service Routine Communication at the UART is half-duplex and is implemented with interrupt on receiving the data. The packet arrived flag is set indicating the arrival of the packet when the packet is completely received. This gives an error of 0% at 57. Interrupt is enabled at the end of each interrupt routine. Data transmission is carried out as and when required.8% at this baud rate according to the data sheet of the AT90S8515. each has packet size of 4.2. The code was verified to be working. The data transmitted to the PC was observed to have the MSB always set 1. When the UART receives an interrupt.3 and 5 bytes respectively. They are the Command.6Kbps. The readings were verified with the temperature data displayed on the LCD at the microcontroller.608MHz one. Fig 5. the baud rate was tested at 57. One of the byte in each packet carries the information on length of the data. 36 . 5.7 show the flow chart of the interrupt routine of the microcontroller and PC respectively.1. The PC samples the data each time a key is hit.1.6 and 5. 5. all other interrupts are disabled.2.3 Communication of Temperature Sensor with PC This UART interrupt routine was integrated with the DS1820 sensor function.6Kbps. The error rate of the 4MHz crystal on the STK200 is as high as 7. This byte is used to evaluate the size of the ACL packet. A simple routine for the PC to receive temperature data from the microcontroller was written to test the communication. lost of data and communication failure occurred. different temperature readings were taken. The fist byte of the data determines the packet type. The data is first saved into the UART buffer.6Kbps and solved the problem. Event and ACL packets.2. By varying the temperature at DS1820.1. When more data was sent.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.Intelligent Fire Alarm with Bluetooth 5. There are 3 packet types in the HCI. To accommodate this.

6 Interrupt Service Routine for Microcontroller(Slave) 37 .Intelligent Fire Alarm with Bluetooth Start Disable UART interrupt Save byte received into buffer Determine packet type Data received complete? Yes No Is event packet? Yes Save data to packet structure No Is ACL packet? Yes Send sensors info to Master No Set packet arrived flag Enable UART interrupt End Fig5.

7 Interrupt Service Routine for PC(Master) 38 .Intelligent Fire Alarm with Bluetooth Start Save byte received into buffer Determine packet type Data received complete? Yes No Save data to packet structure Set packet arrived flag End Fig5.

In addition to the HCI code for the Bluetooth communication with the Bluetooth module of the Slave. 5. AND Make use of my existing code developed from 5. The Slave code runs on the microcontroller. Use existing HCI code written for the PC.9 show the main flow charts of the code for the Slave and Master respectively.Intelligent Fire Alarm with Bluetooth 5.3. From scratch 2. Fig 5. the Master and Slave.1. 3.1 HCI Master and Slave The HCI consists of 2 sections.1.1.8 and 5. Both HCI codes use the interrupt service routine described in 5.1. This is the HCI code for the serial communication with the Bluetooth module of the Master . Major Issue Implementation of HCI code requires fairly substantial understanding of the Bluetooth Specification.10 and 5. 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. Once connection is established between the Master and Slave. the Slave code includes the temperature sensing function of the DS1820 and the smoke detector. 39 . The Master is the initiating device searching for the Slave during initialization.3 Implementation of the HCI The wireless communication between the Master and Slave is via the Bluetooth modules. To requests the data from the Slave by hitting the keyboard of the PC. Fig 5.2 for the sensors and serial communication to implement the HCI code.2 for data receiving. the Slave proceeds to perform its routine of the fire alarm system and sends the data upon request from the Master. The Slave waits for the Master for connection.1 and 5. The Master code runs on the PC.1.8 of chapter 4. The implementation follows closely to Fig 4.11 are the flow charts for initializing connection. • To develop the HCI code 1.

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 Service Routine interrupt No Read and check sensors End Fig5.8 Main Flow Chart for Slave 40 .

9 Main Flow Chart for Master 41 .Intelligent Fire Alarm with Bluetooth Start Initialize Connection Yes Quit? No Request to release connection Send sensors info request to Slave interrupt Serial Comm Interrupt Service Routine Wait for Disconnection_ Complete event packet Wait for response from Slave Restore serial comm interrupt vector Display sensors info End Fig5.

10 Slave Initializing Connection 42 .Intelligent Fire Alarm with Bluetooth Start Write Connection Accept Timeout Initialize UART Reset Wait for Command_Complete event packet Wait for Command_Complete event packet Write scan Enable Set event filter Wait for Command_Complete event packet Wait for Command_Complete event packet Wait for Connection_Complete evetn packet Connection Established Fig5.

the connection handle parameters identify the ACL connection for the data. For sending and receiving of ACL packets. the OGF and OCF fields of the HCI packet identify the HCI command. The HCI codes are attached in Appendix B.11 Master Initializing Connection In the initialization process. The term host denotes the PC of the Master or the microcontroller of the Slave. 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 Start Initialize Serial Comm Inquiry Reset Wait for 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. Each time a command is sent to the BT module.

the host must ensure that the HCI data sent does not exceed the buffer size of the module. These are used later when creating connection.1. 44 . otherwise Command_Status is used. the host waits for the event packet in the receive() function.3.2 Establishing Connection In the following paragraphs. It waits for a second packet in the next receive() function if it expects the Command_Complete event to come next. This allows the hosts to automatically accepts a connection when a device is found. In the HCI code. 5.1 Reset Both the hosts of the Master and Slave start the communication by issuing a Reset command. The BT module of the Slave responds to the inquiry. 5. The communication between the two modules of the Master and Slave is not visible.1. However.1. The host_Master issues a read_buffer_size command to gather the information of the buffer size of the ACL packet at the module. Inquiry scanning is performed automatically by the BT module of the Slave.Intelligent Fire Alarm with Bluetooth executed immediately. The host sends out a HCI Command to the BT module and waits for it to return a Command Complete event. After issuing a HCI command. the term host_Master denotes the PC of the Master and the host_Slave denotes the microcontroller of the Slave. This will be reported to the host_Master in an Inquiry Result event. This resets the Bluetooth module and the Link Manager. The host_Master issues an Inquiry command to discover the BT devices around it. This command is found to be optional and was not implemented on the host_Slave.3. It gathers information such as Page_Scan_Mode. Both hosts issue a Set Event Filter command. Page_Scan_Repeatition and BD_ADDR(BT address) of the devices discovered.1. the host issues a command and waits for an expected event packet from the BT module according to the BT specification.

This is because it would be of no interest to connect to other slaves devices as far as my application is concern.1.Intelligent Fire Alarm with Bluetooth The host_Master uses Create Connection command to carry out the paging. The explaination that I can provide is probably the difference in the execution speed of the microcontroller and the PC. the same code that works on the PC may not on the microcontroller.1. 5.1. certain information may be missing. the packet arrived flag is use in the receive() function to indicate the arrival of the packet from the BT module. At this point in time.3 Sending and Receiving ACL data After establishing connection.3. they may present as nuisance. it possible to connect a device just by entering the BT address without performing an inquiry. Upon receiving an ACL packet. This command contains all the information that the BT module requires to establish a connection. 45 . However. This may result in the flag being set at a different timing and thus affects the synchronization process.3. the host _PC can start to request for data from the host_Slave by using ACL packet. Following is a section of the code for the Master and Slave with a difference in the position of the flag. these parameters again may be fixed.4 Synchronization In the HCI code. the temperature data reading is displayed on the PC. However. Moreover. The position where the packet_arrived flag is inserted is crucial in the code. Therefore.1. The BT address of the Slave is fixed in the host_Master code. This allows both Master and Slave to establish connection. Practically. It then evaluates the data of the alarm status and displays the information accordingly 5. At the host_Master. The data contains the temperature reading and alarm status of the temperature sensor and smoke detector if an alarm is triggered. the PC and the microcontroller does not behave the same way. The entire code cannot function if this is not correctly done. the host_Slave will respond by sending the data in an ACL packet. the host_Slave should be performing a page scan using Write Scan Enable command.

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. while(!pkt_arrived).12 shows the result displayed on the PC with the Master establishing connection and reading the data from the Slave. } HCI Slave void receive() { struct event_pkt *hc_event_pkt. pkt_arrived = 0. if (hc_event_pkt->event_code == 0x0F) { while(!pkt_arrived). while(!pkt_arrived). Different temperature readings were taken to show the response of the temperature sensor. Ready To Send (RTS) and Clear To Send (CTS) is used to flow control the UART interface.Intelligent Fire Alarm with Bluetooth HCI Master void receive() { struct event_pkt *hc_event_pkt. while(!pkt_arrived). pkt_arrived = 0. This is not implemented since the code can handle the problem. 5.2 Communication between Master and Slave Fig 5. 46 .1. switch (flag) { case 0x04 : hc_event_pkt = (struct event_pkt *)rec_buffer. } This problem might be solved using flow control as recommended in the Bluetooth specification. switch (flag) { case 0x04 : hc_event_pkt = (struct event_pkt *)rec_buffer.3. The PC is the Master itself. pkt_arrived = 0. if (hc_event_pkt->event_code == 0x0F) { pkt_arrived = 0.

Intelligent Fire Alarm with Bluetooth Fig 5.12 Communication between Master and Slave displayed on the PC 47 .

3. 6.1 Product Description The final product of the fire alarm system consists of a Master and a Slave. connect the STK200 board to an AC-DC converter. Connect the serial cable of the Slave BT module to the serial port of the STK200 board. Connect the USB cable of the BT module to the USB port of the PC of the Master. each has Bluetooth module attached. At the Slave. The executable file allows the Master to be run on any PC. The display on the PC is in DOS mode. 4. The Master and Slave can operate within a distance of 10m even when separated by the wall. 2. It displays the temperature as well as the alarm message on the LCD. At the Master. This is done by hitting a key on the keyboard of the PC. the whole unit is powered by the board which draws the supply from a 12V AC-DC converter.2 Operation Procedure 1. The temperature sensor of the fire alarm unit operates at an accuracy of +/-0. Turn on the power at the STK200 board. The Slave performs the function of a fire alarm sensor. connect the serial cable of the BT module to a null modem cable. Once the Master and Slave are setup for connection. The user operates the Master by running an executable file from the PC of the Master unit. The output from the smoke detector is simulated. 6.Intelligent Fire Alarm with Bluetooth 6. Connect the null modem cable in the RS232 port of the PC. Product Evaluation 6. The Master and Slave. As the Fire Alarm Unit (FAU) is implemented on the Atmel evaluation board.5 °C within the operating range of 0 to 85 °C. 5. 48 . The module taps its power supply from the USB port of the PC. The product was tested to ensure it fulfills its intended functionality. the user may obtain the temperature data and the alarm message from the Slave. Connect the USB cable of the Slave BT module to the USB port of any PC.

the Slave should display temperature reading and the Master should display a message stating it is ready. Turn down the heat slowly. 49 . Place the DS1820 and the thermocouple of the Alda 838 into the oven and close the oven door. 11. Allow it to stabilize. reset the power at the Slave and restart the PC if necessary. Check that both Master and Slave established connection. When the smoke detector is triggered. use the 2-way switch. run the executable file.3 on the STK200 should turn on. 10. After connection is established. If the Master or Slave is disconnected or hangs.Intelligent Fire Alarm with Bluetooth 7.3 Product Testing 6. 4. Repeat step 10 each to sample for more data. 13. Follow the instruction on the PC and hit the Enter key when the first message appears. 8.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. To simulate the smoke detector. Heat up the oven to approximately 100°C 2. 3. the LED at PB. 6.3. At the Master. Repeat steps 7 to 10. Hit the Enter key at the PC to obtain the data from the Slave. 12. 9.

5 54 50.0 70 64.5 64 60.5 36 30. Start taking the temperature reading of both thermometers when the temperature reaches 85°C. This is repeated until all the readings are taken.0 75 70.5 81 75.0 30 Table 6.3. Table 6. Table 6. 6.5 50 45.0 40 35.5 45 40.0 85 80. Turn down the heat of the oven to take the next reading when the temperature stabilizes.Intelligent Fire Alarm with Bluetooth 5.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. The Alda 838 stabilized fast. The fire alarm sensor was relatively slow.5 60 54.1 shows the result. The readings were taken when the temperature of the fire alarm sensor stabilizes. Fire Alarm Sensor (°C) Alda 838 (°C) 85.1 Result of the Temperature Test Observation • • The Alda 838 responded very fast to temperature changes. 50 .2 shows the tests carried to test the connection between the Master and Slave. 6.

6.4 Power Consumption It is difficult to evaluate the power consumption of the whole FAU as it is implemented on the evaluation board. 2. the Slave will always be waiting. Thereafter. However. 3. 51 .Intelligent Fire Alarm with Bluetooth Test Condition 1. Master a Slave placed >10m apart separated by a wall after connection established. This prevents excessive power from being drained off. 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. the Slave need not perform any periodic page scanning. both the Master and Slave hang when they were separated by more 10m apart.2 Connectivity Test Observation • In test 3. Master a Slave placed 3m apart with 3 computers in between. 5. Connection Established? Master Receive Master Slave Data? Y Y __ Y Y __ Y Y N N N __ Y Y Y Table 6. all the components were selected on the basis that are of low in power consumption and designed for battery operation. the Master does not need to perform any periodic inquiry or paging. The BT modules are not intended to function outside the distance. If the Master fails to connect. Master a Slave placed 10m apart separated by a wall. 4. The Master and Slave need only to setup connection once. Run Master without Slave address fixed. For the same reason. Run Master with a different fixed Slave address.

Design for low cost and low power consumption. • The connectivity test shows that the product has strong ability to establish connection.5 Budget Table 6.50 5. it may a problem that the Slave responds to any paging BT device.3 Price of Major Components 6. A thermocouple or a thermister will be a better choice in the fire alarm application.1 shows that the response of the temperature sensor is not as good as the thermocouple. However.6 Performance Evaluation • • • • Fulfils the functionality of a fire alarm.03 Supplier Polykom Arrow Electronics Arrow Electronics Arrow Electronics Arrow Electronics Dick Smith Table 6. the Slave will not perform its sensing function unless it has setup its connection with the Master. 52 .57 7.72 2. Fulfils the requirement to implement Bluetooth for communication.82 25.60 4. • As mentioned in the observation of the connectivity test. The test in section 6. Description Microcontroller Temperature Sensor Smoke Detector • • • LCD Photodoide Alarm IC Buzzer Part Number AT90S8515 DS1820 OPT101P MC14600P PT-2735FPL Z4170 Total Price (A$) 22. It makes sense to fix the Master“s address in the Slave restricting the Slave to connecting only to the intended Master.3 shows the cost of the major components used in the design of the FAU. If the Master fails to function.3. the result shows the Slave establishing connection with a Master that does not have the Slave“s address fixed. This is verified in test 5.12 $68. The HCI does have certain commands that allow the length of the page scan window to be set.Intelligent Fire Alarm with Bluetooth 6. The implementation is half-duplex. the Slave will also not able to function.

53 . • 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 FAU performs beyond this. 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.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. operating up to 85°C at the specified accuracy.

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.3. we see some limitations in the product performance. 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. § § • Replace DS1820 with a thermister or thermocouple. The Slave then starts to perform it routine sensing function and responds to any request only upon interrupt. Recommendation From the product evaluation in chapter 6. 3. 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 current implementation requires the user to manually hit the keyboard each time to retrieve data from the Slave. The Write_Page_Scan_Activity of the HCI command allows this to be done.Intelligent Fire Alarm with Bluetooth 7. Functions such dialing a number. 2. As mentioned in section 6. The advantage of having a PC in the system allows it to expand beyond the current capability. The FAU sends out the data only when the alarm is triggered and the PC waits to receive the data upon interrupt. It may be a better idea to implement the PC as the Slave and the FAU as the Master. paging or sending a message via the telephone are practically useful when implemented. to overcome some of the limitations in the product. Alternatively. The product can be further improved and the system can be expanded to include other features to make it more feasible for practical application. The Slave needs to verify this address during the page scanning. 54 .4 of chapter 6. The PC is a powerful equipment that can be made to performance many useful tasks. Following is the recommendation: 1. 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 following is recommended • • To enhance the response of the temperature sensor.

Data transmission is not a problem but receiving is not that straight forward. The thesis had provided the opportunity to improve my programming skill especially in serial communication. If I had taken a better approach to carefully analyse the problem and identify the causes first. The communication between the Bluetooth module of the Master and Slave is not visible. this makes the debugging very difficult. I had a hard time testing for receiving complete at the UART as the microcontroller does not have a flag for it.Intelligent Fire Alarm with Bluetooth 8. It was too optimistic of me to plan for full implementation of the smoke detector. Personal Evaluation The toughest part of the thesis is to get the serial communication working. It took me only a couple of days to get the hardware working on the breadboard including modification. I would like to but I never had enough time. 55 .7kbps. The crystal on the evaluation board generates high error rate when running at 56. The Bluetooth communication is another difficult part. It took me sometime to understand the Bluetooth specification before I can debug the code. However. so much so that it could not even communicate when the code expands. I do gain valuable knowledge in the UART and Bluetooth communication. it would have saved me the lengthy hours spent in debugging. I had to re-schedule my plan to make sure that I got the Bluetooth communication working first. Due to the lack in experience in programming serial communication. my learning curve is steep. I had to write the code to handle it in the interrupt service routine. I spent quite some time debugging and later realized I could simply replace the crystal to solve the problem.

56 . The final product has demonstrated that it achieved its intended function of a fire alarm sensor.Intelligent Fire Alarm with Bluetooth 9. It can expand beyond the current application to establish a Personal Area Network for home security system. 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 PC serves its function as a master control panel reading data from the FAU. It has the capability to interface with the PC using Bluetooth communication protocol. 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.

Thermal Management Products. Butterworths. http://www. NJ. http://www. 2001 4.E.Sturman. Prentice Hall.A.maxim-ic. J. Indianapolis. Fire Detection and Alarm http://www. Prentice Hall. Ericsson. http://dbserv. Understanding Security Electronics.Bray and C. Quick Guide to 1-Wire Net using PC and Microcontroller (AN132 敭 11/02/00). NJ. Dallas Semiconductor. Upper Saddle River. IN. Reference 1.dbefire.com (Mar 2001) 7. Edinburgh.co.national.htm (Jul 2001) 11. Dongbang Electronic Industrial Co Ltd. Reading and Writing iButton via serial interface (AN74-26/3/01) 6. J.Bisdikian.it. Upper Saddle River.1994 2. Bluetooth Connect Without Cables.com/bluetooth (2/4/01) 5. Playmobil.se/it/msprojects/ita/past/playmobile (May 2001) 57 . How to Simplify the Interface between Microcontroller and Temperature Sensor.Sanger. USD.com (Jun 2001) 10. Simplex and Grinnell Fire and Protection. Bluetooth Revealed. 2001 9. B.Miller and C. J.kr/e_dbe/e_product. Maxim Semiconductor.simplexgrinnell.Intelligent Fire Alarm with Bluetooth 10. National Semiconductor.com (Feb 2001) 8. Security/Fire-alarm Systems. National Semicoductor Temperature Sensor Handbook (12/8/00).ericsson. Specification of the Bluetooth System 敭 Core and Generic Access Profile http://www.lth. Connecting two Gameboys over Bluetooth and GSM http://www.Cunningham.1990 3. UK.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.