Building Monitoring System Based on Zigbee

This paper presents the building monitoring system that can determine the building condition in real time and ensure the safety of building operations. This monitoring building system can detect the ambient, CO gas, fan, water leak, and also intrusion detectors, through a wired sensor network. Then the data is processed by a main controller to generate a report that sent to the inspectors through ZigBee and / or sound an alarm if the situation is considered dangerous. Prototype of this monitoring system shows precision and stability with minimal error rate. Main controller can receive data from the sensor network properly and send it through ZigBee modules.


Introduction
with the development of communication technology, sensor network can be developed and connected in a building monitoring system (BMS) to replace the conventional control methods. A building monitoring system can feel the variables in the building e.g temperature, relative humidity, air flow, etc. It sends data measurements to a data center and process the data to generate alarms or display them to the operator. BMS consists of software and hardware. There are several wellknown manufacturers BMS, for example: Siemens, Honeywell, Johnson Controls, TAC, etc [1]. Some protocols that are commonly used for this BMS are Modbus or BACnet. However, in many cases, the costs required to implement the BMS is still very high and only large buildings use BMS system. However for small-sized sensor network, there are no specified standards [2].
In order to reach an effective and efficient of the sensor network, it needs to develop as needed. Wired system is suitable for sensors with fixed locations that need bandwidth and high power [3]. However the price of wired system is relatively more expensive, it is harder to add monitoring points and it is not mobile. While wireless technology has advantages in portability, low power, low cost and easy installation [4]. The wireless system also has a weakness against interference caused by high voltage electricity and strong electromagnetic fields. The presence of an electromagnetic field of 400KV causes interference that reduces the 70% range wireless data transmission [5].
Our research aims are to develop and create a prototype system that is used to monitor building condition automatically with sensors and ZigBee networks. The combination of sensors and Zigbee networks provide a highly economic way to monitor building. Zigbee is a new technology that eliminates wired connections between home appliances and personal computer. Instead of connecting with wires, every appliance has small transmitters or receivers.

Design for building monitoring system
The general description of BMS is shown in Figure 1. It consists of a main controller module, a laptop (as monitoring device), two ZigBee modules and five sensor modules (i.e. temperature and relative humidity sensor, intrusion detector, water leak detector, CO gas detector and fan RPM meter). Each sensor module has a microcontroller to measure sensor data and then sent it to the main controller using RS-485 communication standard. Therefore, each sensor module is connected to the RS-485 module that communicates with a microcontroller using serial UART (Universal Asynchronous Receiver-Transmitter) protocol. Main controller also has a RS-485 module to receive data from each sensor. Then data is processed by a main controller to generate a report and send it wirelessly to the monitoring device through ZigBee network using AT-Command protocol. The main controller could also sound an alarm if the situation is considered dangerous. Fig 2 shows the BMS flowchart, as the system turns on for the first time, the microcontroller start initializing. The program uses 3 interrupts, i.e. timer interrupt, serial 1 interrupt and serial 2 interrupt. Serial 1 interrupt will raise the microcontroller interrupt flag bits, RI (Receive interrupt flag) or TI (Transmit interrupt flag). RI bit value 1 when a data is received by the serial port (from the sensor module) and the TI bit value 1 when a data is sent via the serial port (to the sensor module). Like serial 1 interrupt, serial 2 interrupt also has an interrupt bit which are S2RI (Serial 2 receive interrupt flag) and S2TI (Serial 2 transmit interrupt flag). S2RI bit value 1 when a data is received from ZigBee module and the S2TI bit value 1 when a data is sent via the serial port 2 to the ZigBee module. Timer interrupt is set at certain time. The main program checks if "callsensorflag" value is 1 and it runs the "callsensor" function. This function sends a sensor module network address and a command for the sensor module whose address is mentioned to send its data. As it uses a 9-bit UART, each module that is connected to the system has a unique address. This routine is executed using polling method to avoid data collisions between the sensor modules. Serial 1 interrupt will receive response data from each sensor module and store it in a unique variable. Then, the main program checks if "displaysensorflag" value is 1 and it runs the "displaysensor" function. This function will display data from sensor module to the 2x16 character LCD. Data displayed in order, starting from the first sensor to the last sensor with an interval of 1.5 seconds. This function also checks whether the received sensor data is correct, e.g. one of the sensor modules is disconnected or the module is damaged, then it displays an error message to the LCD. In addition, this function can also activate a buzzer at the specified threshold, i.e. when the temperature is over 50°C, when water leak sensor detects water and when the CO gas detector sensor voltage exceeding 1.960 V.
Afterwards, the microcontroller checks if "Zigbeedataflag" value is 1 and the main program runs "ZigBeehandler" function. This function calls a function that will eliminate any ZigBee header e.g. "ATcommand+". This function extracts the data contents and take appropriate action. If the message is UCAST, then microcontroller checks 4 digit codes that are sent. If the code is "1991", then the sender"s address is stored in "true_adress" variable and give a value of 1 for "flag1" (this is a flag for the next function). If not, the sender"s address will not be saved. If the message is "NACK" (this happens if the ZigBee module is disconnected), then flag1 value is 0. If the "wait5sec" value is 100 (timer interrupt adds 1 value every 50 ms) or every 5 seconds, microcontroller will check the "flag1" variable. If "flag1" value is 1 (the command code sent to the ZigBee is "1991") it sends sensor data to the

Firdaus Kurniawan, et al., Building Monitoring System 67
Zigbee sender"s address. If "flag1" value is 0, then the data transfer is stopped, because it is assumed that the ZigBee module is disconnected or sent incorrect code. This function only sends data to one ZigBee module. If there is another ZigBee module that sends the right code, the main controller will be connected to the last ZigBee modules.

Discussion and Analysis
Some tests were conducted to check the precision of the sensors on the BMS prototype.
For the temperature and humidity sensors, the tests were taken in the room temperature and shown in figure 3. This shows the closeness of agreement between the actual temperature and relative humidity with the successive results obtained in a short time interval of these sensor modules. To check the intrusion detector, the reed switch and PIR sensor were used. Table 1 shows the results from the intrusion detector. If the reed switch sensor value is 1 and sensor PIR value is 1, the microcontroller sends a code '0' which means the door is open, motion detected. If the reed switch sensor value is 1 and sensor PIR value is 0, the microcontroller sends a code '1' which means the door is open, no motion detected.
If the reed switch sensor value is 0 and the PIR sensor value is 1, the microcontroller sends a code '2' which means the door is closed, motion detected. If the reed switch sensor value is 0 and the PIR sensor value is 0, the microcontroller sends a code '3' which means the door is closed, no motion detected. From the experiments performed, this sensor works well in responding to human movement. Therefore, these sensors can be used as an intrusion detector. Water leak detector produces the AC waveform to avoid electrolysis process on the probes and uses probes that made from stainless steel bolts to increase the corrosion resistance so it can be used for a long time. Figure 4 shows the AC waveform from the transmitter probe (CH1/top) and the waveform received by the receiver probe (CH2/below). Test was performed by inserting both of the probes into a container of water. The results showed that the water leak detector works well in detecting the presence of water. By using the oscilloscope, the output signal of CO gas detector was measured as shown in figure 5. CO gas sensor requires cycles of 5V heating period for 60 seconds and 1.4V sensing period for 90 seconds. The CO gas was given in the middle of 2 nd heating period. It seems that heating period suppressed output of the sensor. However, upon entering the sensing period, the sensor output increased significantly until the end of the 90 second period when the data is captured by the ADC port of microcontroller. After that, the sensor enters heating period again and the heater works to clean gas absorbed by the sensor surface before. Because of the heating cycle requirment, the sensor can only detect CO gas every 2.5 minutes. The response generated by this sensor is match with the data in the datasheet where the significant resistance changes when the sensor detects CO gas even in the 100 ppm level which leads to a sudden increase in voltage.
To test the fan sensor module, the comparison between the data generated by this sensor module and a tachometer to test the accuracy were done ( figure 6). It shows that the fan RPM meter generated the close even same value with the tachometer. It can be concluded that the fan rpm meter produces accurate data.

Conclusion
The prototype of BMS can be used to monitor the building conditions using 5 types of sensor modules, i.e. temperature and relative humidity sensor, intrusion detector, water leak detector, CO gas detector and fan RPM meter. It uses wired connection between sensor modules and main controller and it sends the data to monitoring device using wireless connection. Test results shown that this prototype has a good precision and stability with minimal error rate.