Вы находитесь на странице: 1из 11

CS3082014FinalReport

SmartHome
Gladiators
TH07

RahulGupta,100050086
PrakharJain,100050024
UtkarshDiwaker,100050087
SaketTiwari,100050075






TableofContents
1.Introduction
2.ProblemStatement
3.Requirements
3.1FunctionalRequirements
3.2HardwareRequirements
3.3SoftwareRequirements
4.SystemDesign
5.WorkingoftheSystemandTestresults
5.1CommunicationbetweenArduinoandRaspberryPi
5.2Stepswhenaswitchonswitchboardisturnedon/off
5.3Stepswhenaswitchonwebsiteisturnedon/off
5.4Howaresensorvaluesupdated
5.5Automaticon/offswitchviaSensors
5.6DiscoveryProtocol:
5.7AssigningNamestoSwitches,SensorsandRooms:
5.8TestResults:
6.DiscussionofSystem
7.FutureWork
7.1Bugs
8.Conclusions
9.References


1.Introduction
The system we developed has come to be called as Smart Home collectively, including the
hardware and software components. The motivation for developing Smart Home was to provide a
central control dock for all home switches and appliances. A docklikethiswould onlyhave utilityif it
couldbeaccessedfromanywhere,beitaremotelocationorlocallyinsidethehouse.
The Smart Home system allows access to switches through a web page which can be accessed
from anywhere with an internet connection. A user can view the state of a switch in real time as it
changes. In addition to that accessing sensor values with a delay of two seconds is also available on
this system. Control of switches depending on thesensor values has alsobeenenabled. Thiskindof a
setup can be useful in all environments requiring remote and intelligent control of electrical switches,
whichcanrangefromhomestoofficesandcanevenbeappliedtoagreenhouse.
In this report first we give an overall description of the Smart Home. Next we go into specific
details of hardware, software,userinterface,communicationinterfaceand testing strategiesin section
3.Wehaveexplainedtheintricaciesofeachofthesetopicsinthecorrespondingsections.

2.ProblemStatement
We intended to comeupwith asystemwhich wouldallow us tocontroltheswitchesofourhome
remotely via a web interface. Thesystem should alsobesmartenough toautomaticallyturnon/off the
switchesdependinguponthesensorsintheroom.
We believe that this is a real life problem that have moved to using smaller portable devices
connected to the internet.The product makes the users life easier by not requiring him/her to be
physically present ata placetoswitchon/offtheelectricalappliancesandfixtures. Thisproductbrings
switchestotheusershand.
With the advent of mobile technology people the tech savvy users to remotely control their
switches.Thefunctioningandefficacyoftheproductdependsontheinternetconnectivity.

3.Requirements
3.1FunctionalRequirements
Thefunctionalrequirementsofourprojectareasfollows
1. Switcheson/offinplace
2. Remotecontrolofswitchesviaweb
3. LEDlightsforinplaceswitches
4. Interactiveuserinterface
5. Anychangesmadetotheswitchinplaceshouldbereflectedonthewebinrealtime.

3.2HardwareRequirements
1. Raspberry Pi A centralised server for a home/greenhouse which communicates with the
arduinoboardsthroughXBee.
2. Arduino Boards We use Arduino Duo as hardware interfaces that control the switches.
TheseareconnectedtotheRaspberryPioverwifiviaXBeechips.
3. XBeeXBeesareusedforcommunicationsbetweenRaspberryPiandArduinoboards.
4. Switchboard Switches are attached on the switchboard to manually turnon/off LEDs.These
switchboardsareconnectedtotheirrespectiveArduino.

3.3SoftwareRequirements
1. Arduino IDE This software is required to program the Arduino Boards according to our
requirement.
2. NodeJS Web Server Weare usingtheNodeJSWebserverto create persistentwebsockets
between the web browser and the Raspberry Pi. This helps us to have real time communication
betweenthem.
3. MySQL MySQL is used as a database management system for storing the current status of
switchesinthedatabase.ItisusedbyNodeJSwebserver.

4.SystemDesign


Figure1:SystemDesign
Figure2:SwitchboardCircuit

1. There will be asingleRaspberryPihosting acentralwebserver inthe entire home.This is shown


inFigure1.
2. Each switch board in the home comprises of an Arduino board to control the switches, a XBee
connected to the Arduino which is used to communicate with the Raspberry Pi. A detailed
switchboardcircuitisshowninFigure2.
3. Differenttypeof sensors attached tothe Arduino areused toget the sensorvalueswhicharethen
sent to the central web server(through XBee).The central web serveranalyzes these valuesand
turnstheswitcheson/offaccordingly.
4. A Web Interface, which allows the user to remotely switch on/off the appliances (LEDs in our
case). It also displays the current state (on/off) of each switch and sensor values ofeach sensor
in the home. It also provides an option to control the switches based on sensor values. This is
shown in Figure 3. So, In Figure 3, Bedroom Kids is one switchboard and Lounge Room is
anotherswitchboard.

Figure3:WebInterface

5.WorkingoftheSystemandTestresults
5.1 Communication between Arduino and Raspberry Pi
MessagesarepassedfromArduinotoRaspberryPiserverorviceversaviaXBee.Wehave
madeacustomprotocolforsupportingdifferenttypesofmessages.Themessageisoftheform:
255<switch_board_id><Message_Type><Field_A><Field_B>
a. IfMessage_Typeisequalto1,thenField_AcorrespondtoSwitch_IDandField_Bcorrespondto
Switch_State(1foron,0foroff).
b. IfMessage_Typeisequalto2,thenField_AcorrespondtoSensor_IDandField_Bcorrespondto
Sensor_Reading(between0and255).
c. Ifmessagetypeis10,thenthemessagecorrespondingtoField_Aisthenumberofswitchesand
Field_Bholdsthenumberofsensorsofaswitchboardcorrespondingtoswitch_board_id.

5.2 Steps when a switch on switch board is turned on/off


1. Whenever a user opens the website, a persistent web socket is created between the web server
andthewebbrowser.
2. Whenever a user turns on/off a switch ontheswitchboard (whichisconnectedto theArduino),a
messageispassedfromArduinotoRaspberryPiserverviaXBeeasshownin5.1aabove.
3. The message is then analyzed by the Web Server which then updates the corresponding switch
state in the MySQL database. The web server broadcasts the message to all the websockets
whichresultsinupdationoftheswitchstateonallopenwebpages.
5.3 Steps when a switch on website is turned on/off
1. Whenever a user turns on/off a switch onthewebsite,a messageispassedfrom browserto web
server through the web socket. The message contains the switch id, room id andthenewswitch
state.
2. Onreceivingthemessage,serverupdatestheswitchinfointheswitchestableinthedatabase.
3. ServerthenbroadcastsacommandtotheArduinoboardsthroughXBeesimilartothecommand
asshownin5.1a.
4. The Arduino board with the same <switch_board_id> as in the command will turn on/off the
requiredswitchaccordingtothecommand.
5. Server also writes the message to all the sockets so as to synchronize the switch state in all
browsers.

5.4 How are sensor values updated


1. Arduino sends messages of type 5.1 (b) to Web server at regular intervals (currently set to 2
seconds)throughXBee.Thesemessagescontainssensorreadings.
2. The message is then analyzed by the Web Server which then updates the corresponding sensor
value in the sensors table. The server also checks the switches which are auto configured
(Refertosection5.5)tosomesensorandtakesappropriateaction.
3. Server also broadcasts the sensor values to all the socketssoasto synchronizethesensor values
inallbrowsers.

5.5 Automatic on/off switch via Sensors


With each switch, we have added an option to auto control it. Switch can bebindto asensor for
auto on/off basedonsensorvalue.On clickingtheConfigureAuto buttonin Figure 3,a modalopens
up as shown in Figure 4.Itasksfor thesensorwhich wewanttobind withthe switch. Italsoasksfor
the rangein whichwe needto turnon/off theswitchand thedefault behaviorin therange.On clicking
Save Changes button, this information is sent to server which updates it into table
sensor_switch_mapsinMySQLdatabase.


Figure4:AutoConfiguringSwitches

5.6 Discovery Protocol:


1. WhenevertheuserclicksthebuttonDiscoverDevicesthesocketconnectionsendsouta
messagetotheserverfromthewebpage.Thisleadstotheserverbroadcastingamessageto
arduinosviaXBeeoftype5.1c(withid10).
2. Whenthearduinoreceivesthismessageitrepliesbackwithmessagoftype5.1cwiththefields
filledinwiththenumberofswitchesandsensors.
3. OnreceivingthemessagesentoutbyArduinostheserverupdatestherespectivemysqltables
withdistinctanddefaultnamesgiventoeachsensorandswitch.
4. Thisshouldbeideallyrunaftereachinstallationofanewboard,switchorsensor.

5.7 Assigning Names to Switches, Sensors and Rooms:


Afterthediscoveryprotocolhasbeenrun,theusercanassignnamestoeachoftheswitchesand
roomsdiscovered.ThisisshowninFigure5.Thestepsareasfollows
1. OnClickingtheeditbuttonprovidedatthetopoftheroomstaballthefieldsbecomewritable.
2. Theusercanthengoontoeditthesenamesaccordingtohis/herconvenience.Onceeditedthese
canbesavedattheclickofabutton,whichinitiatescommunicationtothewebserver
(RaspberryPi)overNodeJssockets.
3. FinallythesenamesareupdatedintheMySQLdatabaseontheserver.

Similarstepsfollowintherenamingofsensors,whichcanbeinitiatedbyclickingtheeditbuttononthetop
ofthesensorstable.


Figure5:EditingRoomnames,SwitchNamesandSensornames

5.8 Test Results:


Wetestedthesystembyopeningmultiplewebpagesandattachingtwoarduinoswitchboard.We
alsoattachedalightsensortochecktheuseofsensorstoswitchvaluesonoroff.Allthesetests
yieldedamaximumdelayof2secondsbetweenactionsontheboardtothewebpageandviceversa.
Thiscanbeclearlyseeninthedemonstrationvideo.

6.DiscussionofSystem

a)Whatallcomponentsofyourprojectworkedasperplan?
All except onecomponents worked asperplan.We hadresolvedtoimplementRelaydrivingcircuits
intheSRSdocumentbutendedupnotdoingitbothduetotimeconstraintsandimplementationdifficulty.

b)WhatfunctionalitieswereaddedotherthanthosediscussedinSRS?
1. Sensor Readings: We felt the need to add sensors to the system. So, we added sensors to
switch boards, which allow us to see real time sensor values on the website. Sensors can be of
differenttypeslikelightsensor,temperaturesensor,etc.
2. Automatic Switch On/Off via sensor readings: To make the system smarter, we added the
functionality to automatic switch on/off the switches based on sensor readings. Through this, a
user can bind a switch with a particular sensor and specify the sensor range in which he/she
wants to turn on/off the switch. So, when the specified sensor reading is within the specified
range,thesystemwillautomaticallyturnon/off(asspecifiedinthesettings)theswitch.

c)ChangesmadeinplanfromSRS:
Initially, We decided to use Ajax andPHPformakingclientserverapplication. We implementedit
but it seemed veryslow andweneededafastersystemfor realtime communication. Then wedecided
to go for NodeJS. NodeJS allows real time clientserver communication by making persistent web
sockets.WealsocouldntimplementtheRelayDrivingcircuits.

7.FutureWork
Wehavemainlytwocomponents:webserverhostedontheRaspberryPiandSwitchBoardattachedwith
theArduino.Bothofthesecomponentsarereusable.Ifonecanunderstandtheworkingofthissystem
correctly,theneitherofthesecomponentscanbecombinedwithsimilarothercomponents.Forexample,
thesamewebserverhostedonthesameRaspberrypiconnectedtothesameXBeemodulecanbeused
withanotherswitchboarddesignedbysomeoneelsejustbyfollowingthesamecommunicationprotocol.

Possibleextensionsoftheproject:
1. Scheduling:Aschedulingalgorithmcanbeimplementedontheservertoscheduleeventslike
turningon/offswitchesaccordingtothetime,turningonthelightwhenyoureturnfromhomeis
oneexampleforthisusecase.
2. Additionofavideo/audiofeed:Wecouldprovideamodalwiththevideofeedofthehomeor
greenhousetomonitorthelocationforsafetyand/ormaintenancepurposes.wecouldalso
similarlyaddaudiofeedifrequired.
3. UseofMux/Demux:Asarduinohaslimitednumberofpins,multiplexeranddemultiplexercan
beusedtoincreasethenumberofswitchesattachedtoarduino.
7.1 Bugs
Apartoffutureworkcouldberesolvingthebugsthatexistinthesystem.Theonlybuginthe
presentsystemisthatthepageneedstoberefreshedbeforethesensornameisreflectedonallother
webpageswherethesocketconnectionexists,thisisnotanissueinthecaseofroomsandswitches
orswitchsensormaps.

8.Conclusions
Webelievethattheprojecthasachievedeaseofswitchingelectricalconnectionsfortheuser,ina
costeffectiveandefficientway.Thecontroloftheswitchesusingthesensorsensuresthesmartness
ofthesystemasawhole.TherealtimedatadeliveryusingNodeJswasachallengingaffairto
implementresultinginarealtimeresponsivesystem.Thecircuitryusedwasdesignedand
implementedwiththegoalthatagooddemonstrationofthesystemcouldbegiven,butaneedfor
usingrelaydrivingcircuits.ThecommunicationbetweenXBeesbydefiningourowncommandsand
protocolswasachallengingtask.Allthesecanbeputtouseinfuturework.
Thepresentsystemcanbeusedtoswitchelectricalfixtureseithermanuallyorwithsensor
constraints.Thediscoveryprotocolhasbeenimplementedtoprovidetheusertheeaseofattaching
newsensorsandswitcheswithoutchangingArduinocode.Theuseoftheeditbuttontochangenames
hasbeenimplementedtoensurethatnocodechangesareneededontheRaspberryPiserver.The
circuitrydescribedabovecanbeusedtomakerelevantconnectionsinarealsystembeingdeployed.
Overallthisprojecthasbeenagreatlearningexperienceforalltheteammembers.Wehave
learntalotregardinghowanEmbeddedSystemisdifferentfromanyothersoftwaredevelopement
project.Wehavealsolearntdifferenttechnologiesintheprocess.Inadditiontothiswehavealso
learntthestagesofprototypingaproductinanentrepreneurialenvironmentandgottenapeekinto
howprojectsaredealtwithwhenthereisanenduserinvolved.

9.References
NodeJS:http://nodejs.org/
JadeTemplateLibrary:http://jadelang.com/
BootstrapCSSFramework:http://getbootstrap.com/
AjaxJavascriptLibrary:https://api.jquery.com/jQuery.ajax/
ArduinoProgrammingLanguage:http://arduino.cc/en/Reference/HomePage#.UxBr89YKgg

Вам также может понравиться