Home automation with Raspberry Pi

Spread the love

Today we are living in 21st century. It is necessary to control the home from desire location. Home automation is the control of any electrically and electronics device in our home and office, whether we are there or away. There are hundreds of products available that allow us to control over the devices automatically with using raspberry pi model either by remote control or even by webpage. This Home automation system provide the user with remote control of various lights and appliances within their home. This system is designed to be low cost and expandable allowing a variety of devices to be controlled. Home automation and benefits will be focus on and how this can be achieved through the use of the raspberry pi.


The internet of things (IOT) is the network of physical objects–devices, vehicles, buildings and other items embedded with electronics, software, sensors and network connectivity that enable these objects to collect and exchange data. The Internet of Things allows objects to be sensed and controlled remotely across existing network infrastructure, creating opportunities for more direct integration of the physical world into computer-based systems, and resulting in improved efficiency, accuracy and economic benefit. When IOT is augmented with sensors and actuators, the technology becomes an instance of the more general class of, cyber physical system which also encompasses technologies such as smart grids, smart homes, intelligent transportation and smart cities. Each thing is uniquely identifiable through its embedded computing system but is able to interoperate within the existing internet infrastructure. Experts estimate that the IOT will consist of almost 50 billion objects by 2020.

Home automation is the control of any or all electrical devices in our home or office.  There are many different types of home automation system available. These systems are typically designed and purchased for different purposes. In fact, one of the major problems in the area is that these different systems are neither interoperable nor interconnected. There are number of issues involve when designing a home automation system. It should also provide a user friendly interface on the host side, so that the devices can be easily setup, monitored and controlled.  In smart home systems, the internet is also use to ensure remote control. For years, the internet has been widely used for the processes such as surfing on the pages, searching information, chatting, downloading and installation. By the rapid developments of new technologies, monitoring, controlling services have been started to be served along with internet as an instrument providing interaction with machinery and devices. The system can be used in several places like banks, hospital, labs and other sophisticated automated system, which dramatically reduced the hazards of unauthorized entry. The main reason to develop this system is to save time and man power along with maintaining security and convenience.

There are many methods by which we can implement home automation system .Some of the method are listed below:

  1. Home Appliances Control Using A Remote Control
  2. Home Appliances Control Using DTMF
  3. Home Appliance Control Using Free Hand Gesture
  4. Home Appliance Control Using Internet And Radio Connection
  5. Wireless Browser Based Device Control Using Raspberry Pi


  1. Home Appliances Control using a Remote Control:

The lights, fans can be automatically turned on/off with the help of a remote where there will be a sensor instead of going near to a switch board and putting on/off the switch. Companies like Legrand and Gold Medal already started these kinds of control system and they are at present available in the market.


  1. Home Appliances Control using DTMF:

In this method, the control of home appliances can be done even though when we are elsewhere just by using the DTMF tone generated when the user pushes mobile phone keypad buttons or when connected to a remote mobile.


  1. Home Appliance Control Using Free Hand Gesture:

This is a type of home appliance control system where the person must be present in sight to the appliance that is needed to be controlled and a predefined gesture must be used to turn on the device and another gesture must be used by us to turn off the device. The performance of the proposed system is done with a hardware embedded in that particular device.


  1. Home Appliance Control Using Internet and Radio Connection:

In this system, the control of home appliances can be done from a remote are with an option from a local server, using the Internet and radio connection. This system is accomplished by personal computers, interface cards, radiotransmitters and receivers, microprocessors, ac phase control circuits, along with window-type software and microprocessor control software.


  1. Wireless Browser Based Device Control Using Raspberry Pi: We can observe this research paper that the appliances controlling through the web browser integrated with the ARM11 microcontroller. The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools. The Raspberry Pi has a Broadcom BCM2835 system on a chip, which includes an ARM1176JZF-S 700 MHz, Video Core IV GPU, and was originally shipped with 256 megabytes of RAM, later upgraded to 512 MB. It does not include a built-in hard disk or solid-state drive, but uses an SD card for booting and long term storage. In this system, we use the raspberry Pi model as a controller. The Raspberry is a credit card sized minicomputer. There are different types of raspberry pi model available in the market, Such as Model A, Model B, Model B+ out of which we uses Model B+.



Smart home is not a new term for science society, it is been used from decades. As electronic technologies are advancing, the field of home automation is expanding fastly. There were various smart systems have been proposed where the control is via Bluetooth, internet etc. Bluetooth capabilities are good and most of current laptop/desktops, tablets, notebooks and cell phones have built-in adaptor that will indirectly reduce the cost of the system. But it limits the control to within the Bluetooth range of the environment while most other systems are not so feasible to be implemented as low cost solution. In Wi-Fi based home automation system is presented. It uses a PC (with built in Wi-Fi card) based web server that manages the connected home devices. The system supports a wide range of home automation devices like fans, lights, other home appliances. A similar architecture is proposed in where the actions are coordinated by the home agent running on a PC. Other papers such as also presented internet controlled systems consisting of a web server, database and a web page of websites for interconnecting and handling the devices.



Figure 1. Shows the basic block diagram of the system. With the help of this system we can monitored and controlled the various equipment that are connected to the relay circuit via the input from raspberry pi model as well as from the WEBIOPI. Whenever the system is turned on, the current lighting data of the home are read and written to the data base and then transferred to the user interface. So, one can easily know the current situation of rooms and change in the state of the lights.


  1. Raspberry pi
  2. Relay circuit


  • Raspberry pi: For this paper, of course you will need a Raspberry Pi board. The version of the board or the model (A or B) doesn’t really matter, but keep in mind that you will have to connect it to your local network, so you will need a Wi-Fi dongle if you are using the A model which doesn’t have an Ethernet port. In this paper, we used a Raspberry Pi model B with the Wi-Fi dongle. The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools. The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC), which includes an ARM1176JZF-S 700 MHz, Video Core IV GPU, and was originally shipped with 256 megabytes of RAM, later upgraded to 512 MB. It does not include a built-in hard disk or solid-state drive, but uses an SD card for booting and long-term storage.

Now also to check that your Raspberry Pi is connected to the Internet. Again, this will depend on your configuration (Ethernet or Wi-Fi) and your router, but is usually really easy. If you are using the Ethernet connection, simply connect a cable to your router and it should work automatically. If you’re using a Wi-Fi dongle, the easiest solution is to use the GUI that comes with Raspbian to find your wireless network and enter your WEP/WPA password.

Figure 2. Raspberry pi

  • Realy circuit:

A Relay is electrically operated switches, which allow low power circuits to switch a relatively high voltage or current on/off. For a relay to operate a suitable pull in and holding current should be passed through its coil. Relay coils are designed to operate from a particular voltage often its 5V or 12V. The function of relay driver circuit is to provide the necessary current energize the relay coil, when a LOGIC 1 is written on the PORT PIN thus turning on the relay. The relay is turning off by writing LOGIC 0 on the port pin. In our system four relays are used for device control.


  • Make a web-based Raspberry Pi home automation system using normal HTTP protocols.


 The Internet of Things is the most trending technology today, alongside wearables and robotics. The concept is simple: Devices in your home (or wherever they are) have the capability to communicate with each other via the internet. This technology usually uses sensors to pass data to the internet. Imagine a sensor installed in your garden that uploads data like temperature, humidity, and soil purity to the internet, and this data is visible to you from anywhere in the world. Or imagine home automation systems you can use to control appliances in your home like lights, door locks, and air conditioning through a web interface or smartphone application. A lot of technologies are being developed around this concept, such as independent lightweight IoT networks and protocols for passing data. Here, I will show you how to make a web-based Raspberry Pi home automation system that will allow you to control any appliance in your home from anywhere in the world using normal HTTP protocols.

Relay circuit components


  • How Does Web-based Automation Work? 

You can consider the whole system to be composed of two parts: server and client. Here, the server is the web interface, consisting of buttons and UI (user interface) that will allow you to turn a device on or off. It consists of PHP files, HTML files, and a .txt file (to store data). The server usually stores information regarding the button press on the page (ON/OFF) on a .txt file. An example of this UI is DIY Hacking IoT Implementation. This is a simple HTML file called main.html, which consists of two buttons. The clicking of the buttons will trigger the execution of a PHP file called button.php. This program serves as an API (application programming interface) to store data on to a text file called buttonStatus.txt. The data is a string: “ON” if ON button is clicked, and “OFF” if OFF button is clicked. Thus the current button-press state is recorded in the text file buttonStatus.txt.


Raspberry Pi home automation Block Diagram


The client side consists of a Raspberry Pi with a relay circuit connected to its GPIO pin. The Pi runs a Python program which is used to “post” a URL link using urllib2. That is, the Pi constantly reads the contents of a URL link. Here, the URL link is another PHP file called buttonStatus.php. This PHP file serves as an API to read the contents of the text file buttonStatus.txt. After reading the data, the Python program checks if the string obtained is “ON”/”OFF” based on which it switches ON/OFF the relay respectively via its GPIO pin.


Step 1: Preparing the HTML and PHP Files 

First, the server side of the system has to be set up. If you have your own domain, you can use the file manager service to drop these files into your server and control your IoT systems from anywhere in the world. The files to be put on your server are main.html, button.php, buttonStatus.php, and buttonStatus.txt. Download them from the DIY Hacking – Raspberry Pi home automation systemtutorial and extract it. The program raspbi.py is the Python program, which is to be copied to your Raspberry Pi. If you are new to HTML and PHP, don’t worry. This project will need only a basic understanding of the two languages, spending some time on a few tutorials — HTML for beginners, PHP for beginners, and reading the code would be sufficient. The HTML file consists of a basic UI with two buttons. On button press, it triggers a PHP program that writes a string to a .txt file depending on the button pressed. The .txt file stores information of the last button state.

If you don’t have a domain, you can simulate a domain in your local network or Wi-Fi using a service called xampp. It is very simple. The instructions for using it are here: Xampp Web Server Emulator Windows and Xampp Web Server Emulator Linux. Using xampp, you can use your PC as a local web server. However, the IoT systems get confined to a control range limited to your home Wi-Fi network. Drop the HTML, PHP and .txt files into the /htdocs/xampp directory.


Step 2: Setting Up the Relay Circuit for the Raspberry Pi Home Automation System

 A small relay circuit is to be made, to switch an appliance ON/OFF. It consists of a BC547 transistor, which acts as a switch. The transistor triggers the relay when it receives a voltage at its base from the GPIO pin of Raspberry Pi. A 1N4001 diode is used to protect the transistor from reverse voltages created in the relay coil. The circuit can be powered either using the 5V supply from the Raspberry Pi or using an external battery. Use the schematic and pinout diagram below to make the connections for the Raspberry Pi home automation system.

 Step 3: Setting Up the Raspberry Pi

If you have a brand-new Raspberry Pi and are looking for instructions to load the OS into the SD card, use installing the OS for Raspberry Pi. The default OS used with the Pi is Raspbian. To use the GUI for Pi, use the command “startx” in the terminal. You can use an Edimax Wi-Fi dongle for wireless connectivity, use the Wi-Fi config application on the desktop of your Pi to scan and connect to the Wi-Fi network. The Raspberry Pi is used to continually run a Python program called raspbi.py — copy this file to your Pi. Before executing this file, open the file using “nano raspbi.py” and edit the line that says:

“response=urllib2.urlopen (‘http://maker.pro/education/buttonStatus.php’)” by replacing the link within ‘ ‘, with your own link generated either through xampp or your own domain on using the command “sudo python raspbi.py”. This will initiate the program.

You can use the Raspberry Pi without a monitor by using SSH. SSH (Secure Shell) can be used to control the Pi remotely from a PC on the same home network if you know the IP address of your Pi. Use “ifconfig” command on your Pi to find the IP address. Use “sudo /etc/init.d/ssh start” to initiate the SSH service. Then, from a remote PC using putty software (for Windows), open the terminal and enter the command “sudo ssh ipaddress -l pi”. “ipaddress” is replaced with the actual IP address you obtained for the Pi in the range –

Connect the relay circuit to the Raspberry Pi. You need to connect GPIO pin no: 5 and 6 (GND) to the circuit, as shown in the schematic. Please note: Raspberry Pi uses GPIO pins 5 and 6 to get into safe mode by shorting them together. Hence, please use any other GPIO other than 5 by editing the Python program to prevent booting into the safe mode. This video shows the Raspberry Pi home automation system in action:

This system can be modified to control anything in your home from anywhere in the world. You can even use it to collect data from sensors and view them from anywhere. Protocols like MQTT and APIs of thingspeak can be used for a large number of devices and sensors to standardize the communication protocol.

    • Low cost and expandable allowing a variety of devices to be controlled
    • Saves money and energy
    • All in one user friendly system
    • This system contain Raspberry pi as a controller so the system contain all the advantages of it.
    • This is noise free system.


    • Human error
    • Reliability



These kinds of home automation systems are required because human can make mistakes and forgot to switch off the appliances when there is no use and in this case, they are useful in order to utilize the power effectively and also in a secured manner.

MeenaG Staff

Internet of Things Enthusiast

Leave a Reply