Introduction: Home Automation Using Web App With Raspberry Pi
In this project we are going to switch on the bulb from remote location using web services. In this we are going to use one raspberry pi interfacing with 12 bulb using 3 relay module with low level trigger. We can trigger the relay from anywhere in the world using a website. In each trigger of relay the correspondence Bulb or group of bulb will glow.
Step 1: Installation of All Software
1) Raspbian OS:
This is the recommended os for raspberry pi. You can also installed other OS from third party. Raspbian OS is debian based OS. We can install it from noobs installer. you can Download here
2) Python idle:
This is the software we get in raspbian os. For this project we have used python script.
This is the tool to make a local website publicly accessible. We’ve used this to make our local website and ssh servers accessible to any network. We'll describe it later. you can Downloadhere
we are using putty for remote access of Raspberry Pi.you can Downloadhere
This software is used to burn Raspbian Os on SD Card. you can Downloadhere
This software is used to format memory card. you can Downloadhere
Step 2: Component Used:
For this project you need :
1) Raspberry pi 3
2) Relay Module
3) 12 led Bulbs
1) Raspberry pi 3:
This is the latest version of raspberry pi. In this we have inbuilt Bluetooth and wi-fi, unlike previously we have to use Wi-Fi dongle in one of its usb port. There are total 40 pins in RPI3. Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins.)
There are 4 USB Port and 1 Ethernet slot, one HDMI port, 1 audio output port and 1 micro usb port and also many other things you can see the diagram on right side. And also we have one micro sd card slot wherein we have to installed the recommended Operating system on micro sd card.
There are two ways to interact with your raspberry pi. Either you can interact directly through HDMI port by connecting HDMI to VGA cable, and keyboard and mouse or else you can interact from any system through SSH(Secure Shell). (For example in windows you can interact from putty ssh.) Figure is given above.
2) Relay Module:
We have used 3 four channel relay module to control 12 led bulbs. As we are working with 220 volt ac we have to make sure that our connection are properly connected.Figure is given above.
Step 3: Circuit Diagram
Circuit diagram for Relay and Raspberry pi:
For complete isolation with microcontroller we can wire up our circuit as below. Here we have to remove jumper used in jd-vcc and vcc. Connection are given in figure 1
Bulb connection with relay and raspberry pi 3:
Here we are connecting our relay to one single Bulb. In this there is no optical isolation we can make it by removing jumper from vcc and jd-vcc. And by giving separate power supply to Jd-VCC.
As below the diagram I’ve just shorted all the com pin of relay and from NO we've taken wire which is going to the entire bulbs one terminal and from the second terminal of bulb it will go to the ac main and the hot line of the ac will be coming from the shorted com pin of relay. Connection are given in figure 2
Step 4: Importing Necessary Library for Raspberry Pi and Python
As we are using web services for this project so we have chosen flask python framework. There are many frameworks in python like flask, django, bottle so you can chose other one as well but in our project we are using flask framework.
So for that you have to import flask for python. Here are the steps for importing Flask
sudo apt-get install python-pip
After pip is installed, you can use it to install Flask and its dependencies
sudo pip install flask
Step 5: Code for Project
You can get the source code of this project in outr github page
Here is the link for our source code GitHub
In this project we are using two programs one is our python script and another one is html page. So what we a have to do, we have to first write our python script, you can chose any editor for that in raspberry pi like nano, vim. in our project we have used nano. you will see in figure 1
So your first command will be
sudo nano bulbdemo.py
In this just paste that code what we have posted in our github
Now create one directory named templates within the same folder where you have save your python script
Now Inside templates directory give this command
sudo nano main.html
And here just paste that main.html from our GitHub
After that you just come out of that templates directory by giving cd .. command and then run the python script
by giving the command
sudo python bulbdemo,py
If everything goes well you will get the result like these Steps:
Step 1: After Running you will see like figure 2.
Step2: go to the browser then type your Raspberry Pi IP and port no which are given in your python script. by default port no is 80. but you change according to your need. Page is display like figure 3.
Step 3: if you will click any link on that web page then correspondingly bulb will glow and you will also get the message on the terminal. Message will be shown like figure 4.
This code will work only for local network. For making it publicly accessible ( or any network) we will discus in next step.
Step 6: How to Make Your Local IP Publicly Accessible
Now everything is working fine till now. But one problem is there that you can only access your web page within local network. So that is one challenging thing. Isn't it?
Okay so we can do port forwarding and all and we can play with our router.
But other then that also we have so many option. So one of the option is pagekite. So you have to install pagekite. As in previous step you can follow the step to install pagekite. You have to run this command below to make your ip publicaly accessible
sudo pagekite.py 80 yourname.pagekite.me
Here 'yourname' will be your pagekite name which will you get when you will sign up to pagekite, and 80 is your port number.
As you can see in above figure our pagekite name is deligence so you can give any name
NOTE: pagekite free trial is only for 30 days after that you have to pay some amount of bucks as per your need
Step 7: Project Video
you can watch it out in action in the above video.
And for more projects you can visit our youtube channel here
If you have any doubt feel free to comment us below in comment section
Thanks and Regards
We have a be nice policy.
Please be positive and constructive.