BASED , LOW COST AND MODULAR HOME AUTOMATION SYSTEM

Original scientific paper Home automation systems allow the user to easily control lighting, security, ventilation, temperature etc. in the house and monitor their operation. This project aims to reduce costs, wasted time and energy consumption of home automation systems by developing a system which makes use of sufficient hardware, which everyone can easily modify and expand, due to plug & play capability and also which can be controlled not by an extra remote controller or other device, but by any device which can already access the internet. In this present study, which uses Arduino and Arduino Shields, it has been demonstrated that it is possible to control different home equipment using the Zigbee wireless protocol. Users will be able to list all these active devices and operate them via a web page broadcasted by an Arduino.


Introduction
Quickly developing technology has made its mark in all aspects of our life.The homes which people spend most of their lives in have undoubtedly had their share of this change.Today numerous electrical technology products are used in the home; television, computer, light fixtures, sound systems, air conditioning etc. are a few examples of these devices.
This increase of technological devices in the home has caused some problems.The most significant of these problems is controlling these devices.After entering a home, most devices are controlled manually by people.First the door is opened, next the lights, air conditioner or heater, television, satellite receiver, and sound system are switched on as a routine in many homes today.
In general, remote controls are used to control devices in the home.But the fact that each device has its own remote control is another problem.Due to the fact that remote controllers which can control multiple devices have been manufactured this problem solved to an extent, but the use of these controllers gets more difficult as the number of devices increases.
Devices which can be controlled by a remote are not limited to just televisions and sounds systems.Alongside these the home's heating system and lighting are among the things which people want to control remotely.
Today, home automation systems have been developed to solve all these problems.With today's home automation systems, the temperature of the home, doors, lighting, sound and vision equipment, cameras and even water flow can be controlled and monitored [1÷3].Despite the fact that these systems can do all these things, they are very expensive.Some attempts have been made to reduce costs [4].Alongside this, most currently available systems [5,6] are controlled by a special device (a dedicated controller) or a computer running a program specially written for the task.However, with the increased use of Android and iOS-based devices, applications have been developed to enable them to be used as controllers [4,2].
Many researchers have attempted to come up with practical, money-saving solutions.These solutions often use Arduino expansion cards [4,7].Among the main resons for this are the availability of many varied and inexpensive Arduino cards and many extension modules which can be used in different situations, together with varying cost, performance, size and ergonomic factors.Alongside this Zigbee modules have been used for wireless communication [1] and GSM modules for remote access [8].

Home automation system 2.1 Overview of the home automation system
The home automation system consists of a server and clients connected to it.The system along with the devices used to access it by users is illustrated in Figs. 1 and 2. At the heart of the system is the server.The server consists of an Arduino Uno controller card combined with an Ethernet and Xbee Shield.

Arduino Uno
The Arduino Uno has been developed as an opensource control card, using an ATmega328 microprocessor.There are 20 I/O pins on the board.14 of these are digital, 6 analogue.It has 32 Kb flash, 2 Kb SRAM memory and operates at 16 MHz [9].A typical household has limited needs.Therefore Arduino Uno which is a basic model is sufficient for houses and small offices.In some exceptional situations such as big mansions etc. Arduino Uno may not be sufficient.For these cases higher level models as Arduino DUE or Arduino MEGA which have more advanced and superior properties may be used.

Ethernet Shield
The Ethernet Shield is an expansion module developed to enable the Arduino to connect to computer networks and communicate via an RJ45 cable.It operates at 10/100 Mbps to the IEEE802.3afstandard.It also has a micro SD card slot [8].

Xbee Shield
The Xbee shield allows Arduino control cards to communicate wirelessly with each other using the Zigbee protocol [10].Zigbee is a protocol developed to enable many low cost, inexpensive devices to communicate seamlessly over varying topologies while consuming little power [1].For Zigbee shields to communicate with each other, as in standard computer networks, it is necessary to establish a topology and apply various settings.Wireless communication range is approximately 90 m indoors and 3 km outdoors.These range values are more than satisfactory for even villa type houses.This is why they are chosen.

Figure 3 Examples of Zigbee Network Topologies
Zigbee networks always consist of at least one coordinator, one end device or one router.One end device or router can be connected to coordinators.There can only be one coordinator on a network.The network is established by the end devices being connected directly to the coordinator or via a router (Fig. 3).In this project the star topology shown in Fig. 3 has been used.But mesh network should be used in large spaces where wireless modules might suffer from bad coverage.Star topology has been sufficient for this prototype.Since this system is designed for home automation topology presented in this paper has been chosen.If the automation of a business like a hotel had been handled mesh topology could have been more suitable.The coordinator shown in red at the centre of the system is the Arduino with the Ethernet Shield undertaking the role as web server.After the topology has been set up, it is necessary to set the baud rate at the same value in each module of the system.The baud rate is the number of characters received from the communication channel in one second [11].In this project it has been set to 9600 as there is no requirement for high bandwidth.After this the PAN (Personal Area Network) settings should be defined.The PAN ID is a numerical value specifically assigned to a Zigbee network and can be between 0-65535.All the Xbee Shields on the same network should have the same PAN ID.In this project the number 5575 has been selected randomly.Following the PAN ID the channel settings should be made.There are 12 different channels and all Xbee Shields should have the same value [7].The Xbee Shields are set to automatically select this channel as default.Also in this project the settings have been set to automatically select the channel.The home lighting system has been controlled in this home automation system prototype project.For this reason a circuit capable of adjusting the lamp's brightness (dimmer) has been included in the end device clients (Fig. 4).

Figure 4 Switching Circuit
The Switching Circuit consists of two sections.The first section is the zero crossing detection circuit which allows synchronization of the PWM signal with the 220 V amplitude sinusoidal mains electricity.If the PWM signal is used for dimming without synchronization to the mains it will cause the lamp to flicker.The zero crossing detection circuit detects when the mains electricity crosses the 0v point and activates the output to trigger the start of the PWM signal.The second section switches the 220 V amplitude mains electricity according to the PWM signal duty cycle ratio after it has been activated by the zero crossing triggered and causes the lamp to illuminate to the required brightness.
In this study adapters with 5 V DC output have been used as power supply for central server and end points.With the use of adapters dead battery problem has been resolved.However for home applications power will be supplied via a low capacity UPS.Considering all automation system units consume lower than 1 watt, power consumption will be proportional to the room and device number in the house.If as an optimistic example 25 devices are connected for a house, typical power consumption will be less than 20 W. Therefore when a black out occurs, even a low capacity UPS will be able to keep the system active for longer than 24 hours.

Operation system
The system's starting point is the home owner being able to access a web browser from his computer, smartphone or tablet.The user accesses the home automation system's control centre web interface using one of these devices.The website has been prepared to the latest HTML 5 standards which are compatible with Webkit, Gecko and Trident HTML layout motors to ensure error-free operation with all browsers.Alongside this, in preparation of the website the jQuery Mobile touch-optimized web framework has been exploited to ensure that it appears correctly on different devices.Due to the use of this framework the automation system has gained a modern interface.
Contrary to other related academic studies, with the use of the developed software, Arduino board takes up the role of the home server here instead of a standard home computer and in terms of low energy consumption and required space, the proposed Arduino based automation system has significant superiorities.This part of the system consists of an Arduino Uno control card and integrated Ethernet Shield.
The Ethernet Shield has been connected by cable to the ADSL modem which broadcasts within the home.An IPv4 standard IP number compatible with the home network has been manually set in the Ethernet Shield.This address is also important as it will be used to access the control centre.Users enter this number in the format 'http://IPno' into the address bar of their browser to connect to the system.
Port 80 has been used for broadcast as the default HTTP connection port is 80 [2].A random address has been entered as MAC address.However when entering this random value it is important that no other device on the network has the same MAC address otherwise the system will not operate.Many Ethernet Shields carry a label with this address and this should be entered into the code section but in case there is no label the method above should be used.The network configuration as it appears in the code is shown below.When the user enters the address and visits the site an HTTP request will be sent to the Arduino web server (Fig. 5).This is a standard request following certain rules [3].In order to follow these requests the Arduino is continually checking whether such requests have been received.When a request is received the website code contained on the Ethernet Shield MicroSD is sent line by line as a reply to the browser.The CSS and JavaScript library files within the code have been arranged so that they are obtained directly from the internet in order to speed up the connection and reduce load on the web server.
Once the browser has received all the codes from the web server it will display the website (Fig. 6).In this day and time devices that communicate with each other must have a security system.In the suggested system a precaution via a password screen has been planned as a first step.In the following figure the mentioned password screen has been shown.User sees the screen that shows the conditions of the lamps in the house after logging in with a user name and password.This way unauthorized access to the system is prevented.Also limitations over the control of devices to individuals with password can be applied.For example small children's access to systems that may cause harm to the house may be restricted.These studies can be integrated to the system in a more excessive way if needed.The website displays the state of the lamps in the home (Fig. 7).States are displayed as a value between 0÷100 where 0 means the lamp is off and 100 means it is at its brightest setting.
The AJAX technique has been used in the web interface.AJAX (Asynchronous JavaScript and XML) is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications in conjunction with an XMLHttpRequest object [12].Using this technique, when the user moves the brightness slider (html: range slider) a request is automatically sent from the page to the Arduino server, the lamp's brightness is changed and the new brightness value is indicated.
When this value is received by the web server (Arduino Uno) a wireless connection is established by its integrated Xbee Shield to another Arduino having an Xbee Shield (Fig. 2 -Xbee Shields and Arduino Uno real photograph).Via this connection the required brightness of the lamp is transferred wirelessly.
This brightness value is conveyed to the switching circuit that will control the lamp by the Arduino Uno control card's PWM output.According to the PWM signals received by this circuit the lamp's brightness is adjusted (Fig. 4).

Modular Construction
When the settings have been carried out on Arduino Uno+Xbee shield and a lamp connected to them, they can be connected to the system without any further settings.When the electricity is connected and switched on the name will be visible on the web interface and it will be automatically added.All currently active devices are listed on the list (Fig. 6).The names of devices listed on the list can be changed by clicking the Change Name button (Fig. 7).
As the lamps can be switched on and off by the slider on the web interface, they can also be set to switch on and off at requested times in the future.Future events which have been programmed using the timer can be seen in the list below the 'Add Timer' button (Fig. 7).During electricity cuts, renewal of battery or similar events, the time and date in the Arduino's memory will be lost.To protect against such situations, when the system is first switched on it connects to the "time.nist.gov"NTP server to refresh the time and date information.As well as controlling lamps, the system records all operations and statistics.As can be seen at the very bottom of Fig. 8, the total 'on time' of the lamp is displayed.This study distinguishes itself from other home automation systems that were stated in the literature in terms of usage of Arduino Uno + Ethernet Shield + XBee Shield as web server.As a result of this hardware preferences, the following superiorities can be mentioned over other systems: • Arduino Uno and its shield consumes significantly low power compared to standard home computers.• Arduino system costs considerably less than PCs.• (In order to prevent shut downs of the home automation system in case of electricity cuts, Arduino system requires only single 9 V battery.However a standard PC requires much larger and expensive UPS.Yet, UPS drains down much faster than the 9 V battery due to low power consumption of Arduino boards).Even in cases where laptop PCs are used, the average operation time does not extend beyond 4 to 5 hours.Since leaving laptops on the mains power all the time reduces their battery life, this will increase running cost of them.The proposed system can operate up to 1 week with a single 9 V battery.• Arduino based home automation system's turn on &turn off time and system restart times are considerably shorter than those of PC based systems'.

seconds 4 Conclusion
With this project using Arduino Uno, Ethernet Shield and Xbee Shield modules together a wireless, web-based, low-cost, modular, flexible and very low energyconsuming home automation system prototype has taken shape.With this prototype users can control the lighting system.Users access the system via the web interface.
The web interface is broadcast by the central Arduino Uno controller card and Ethernet Shield.As opposed to many other web-based projects [13,6] which broadcast the web interface from a computer, this has significantly reduced energy consumption and costs.For example, a typical Arduino Uno consumes on average 1 watt of power while a standard home computer consumes 200 W.The difference between the two system's annual electricity consumption is around 1,75 MW.
The fact that the system works on both the internet and local network means that users can access the system via the home network without needing internet access.Also due to the internet connection and web interface it is possible to access the system from any device which can access the web (computer, tablet, smart phone), and makes it possible to control the system from anywhere in the world.
The system has been developed in a modular way.This allows new lamps to be added without making any changes or additions to the system.For this it is only necessary to activate an Arduino Uno control card fitted with an Xbee shield whose settings have been made.The system will automatically discover this device and add it to the web interface.
Due to the Arduino card's modular construction and the fact that it is open-source coded means that a wide variety of shields are available for integration.Alongside this, a number of standard temperature, humidity etc. sensors which are currently available can easily be used with the Arduino.By means of these modules and sensors and the ease-of-use of the Arduino it is possible to expand the home automation system.For example: • Using a temperature sensor it is possible to display the temperature of the rooms or any required point in the house in the same way lamps are displayed; • Using a flammable gas or smoke detector a warning of fire or danger of poisoning in the house can be given [14]; • Using a humidity detector a warning can be given when it is necessary to water plants in the house or garden; • The state of doors or windows can be checked by using proximity sensors or movement detectors; • By connecting a powerful infra-red device appliances which can be remotely operated can be controlled from the web interface.

Figure 2
Figure 2 Home Automation System

Figure 5
Figure 5 HTTP Request

Figure 6
Figure 6 Login Screen

Figure 7
Figure 7 Device Options

Table 1
Home Automation System Equipment

Table 2
Power Consume

Table 3
Boot Time