The Internet Of Things is the most trending technology today that stands alongside wearables and robotics. It is a very simple concept where devices in our home or wherever they are, have the capability to communicate with each other via the internet. Usually sensors are used with this technology to pass data to the internet. You can imagine a sensor installed in your garden which uploads data like temperature, humidity, soil purity, etc to the internet, and this data will be visible to you from anywhere around the world. Or imagine home automation systems connected to the net, which can be used to control appliances in your home like lights, door locks, air conditioning, etc through a web interface or smartphone application. A lot of technologies are being developed around this concept such as independent light-weight IoT networks, protocols for passing data,etc. Here, I will show you how you can get started on making a raspberry pi home automation system that is web based using normal HTTP protocols. You will be able to control any appliance in your home from anywhere around the world when your done with this Raspberry Pi home automation tutorial.
What are the stuff required to do this project?
Hardware :
- Raspberry Pi 3 Or B with memory card preloaded with an OS.
- 5V SPDT relay.
- (Optional) WiFi dongle (pi3 did't need wifi dongle )
Software (Programming languages and OS involved):
- Microsoft Azure
- Visual Studio
- PHP.
- HTML/CSS.
- Python.
- Linux/Rasbian.
So how does it 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 ON/OFF a device.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 :index.html This is a simple Html file called main.html ,consisting 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
Raspberry Pi Home Automation systemStep 1: Preparing the html, php filesHere, the server side of the system has to be set up. If you are having your own domain, you can use the file manager service to drop these files into your server and can be used to control your IoT systems from anywhere around the world. The files to be put in your server are : main.html, button.php, buttonStatus.php and buttonStatus.txt, download them from here :- Click here 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 which writes a string to a .txt file depending on the button pressed. The .txt file stores information of the last button state.
However, if you don’t have a domain, you can simulate a domain in your local network or wifi 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 gets confined to a control range limited to your home wifi 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==>>Raspberry Pi , pin 2 (+ve 5v) to Relay VCC pin
==>> Rasberry Pi , pin 6 (GND) to Realy GND pin
==>> Rasberry pi , pin 5 to Relay IN1 Pin
==>> Relay "Common " pin to 240v Ac pin
==>> Relay "NO (Normally Open)" pin to Bulb pin
== Run the python Code in Raspberry pi
==>> Host Your WebApp in Microsoft Azure
=> Create an Azure a/c if you already have one skip this https://portal.azure.com
=> open your Azure portal and create an webapp
New -> Web + Mobile -> web app
click webapp to create your webApp
=> now give app name , that's your WebApp name that will become http://"yourwebappname".azurewebsites.net make sure it correct
=> give your subscription details
=> Now Click Create
=> open your webApp in your Azure Dashboard
=> click more and now click "Get Publish Profile"
Download the Publish Profile
==>> Upload your WebApp to Azure Cloud
=> Now open Visual Studio
File -> Open -> Website
and select your folder that our webapp file lie's
click => Build -> Publish WebApp
Click third option Import and Select file that you download from azure
Now click Publish
All done You can see the webApp will be open after the upload the complete
"make sure you have internet connection while uploading"
==>> your web app look like
==>> run the python code in your Rpi and make sure Rpi will connect to the internet
==>> Now click the Turn On the relay will on and also the lights that you connected your relay will On
Thanks all
Happy hacking <3
Comments