Hardware Implementation of Wireless Sensor Network Using Arduino and Zigbee Protocol

This paper presents a designed and implemented Wireless Sensor Network (WSN) based on Arduino and IEEE 802.15.4/Zigbee standards. This network consists of four end nodes; each one is connected to an individual type of sensors (lighting, temperature, motion, and distance) to form a safety network for building offices, factories, homes…etc. Also there is a fifth node in this network to collect the information from each node and send it to the base station which is a computer to be process the data and take the appropriate decision according to the program established by the user. Results confirmed that the network performs its functions with high efficiency and gave accurate readings of the surrounding circumstances. Stable reading of temperature and lighting had been achieved in the implemented network. Also, the motion and distance sensors gave good results depending on the presence of objects close to the more people moving near. In addition, the network is characterized by high flexibility and ease of programing that can be used to give various applications such as warning of fire by setting a threshold level of temperature to enable an alarm when exceeding such level. It can also be used to prevent thefts by detecting movements of the human body with distance sensor. In addition, other uses can be implemented such as controlling heating and lighting devices in homes and other buildings.


INTRODUCTION
ver the last decade, Wireless Sensor Networks (WSNs) held the promise of large scale data processing in a hug number of complex environments. WSNs offer new facilities of monitoring and controlling of various ubiquitous applications. Various types of sensing technologies have been grown and developed for various uses such as brightness, vibration, temperature, sound.... etc. [1]. The Micro Electro Mechanical systems (MEMS) technique leads the sensor node in WSNs to become very small in size, easy to install, replace at any location and can be easily removed [2]. Most often, the sensor nodes are connected wirelessly for short distances. Upon spreading, the nodes are configured as a network to collect the data by multinodes toward the base-station in a fashion of multi-hop to achieve real time and active monitoring [3].
The roll of data collection in WSNs is an important challenge for researchers. Grouping the sensor nodes into clusters is adopted to address this objective. For each group, it can select one node that can aggregate the data of the other members of such group. This node is called cluster head which collects the data from all nodes within its group and sends them to the base station.

817
One of the most first clustering approaches is Low-Energy Adaptive Clustering Hierarchy(LEACH) [4].In this protocol a clustering utilizes randomized rotation in a method that ensures regular distribution of energy load through the sensors that belong to the local cluster. Many challenges face WSNs applications such as hardware cost, system architecture, wireless connectivity, programmability and security. Each of these challenges needs more research to approach a better performance [5].
Much research has been done on efficiently hardware implementation and various protocols or mechanisms are used with different applications. Ref. [6] presents the vision of WSN to extend the lifetime with low cost, flexibility, high sensing fidelity and fault tolerance. On the other hand the remote data monitoring uses a system developed by internet to achieve real time processing, alarm on undesired occasion and visualization. The author in [7] presented a design online monitoring by adding a terminal point on the network and keeping the overall structure without changing. From the side of node communication, [8] presented a design of a network of WSN based on Zigbee protocol to monitor the temperature current and past times. This paper was an attempt to build a prototype of a wireless sensor network based on Arduino as a microcontroller board and XBee series 1 module. Four types of sensors were applied (lighting, temperature, motion, and distance sensors) to explain the evidence-of-concept of proposed system. Extensions of such work include an extended star network to a mesh network which will be suitable for organizing sensor networks in huge areas like in houses with several rooms and several floors.

WSNs Architecture
WSNs are the grouping of embedded systems and wireless communication which permit data transmission among the sensor nodes over wireless networks as shown in Fig. 1. The mind of each WSN node is the microcontroller which senses variables from its own sensors [9].

Figure (1):system diagram
A sensor network comprises an amount of spatially distributed sensor nodes that spread in an area of attention, and one or more base stations that are placed near the sensing area, as it is shown in Fig. 2.The base station sends instructions to the sensor nodes in the sensing area while the sensor nodes work to complete the sensing job and guide the transmitted data to the base station. The base station also acts as a gateway to external networks, such as, the internet. It gathers data from the sensor nodes, executes plain processing on the transmitted data, before it refers data to the users [10].
To refer documents to the sink, every sensor node must be able to use single -hop longdistance transmission, which pointers to the single -hop network architecture, as presented in Fig. 3. But, long distance transmission is expensive in terms of energy feeding [10].In multi-hop wireless networks there are one or more middle nodes along the pathway that obtain and backward packets via wireless links.

Figure (2):Sensor network architecture
Multi-hop wireless networks have some benefits: Compared to networks with single wireless links, multi-hop wireless networks can spread the coverage of a network and increase connectivity. Moreover, communication over multiple "short" links might need fewer transmission power and energy than "long" links [11].

Figure (3): Single-hop and multi-hop networks
The protocol stack used for Wireless Sensor Networks comprises five protocol layers: the physical layer, data link layer, network layer, transport layer, and application layer, as they are shown in Fig. 4. The application layer comprises a variety of application -layer protocols to create several sensor network applications. The transport layer is in charge of reliable data delivery required by the application layer. The network layer is in charge of routing the data from the transport layer. The data link layer is mainly in charge of data stream multiplexing, data frame transmission and reception, medium access, and error control. The physical layer is in charge of signal transmission and reception over a physical communication medium, with frequency generation, signal modulation, transmission and reception [10]. A microcontroller was used as a processing unit. The microcontroller is a minor computer on a single integrated circuit comprising a processor unit, memory unit, and programmable input/output peripherals. Microcontrollers are designed for embedded systems, different from the microprocessors used in individual computers or other general purpose applications. There are many types of microcontroller such as: 8051, Atmel, PIC … etc. [12].In this paper, an Arduino with Atmel microcontrollers has been used, because of its easy to integrate and simple to use. Arduino (Fig. 6) is an open source microcontroller system with a USB plug to join to the computer and many joining sockets that can be wired to peripheral electronics, such as motors, relays, light sensors, temperature sensors, distance sensors, motion sensors, microphones, etc. They are able to either run by the USB connection from the computer or from a 9-12 V DC. They can be controlled from the computer or programmed by the computer and then separated to work individually. The system is designed to be easy to learn, easy to use, flexible, and fast to develop. Arduino can sense the surroundings by receiving input from a variety of sensors and can affect its surrounds by controlling lights, temperatures, and other sensors. The microcontroller on the board is programmed using the Arduino programming language (based

Eng. &Tech.Journal, Vol.34,Part (A), No.5,2016
Hardware Implementation of Wireless Sensor Network Using Arduino and Zigbee Protocol 820 on Wiring) and the Arduino development environment (based on Processing) [13]. There are several sorts of Arduino such as Uno, Mega 2560, Mega ADK, and ArduinoLily Pad … etc. In this paper, an Uno and Mega 2560 were used because they are open source projects, flexible, easy to use and inexpensive.

Communication Unit
There are many wireless technologies used for WSNs, some of them are listed in table 1. It is expected that Zigbee transceivers will be the inexpensive wireless transceivers in the marketplace. As well as its small size, easy to install and high reliability of data transceiver.  [14]. Table 2 shows the characteristics of XBee Series 1.The 2.4 GHz XBee module enables easy and simple communication between a microcontroller and a serial port. This module is a very consistent system that supports point-topoint and point-to-multipoint communication.

821
This module has a power output of 1 mW. Fig.8 shows the four sorts of topologies for the ZigBee communication protocol. The simplest topology is the pair topology. In the pair topology, only two devices are connected: either an end device is connected to a coordinator or an end device is connected to a router. This topology is also known as a point-to-point topology. The second topology that can be used in the ZigBee communication protocol is the star topology. In the star or point-to-multipoint topology, the router or coordinator is placed in the middle of the network and is connected to various end devices or routers. This topology transmits information from the coordinator to wholly the end devices or routers. The mesh and tree topologies are difficult [15].

822
To install XBee module, the X-CTU software was used for its configuration. This software providing by Digi-International is recommended for the testing and configuration of the XBee module. The baud rate must first be configured for the software to communicate with the XBee module. Data can then be transmitted and displayed by the XBee module. Fig. 9 shows how an XBee module is configured [15].In this paper, X-CTU software was used because it's easy to use and permits Digi customers to exam the radio modems in the real environment with just a computer and the objects comprised with the radio modems.

Sensing Unit (Sensors)
The sensor is a device that notices and replies to some types of input from the real environment. The specific input could be photo, temperature, motion, pressure, distance or any one of a great amount of other environmental phenomena.

Lighting Sensor
Photocells (Fig. 10 A) are sensors that allow you to sense light. They are tiny, Cost less, lowpower, easy to use and don't wear out. They are a lot denoted to such as CdS cells (they are used in the manufacture Cadmium-Sulfide), light dependent resistors (LDR), and photo resistors. The Photocell is fundamentally a resistor that changes its resistive value (in ohms Ω) dependent on how much light is shining on the face winding [16].

Temperature Sensor
The LM35, (Fig. 10 B) is an integrated circuit IC. It gives changes in voltage proportional to the changes in temperature. Thus the LM35 has a benefit over linear temperature sensors calibrated in Kelvins, as the user is not necessary to subtract a large constant voltage from the output to get appropriate Centigrade scaling [17].

Motion Sensor
Passive Infrared (PIR) sensors (Fig. 10 C) let you sense motion, nearly all the time. They are used for sensing the movement of human. They are small, cheap, less energy demand, and easy to use. For that cause, they are usually found in applications and devices used in home environment or companies. They are frequently denoted to as PIR "Pyroelectric", or "IRmotion" sensors. PIRs are basically made of a pyroelectric sensor which can sense levels of infrared radiation as all objects with a temperature above absolute zero emit heat energy in the form of radiation [18].

Figure(9)XBee module configuration [15]
Eng. &Tech. Journal, Vol.34,Part (A), No.5,2016 Hardware Implementation of Wireless Sensor Network Using Arduino and Zigbee Protocol 823 Distance Sensor Ultrasonic (Fig. 10 D) is used to sense the distance, ranging module HC -SR04 provides 2cm -400cm non-contact measurement function, the ranging accuracy can extent to 3mm. The sections comprises ultrasonic transmitters, receiver and control circuit. The simple principle of work: 1. Using IO trigger for as a minimum 10 sec high level signal. 2. The Section routinely sends eight 40 kHz and sense whether there is a pulse signal back. 3. IF the signal back, over high level , time of high output IO duration is the time from sending ultrasonic to returning [19].

Power Unit
The power unit stores energy in a battery and supply suitable voltage levels. It consists of a battery and a voltage regulator [20]. An AC-DC switching power supply has been used. The input voltage is the range 100-240V AC. This voltage convertes to 9V DC, it's suitable to display Arduino board. Fig. 11 shows the block diagram of proposed network. Such network comprises four nodes and a base station. Each of end Nodes communicates with the Base Station (BS) using Zigbee protocol (in this paper XBee series 1 has been used). BS aggregates the information from each node and sends it to computer for processing and saving. The user can run any program in a computer for various applications such as to display any information on the screen like temperature, amount of lighting or any information need to be displayed. Also, it can put a threshold value for each sensor to enable alarm system for emergency situations (when the value exceeded threshold) or any function that the user need to apply. Fig. 12 shows the block diagram of each end node, each end node contains sensors, Arduino, and XBee S1.

Implementation of Proposed System
The implementation of wireless sensor network includes: end node, base station, and host computer. Base station gathers information and data from the end node and displays them on a computer screen through the serial port. This information is sent to the host computer to be processed in order to do another job such as display LED, fan, alarm, motor, etc. In this paper the LED is used as warning signal. Also, it can set a threshold for any sensor according to the level of user's desire used for the purpose of alarm when exceeding the threshold value. The base station consists of microcontroller (Arduino) and Zigbee (XBee S1). XBee has been connected to Arduino through Arduino XBee shield.
The sensor in the end node collects the environmental information and sends this information to the microcontroller (Arduino) which processes them. Lighting sensor, Temperature sensor, motion sensor, and distance sensor have been used in such system. Then the processed information has been sent to the XBee S1. The XBee S1 sends the information to the coordinator (XBee S1 in Base station). Some sensors have been connected to Arduino through Analog input pins (such as lighting sensor and temperature sensor), and others sensors have been connected to Arduino through Digital I/O pins (such as motion sensor and distance sensor). XBee S1 has been connected to Arduino through Arduino XBee shield, each End node should be provided by power supply (either by using USB of computer or by using switching power supply AC-DC).

Testing and Results
The hardware designed for the first end node is shown in Fig. 13 A. The lighting sensor (photo resistor) has been used to send the environment lighting information to the base station, A threshold has been put, if the value is exceeding 300 (300 is intensity of illumination), the base station turns on Red LED as alarm. It is possible to program this node either for sensing the intensity of light to be used in the organization of lighting or can be used to extinguish the lighting devices during the day and also can be programmed for specific periods. Fig. 13 B shows the light lamp after passing the illumination intensity at 300.

Figure( 13):Hardware design of lighting sensor
The hardware designed for the second end node is shown in Fig. 14A. The temperature sensor has been used to send the environment temperature information to the base station, 10°C has been put as a threshold value, if the value is exceeded, the base station turns on Green LED as alarm. This point can be used to send data of the temperature continuously; also a specified threshold can be set for warning at a given temperature, for example, as a fire alarm. Fig.14B shows the light lamp after the temperature exceeded the specified 10°C.

Figure (14)Hardware design of temperature sensor
The hardware designed for the third end node is shown in Fig. 15 A. The motion sensor (PIR) has been used to send the information to the base station, if there is a movement, the base station turns on Yellow LED as an alarm. As it is shown in Fig. 15 B the sensor can distinguish between human and other objects movements by sensing the temperature radiated from human body. The last end node is shown in Fig. 16 A. The distance sensor (ultrasonic) has been used to send the information to the base station; 30 cm has been chosen as a threshold, if the value exceeds it, the base station turns on Blue LED as an alarm. Fig. 16 B shows the light lamp to signify the approaching object by less than 30 cm and this distance can be controlled.

Figure (16): Hardware design of motion sensor
The implementation of overall network is shown in Fig. 17. This system has been implemented and tested with base station (coordinator) and four end nodes. All nodes can determine specific sensing times; can determine times for sleeping of nodes to reduce power consumption. In addition the threshold can be changed for various times as sensing to temperature between day and night, as well as the intensity of lighting and Times of the official working for official buildings so as to provide accuracy in useful data. Fig. 18 shows the results of four nodes on a serial monitor.  Table 3 shows the results of the four nodes: lighting, temperature, motion, and distance node. Every two seconds, the results are calculated for each node.

DISCUSSIONS:
The column of node 1 in table 1 presents changed room lighting and shows the response of sensor in this node. It is clear that the node can track the variation of lighting effectively. For the second column the node record stable value with a slight variation where the researcher decided to leave constant degrees of temperature to test the stability of such node. While the node 3 succeeded to recover the motion by moving the researcher himself near to sensor. As a result the sensor indicates variable value from 4 to 7 numbers which refer to have someone moving. Finally node 4 indicates various numbers to show the correct response for any object movement in front of the sensor of its node. Compared with other researches, it has been found that this research progress other researches used for a variety of sensors, so it can be applied for multitasking in the same network and not limited to a single task as was done in [22].
It should be noted here that there are limitations to the work of the proposed network, including the area covered by the network, which is limited and cannot be increased. However, increased number of nodes can increase the area, but with more complexity and cost of the network. Also, the size of the data is limited by the design of communications part (Zigbee protocol) and there is a problem of electrical power for the nodes deployed in large areas forcing to use the batteries and limiting their age.

CONCLUSIONS:
In this paper, a prototype of an embedded wireless sensor network has been built based on Arduino that has a microcontroller. An IEEE 802.15.4 Zigbee module is used to communicate each node with a master node to aggregate the information of the network and send it to the base station which is a computer in this paper. Four sensors are hardware implemented: lighting, temperature, distance, and motion sensor to work as security system that can be used for any building, homes, offices…..etc. The results confirm that such network is active for any type of security that can be used for various users. Such network is also flexible to choose the type of information in the time specified by the user to achieve and can enable alarm when the read value exceeds the threshold defined by the user. Testing such network in real time environments indicated that it responded well for three tasks carried out using four sensors. The number of tasks can be increased by setting more sensors based on the same manner of such network. In addition, multi-options can be added in this work reading the environments at any time automatically, describing the average value to improve the reliability, controlling the electrical home equipment like light, air condition and other by setting such network to enable home control system for energy economic and other options can be done in proposed network.