Wednesday, 4 June 2014

Home Automation System

Introduction
Have you ever dreamed of controlling your home appliances from anywhere in the world using an android app or website?? If that's the case then you are at right place. In this article I'll be explaining  my Home Automation System project. Its basically an embedded system as well as software project.

Things you should know
  • Basics of working with microcontrollers - any platform(AVR,arduino,8051)
  • Basics of database management
  • Basics of website development
  • Basics of android app development

Block diagram
(Note: for all those who don't know about database management and MySQL refer the followings before referring  next part of this article.
Tutorialspoint
MySQL official website )

This is how the project works. User will have to select an appliance and click ON or OFF button either from website or using an android app. Both will perform same task in background i.e updating data in MySQL database.

For example in database there will 1 table named Appliances. This appliances table will have 3 columns :
  1. Sr_no  (Auto increment type)
  2. Name (Varchar type) for storing name of appliance
  3. Current_status  (boolean true/false)
Whichever appliance which will be controlled , first have to registered in this table. On insertion it will get an unique  id(Sr_no column auto_increment). This id will be used for all further database stuff. When user clicks ON button Current_status column of the appliance will be updated to True using its unique id and for OFF button click it will be vice versa.





Now we should host this data some where in cloud. One way is we can buy our own server , 2nd option is to use any old computer for this purpose , or use paid hosting such as Google cloud SQL service. Once this data is available on cloud our next task is to read data using any of the following 3 options:
  1. Any old computer - here you can read the data from MySQL database in cloud using python language which has well developed library for reading MySQL database data in form of MySQL-db library/module. Then you can send this data to micro controller using RS232 (serial) communication between micro controller and pc. This can be done,either using RS232 cable (wired ) or wirelessly using Bluetooth or RF modules. Another advantage of this is you can use this computer as your MYSQL server. You don't need spend more money on hosting the database.
  2. Using arduino ethernet shield: In this case it is not possible to directly read the data  from mysql database. So basically you will have to create a php script which reads the data from MySQL database. Then you will have to call this script from arduiono ,it will read the data and then send the read data to arduino in form of HTTP response. For this you require arduino board with ethernet shield , but the advantage is it removes the need of pc and serial communication between the 2.
  3. Using linux based micro-controller boards such as Raspberry Pi,Intel Galieo etc. These boards are as good as pc plus they have micro-controller features such as IO pins. So we can do all the things which we have done in option 1 with the advantage of non requirement of serial communication.
This completes our task of reading the data from database at the microcontroller. Now we have  to set digital I/O pin of microcontroller ON/OFF based on data received.

Next task is to control the AC appliance based on output of digital I/O pin. We use Relay Switch for this purpose. This is how the relay works:
Relay consists of an electromagnet, so whenever we power it up using digital I/O pin of micro-controller it will act as magnet ,pull down the switch and completes the circuit, and appliance is switched on.

So now you can use any microcontroller as per your convenience, program it as per any 1 option and then use a relay switch to control the appliance. Hope everything works as expected for you all.

You can use the following links for referance on various topics :
Android Application development
Using MySQL with php
Google Cloud Sevices

You can download the project code from following Github repository.
Github repository

Demo:

Future developments:
  • Developing a mechanism to calculate the time for which appliance was on.
  • One of the disadvantage is suppose  main switch of appliance is off then you can't control the appliance. So we can develop some mechanism by which main switch also works through database.