in , ,

Raspberry Pi Home Automation

Let us build a home automation system that can control electrical appliances such as lights, fans, gates etc suing our mobile phone from anywhere around the world. All you need is a Raspberry Pi, some relays and an android phone. Lets get started.

Components Required

Click on them to purchase from amazon

Instructions

Step 1 – The Relay

Relays are switching circuits that can close and break circuits mechanically. That means it can control an electrical circuit by closing and breaking connections in that circuit.

As you can see, there are mainly 5 terminals in a relay. Two for energizing the coil, one Common terminal, a Normally Closed terminal which will be connected to the Common terminal when the coil is not energized and a Normally Open terminal which will be in contact with the Common terminal when the coil is energized.

This is how the relay works. In our case, we will be connecting

  • GPIO pins to One End of Coil
  • Ground to other End of Coil
  • Phase of Main Power Supply to The Common terminal or Pole
  • One Terminal of bulb (Or other electrical Appliance) to Normally Open Terminal
  • And the Other Terminal of Bulb to Neutral Point of Main Power Supply

 

Since the Output of Raspberry Pi GPIO pins are 3.3V, you will have to buy a 3.3V Relay. You can purchase the relay board of 4 relays that is compatible with Raspberry Pi from here or click on the image.

Step 2 – The Raspberry Pi

Raspberry Pi is a low cost single board computer which can be used for robotics, home automation etc.

Get your Raspberry Pi from Here

Download and burn an OS to a micro SD card and insert it into the raspberry Pi. In this project, I used Raspbian OS. You can download the OS by clicking the below link Download

Now power it up. Now fire up your terminal and create a password for the user ‘pi’ by executing the command

sudo passwd pi

Now perform and update and upgrade by running

sudo apt update -ysudo apt upgrade -y

Now you can connect GPIO pins to Relay board

  • GPIO 11 to Relay 1 Controlling Device 1
  • GPIO 13 to Relay 2 Controlling Device 2
  • GPIO 15 to Relay 3 Controlling Device 3
  • GPIO 29 to Relay 4 Controlling Device 4

Step 3 – The Network

Connect your Raspberry Pi to a WiFi router or Wired network and make sure it is connected by checking whether it is getting an IP address from the switch. Connect your mobile phone to the same network and make sure there is connectivity between the mobile phone and the raspberry pi. You can confirm it by pinging your mobile phone from your Raspberry Pi by pinging to your mobile phone

ping <ip address of mobile phone>

Take a note of the IP address of the raspberry Pi as we will be using it in the future.

ifconfig

Step 4 – Connections

Raspberry Pi should be provided with 5V.

For this project we will be using 4 GPIO pins to control the devices. 11, 13, 15 and 29 all goes directly to the 4 relays input.

Step 5 – Setting Up the Listener

Best WiFi Routers of 2018

Here is a list of World’s Best WiFi Routers of the year 2018. Make sure you grab one of them for High speed, Long Range, and Stable Internet connection.

Top 5 WiFi Routers 2018

 

Now all you have to do is setup a listener on the Pi. Download the sketch from the link below and save it as a file named “automation.py”

The Code

Download

Run the script by running

python automation.py

Step 6 – Install RootSaid WiFi Command Center from Google PlayStore

RootSaid WiFi Command Center is a simple light weight android application that can be used to control robots and home appliances over WiFi. All you have to do is connect your mobile phone to the network, enter the IP address and Port of the server (the home automation system) and control it using the On Off buttons. Click here to know more about this App.

Click Here to Download this app from Playstore.

Step 7

Now all you have to do is start the App, enter the IP address of the Pi and port it is listening to (5050).

Load the IP and Port using the link button and navigate to the Home Automation Tab.

Thats it, you can now control devices connected to your raspberry pi using this simple app and turn it on and off.

Coming Soon – Controlling It from Outside the LAN over the Internet. Subscribe to RootSaid to get live updates. 

Rate the Project

Did you find this page useful? Help us to improve by rating this page.

Rating
Raspberry Pi Home Automation
4.4 rating based on 12,345 ratings
Overall rating: 4.4 out of 5 based on 223 reviews.

Written by Jithin

12 Comments

Leave a Reply
  1. Awesome Project.
    Thanks for sharing. I will be doing this for my final year project.

    • Thank You Rishikesh,
      Glad to hear that. If you get stuck somewhere, let me know it in the comments.

  2. file “automation.py” line 9 in
    GPIO.setmode(GPIO.BOARD)
    AttributeError: ‘module’ object has no attibute ‘setmode’

    Why am I getting this error?

    • There are so many reasons for this error buddy. Mostly because the GPIO library which is used to control the GPIO is is not properly installed.
      Which OS are you using?

    • you have to install GPIO library manually..
      That will solve your problem

  3. how to download a listener on pi as mentioned in step 4

  4. Just want to know if i can also use my phone as a hotspot to provide internet connection, or do i necessarily need a router to connect the devices?

  5. L293D Motor Driver with 12 V.

    Did not get what needs to be done for above line.

  6. do you mean port 26? i cant find 29 anywhere

Leave a Reply

Your email address will not be published. Required fields are marked *

Kali Linux 2017.3 Features, Tools, Download and Upgrade

Arduino and Raspberry Whatsapp group

RootSaid now on WhatsApp – Arduino and Pi WhatsApp Group