Sunteți pe pagina 1din 7

HOMEAUTOMATI

ON

OBJECTI
VE
I
nt hi
spr
ojectwearegoingtomakeahomeaut omat
ionsystem
usi
ngESP8266Wi FimoduleandArduinoUno.Usi
ngthi
swewi ll
beablet
ocontroll
ight
s,el
ectr
icfanandotherhomeappl
iances
thr
oughawebbr owserusi
ngy ourPC..

METHODOLOGY
I
nt hisprojectwearegoingtomakeahomeaut omat i
onsy stem
usingESP8266Wi FimoduleandAr dui
noUno.Usi ngthiswewi ll
beabl etocont r
oll
ight
s,el
ectr
icfanandot herhomeappl i
ances
throughawebbr owserusi
ngy ourPCormobi le.TheseACmai ns
applianceswi l
lbeconnect
edtor el
ayswhichar econtrol
ledbyt he
arduino.Usercansendcommandsandt hi
swi l
l st
artworking.

HARDWAREREQUI
RED
ESP-01istheoneoft hemostpopul arESP8266modul eav ai
labl
e
i
nt hemarket.ESP8266i saselfcontai
nedSoCwi thint
egrated
TCP/IPstackwhichhel psanymicrocontr
oll
erhavingUARTt o
accessawi f
inetwork.ItcanactasbothWi Fiaccesspointaswell
asaWi Ficl
ient.I
tispre-pr
ogrammedwi thATcommands, sowe
caneasil
yaccessandconf i
gureitusi
ngami crocont
rol
ler.

ESP8266r unson3.3Vandi t
sinputpinsarenot5Vt ol
erant.So
weneedt oreducethe5Vout putoftheArduinoTxpinto3. 3Vby
usi
ngv ol
tagedividi
ngresi
storst
oconnectt oRxpinofESP8266
module.ArduinoTTLinputpinswilldet
ect3.3Vaslogi
chi gh,so
wecandi r
ectlyconnect3.
3Vout putofESP8266Txt oArdui noRx
pi
n.
SOFTWARESETUP
Pr
ogr
am

Ar
dui
noSket
ch

#i
ncl
ude<Sof
twar
eSer
ial
.h>/
/Incl
udi
ngt
hesof
twar
eser
ial
li
brar
y

#def
ineDEBUGt
rue

SoftwareSer
ial
esp8266(
2,3)
;//Thi
swi
ll
maket
heAr
dui
nopi
n2ast
heRXpi
nand
Arduinopin3astheTX.Soft
wareUART

/*Soy ouhavet
oconnecttheTXoftheesp8266t
othepi
n2oft
heArdui
noandtheTX
oftheesp8266tot
hepin3oft heAr
duino.Thi
smeanst
haty
ouneedt
oconnectt
heTX
l
inefrom t
heesptotheArdui
no'spi
n2* /

v
oidset
up(
)

Ser
ial
.begi
n(9600)
;//Set
ti
ngt
hebaudr
atet
o9600

esp8266.
begi
n(9600);/
/Seti
taccor
dingt
oyouresp’
sbaudr
ate.Di
ff
erentesp’
shav
e
dif
fer
entbaudrates.

pi
nMode(
11,
OUTPUT)
;//Set
ti
ngt
hepi
n11ast
heout
putpi
n.

di
git
alWr
it
e(11,
LOW)
;//Maki
ngi
tlow.

pi
nMode(
12,
OUTPUT)
;//Set
ti
ngt
hepi
n12ast
heout
putpi
n..

di
git
alWr
it
e(12,
LOW)
;//Maki
ngpi
n12l
ow.

pi
nMode(
13,
OUTPUT)
;//Set
ti
ngt
hepi
n13ast
heout
putpi
n.

di
git
alWr
it
e(13,
LOW)
;//Maki
ngpi
n13l
ow.

sendDat
a("
AT+RST\
r\n"
,2000,
DEBUG)
; /
/Thi
scommandwi
l
lresetmodul
eto
defaul
t

sendDat
a("
AT+CWMODE=2\
r\n"
,1000,
DEBUG)
; /
/Thi
swi
l
lconf
igur
ethemodeas
accesspoi
nt
sendDat
a("
AT+CI
FSR\
r\n"
,1000,
DEBUG)
; /
/Thi
swi
l
lgeti
paddr
essandwi
l
lshow
i
t

sendData(
"AT+CIPMUX=1\
r\n"
,1000,
DEBUG)
; /
/Thi
swi
l
lconf
igur
etheESP8266f
or
multi
pleconnect
ions

sendDat
a("
AT+CI
PSERVER=1,
80\
r\n"
,1000,
DEBUG)
;//Thi
swi
l
lsett
heser
veronpor
t
80

v
oidl
oop(
)

i
f(esp8266.
avai
l
abl
e()
)//Checki
ngt
hatwhet
hert
heesp8266i
ssendi
ngamessageor
not(Soft
wareUARTData)

i
f(
esp8266.
fi
nd(
"+I
PD,
")
)

del
ay(
1000)
; /
/Wai
ti
ngf
or1sec

i
ntconnect
ionI
d=esp8266.
read(
)-
48;/
/Subt
ract
ing48f
rom t
hechar
act
ert
oget
t
henumber.

esp8266.
fi
nd(
"pi
n="
); /
/Adv
anci
ngt
hecur
sort
othe"
pin="

i
ntpi
nNumber=(
esp8266.
read(
)-
48)
*10;
//Get
ti
ngt
hef
ir
stnumberwhi
chi
spi
n13

pi
nNumber+=(esp8266.
read(
)-
48)
; / /Thi
swil
lgetthesecondnumber
.For
example,
ift
hepi
nnumberi s13thent
he2ndnumberwil
lbe3andt henaddi
ttot
he
fi
rstnumber

di
git
alWr
it
e(pi
nNumber
,!di
git
alRead(
pinNumber
));
//Thi
swi
l
ltoggl
ethepi
n

/
/Thef
oll
owi
ngcommandswi
l
lcl
oset
heconnect
ion

St
ri
ngcl
oseCommand="
AT+CI
PCLOSE="
;

cl
oseCommand+=connect
ionI
d;

cl
oseCommand+="
\r\
n";
sendData(
closeCommand,
1000,
DEBUG)
; /
/Sendi
ngt
hedat
atot
heESP8266t
o
cl
osethecommand

Str
ingsendData(
Stri
ngcommand,
consti
ntt
imeout
,bool
eandebug)/
/Funct
iont
osend
thedat
at otheesp8266

St
ri
ngr
esponse="
";

esp8266.
pri
nt(
command)
; /
/Sendt
hecommandt
otheESP8266

l
ongi
ntt
ime=mi
l
li
s()
;

whi
l
e((t
ime+t
imeout
)>mi
l
li
s()
)//ESP8266wi
l
lwai
tforsomet
imef
ort
hedat
ato
r
ecei
ve

whi
l
e(esp8266.
avai
l
abl
e()
) /
/Checki
ngwhet
herESP8266hasr
ecei
vedt
hedat
aor
not

charc=esp8266.
read(
); /
/Readt
henextchar
act
er.

r
esponse+=c; /
/St
ori
ngt
her
esponsef
rom t
heESP8266

i
f(
debug)

Ser
ial
.pr
int
(response)
; /
/Pr
int
ingt
her
esponseoft
heESP8266ont
heser
ial
moni
tor
.

}
r
etur
nresponse;

RESULT
HomeAut omationisabl
etocont r
oll
ightsandmanyelectr
ic
appli
ances.ESP8266andAr duinotogetheract
sasaWebSer ver
andwewi ll
sendcontrol
commandst hroughaWebBr owserli
ke
GoogleChromeorMozi l
laFi
ref
ox.ESP8266i st
heoneofthe
mostpopularandlowcostwifimoduleav ai
labl
eint
hemar ket
today.Youcanreadymoreaboutithere,ESP8266–Wi Fi
SoC.

CONCLUSI
ON

TheHomeAut omationi
sveryusefulforpeopl
eintodaysli
fe.
nowever
yonewant seasyl
if
esot hismakesaper sonli
feeasi
er.
Byusi
ngthi
saper soncaneasil
yswi t
chonandswi tchofft
he
el
ect
ri
cappli
ancesasperhis/herneed.

Submi
tt
edBy
PushkarJat

Shi
vangi
Shar
ma
Pr
agy
aYadav

Pr
it
am Si
ngh

2nd YearCSPGI

S-ar putea să vă placă și