close

How To Make Home Automation Projects Using Raspberry Pi Computer

Home Automation projects

The concept of home automation is not just a fantasy anymore. Nowadays, people are actually able to do it. Here in this article, we will focus how knowledge about the open source hardware, Raspberry Pi can help you with home automation projects. We know there are many home automation projects out there. But still, we never thought we can do one for ourselves easily.
Without only focusing on attractive home automation lightings and automated blinds. We can also use this system to know about the water leaks, to check if a door is open, and monitor other things inside the house. A home automation kit will be using an Arduino as well as a Raspberry Pi computer. There will be many sensors too. To make it more comfortable you can set alerts for you when something happens or you can just monitor everything from your phone.
So let’s start from the beginning.

What is Raspberry Pi?

A Raspberry Pi computer is a kind of open source hardware. It is a credit card sized computer. Raspberry Pi was designed for education purpose, inspired by 1981 BBC Micro. It was created as a low-cost device that will help in improving programming skills and hardware understanding at a beginner’s level. But because of some factors like the small size and affordable price, electronic enthusiasts took it for projects that require more than a basic controller. One can also make the home automation projects using a Raspberry Pi.

Raspberry Pi might be slower than your laptop or desktop but it is still a complete Linux computer and can provide all the functions expected, at low-power consumption. It was designed to work on Linux operating system, but being open source software Linux is optimized to a version that is compatible with Raspberry Pi computer. The most popular examples of such operating systems are Raspbian, based on the Debian operating system and Pidoraa, which is based on the Fedora operating system.

How does the Raspberry Pi work?

Before you get a home automation tutorial, you need to know how the Raspberry Pi works.
A Raspberry Pi consists of a primary chip which runs the main components of the board like CPU, graphics, memory, USB controller, etc. Many of the Raspberry Pi projects are said to be open and are well-documented as well. You can modify and build a raspberry pi computer yourself.
There are two raspberry pi models, A and B. They are named after the BBC Micro which was released in Model A and a Model B. The A comes with the specifications of 256MB of RAM and one USB port. While the B comes with 512 MB of RAM, 2 USB ports, Ethernet port for connection to a network. The A is cheaper and uses less power than B.
Upgrades for the raspberry pi computer come with minor improvements and slight modifications. The upgraded versions are A+ and B+. They come with increased no. of USB ports and improved power consumption, especially in B+.
That’s all about the Raspberry Pi. Now let’s get started with home automation projects.

Here is the list of the components required to build a home automation system

* Raspberry Pi computer (model B with memory card preloaded with an OS)
* Bc547 Transistor
* 5V SPDT relay
* 1N4001 diode
* Solder dot prototyping board
* 9V battery
* WiFi Dongle (optional)
* USB keyboard
* HDMI monitor

There are some software (Programming languages and OS involved) that you need to be familiar with.

Let’s build the Home Automation system

The whole system will mainly consist of two obvious parts i.e. Server and Client. The server is going to be the web interface that will consist of buttons and User Interface to allow you to turn a device ON or OFF. It will have a PHP file, HTML file, and a .txt file too. A major example of UI (User Interface) is DIY Hacking loT Implementation. It is a simple file called main.html having two buttons. The pressing of buttons will cause the execution of a PHP file called button.php. This Raspberry Pi home automation software serves as an API(Application Programming Interface) to store data on buttonStatus.txt file. The action of the button being pressed is recorded in this buttonStatus.txt text file.
In this Raspberry Pi project, client is the part where Raspberry Pi comes into the role. Here its GPIO pin is connected with a relay circuit. A python program is executed to ‘Post’ a URL link using urlib2. The Pi reads the URL link constantly. The URL link is a PHP file buttonStatus.php. It works as an API to read the contents of bottonSTatus.txt. Then the python program comes into play. It tests if the string obtained is ON or OFF and hence switches the corresponding relay via its GPIO pin.
Raspberry Pi Home Automation system.
Let’s begin with some of the important steps for Raspberry Pi home automation projects which will turn your home into a smart home.

STEP 1

What we need to do first is preparing the HTML and PHP files mentioned above.
First of all the server side of this system is to be set up. For doing so you need your domain which will let you control your loT systems from anywhere around the world. You can easily drop the files in the server using file manager. You can download the required files from internet. These files include main.html, button.php, buttonStatus.php and buttonStatus.txt. Then copy the raspbi.py to your raspberry pi computer. You can learn HTML and PHP for beginners and it will be sufficient
By using a service called xampp, you can stimulate a domain in your local network or WiFi. By the use of this service, you can use your PC as a local web service. All you need to do next is dropping all those HTML, PHP and .txt files to “/htdocs/xampp directory.

STEP 2

The second step for the Raspberry Pi home automation projects is setting up of the relay circuit. A BC547 transistor acts as a switch to turn an appliance ON or OFF. To protect the transistor from reverse voltages created in the relay coil you can use a 1N4001 diode. The circuit can be powered using a 5V supply from the Raspberry Pi computer or you can also use an external battery as an alternative.
Home automation circuit relay

STEP 3

The final step for our home automation projects is obviously setting up of Raspberry Pi.
You must first load an OS (a modified and compatible version Linux) to your raspberry pi computer. The default OS used in the raspberry pi is Raspbian. You can use the command “starx” in the terminal to use the GUI for pi. Use wifi dongle for wireless connectivity and you can also use the wifi config app on the desktop of your Raspberry Pi computer to connect to wifi network. Then copy the file raspbi.py on it. The Pi runs this python program continuously. Open the file using nano raspbi.py and edit the line
response=urllib2.urlopen(‘https://diyhacking.com/projects/IOTautomation/buttonStatus.php’
by replacing the link within ‘ ‘ by the link generated using xampp or your domain. Use the comanfsudo python raspbi.py” to initiate the program. A raspberry pi computer can be used without a monitor. SSH or secure shell is used to control the pi from a PC. All you need is the IP aaddress of your pi. To get the IP address of your pi use command “ifconfig”. To initiate the secure shell service use the command “sudo/etc/init.d/ssh start”.

Controlling Lights with Home Automation System

The above steps will create the exoskeleton of your Raspberry Pi home automation project. All the elements of this system will follow the above pattern. One example of such elements is controlling lights. The tools that you will need for it are:-

HARDWARE
*Raspberry Pi Model 2
*Relay channel module boards
*Raspberry Pi jumper cables
*Crosshead screwdriver
*Wire snippers
*Wire strippers
*Craft knife
*Soldering Iron
*Cable flex

SOFTWARE
*Raspbian
*PuTTY
*Nmap
*FileZilla
*Win32Disklmager

Now we are all set to start our project with Raspberry Pi computer. First of all, we need to design a GUI. It is really simple. With a little knowledge about HTML and PHP we can easily design the GUI. The second thing after designing GUI is wiring. We need to connect the Lamp, relay connectors, and Raspberry Pi. Once all the connections are made properly we can test our lamp with the relay channel. At last,  you need to add the web functionality to the setup. You have to turn your Raspberry Pi computer to a web server  to host the pre-designed GUI

If you have more ideas about home automation projects, feel free to drop it in our comment section. Follow us for more updates.

 

 

Tags : home automationhome automation projectsopen sourceraspberry piraspberry pi computer
Ankush Mishra

The author Ankush Mishra

Ankush is a student of VIT, Vellore. He is a gamer and a tech geek as well. He loves to read and write about new innovation and Technology. You can reach him through our contact page.

Leave a Response