ESP8266 Fan Control (Poor Man's A/C)

Place your projects here
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

ESP8266 Fan Control (Poor Man's A/C)

Post by Zim »

fan.jpg
2021-02-10 18_19_00-Forum - Annex WiFI RDS — Mozilla Firefox.jpg

Code: [Local Link Removed for Guests]

'Zim's fan control
onHtmlReload create_page 'one wire sensors are connected to gpio2
gosub create_page
gosub man_off
timer0 3000, update_temps
wait

create_page:
cls
PIN.MODE 0, OUTPUT
PIN(0)= 1
butt$ = "background-color:lightblue;text-align:center;display:block;width:180px;height:80px;font-size:40;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height:1"
tbox$ = "background-color:white;text-align:center;display:block;width:180px;height:32px;font-size:14;font-weight:bold"
stat$ = "off"
stat2$ = "Fan is Manual "+ stat$
ot = val(tempr$(2,1))                            'First sensor
outside$ = str$(ot,"%2.1f")+ " Outside Temp."
it = val(tempr$(2,2))                            'Second sensor
inside$ = str$(it,"%2.1f")+ " inside Temp."
ac = 0
HTML "<center>"
HTML TEXTBOX$(inside$ ,"txtb1")
CSS cssid$("txtb1" , tbox$)
HTML "<br>"
HTML TEXTBOX$(outside$ ,"txtb2")
CSS cssid$("txtb2" , tbox$)
HTML "<br>"
HTML TEXTBOX$(stat2$ ,"txtb3")
CSS cssid$("txtb3" , tbox$)
HTML "<br>"

HTML BUTTON$("Auto", auto_mode, "but1")   ' "but1" is the ID
CSS cssid$("but1", butt$) 'the same ID is used here
HTML BUTTON$("Off", man_off, "but2")   ' "but2" is the ID
CSS cssid$("but2", butt$) 'the same ID is used here
HTML BUTTON$("On", man_on, "but3")   ' "but3" is the ID
CSS cssid$("but3", butt$) 'the same ID is used here
HTML BUTTON$("Exit", exitt, "but4")   ' "but4" is the ID
CSS cssid$("but4", butt$) 'the same ID is used here
HTML "</center>"
refresh
return

update_temps:
ot = val(tempr$(2,1))                            'First sensor
outside$ = str$(ot,"%2.1f")+ " Outside Temp."
it = val(tempr$(2,2))                            'Second sensor
inside$ = str$(it,"%2.1f")+ " inside Temp."
if ot < (it - 2) then ac = 1                      'gives 2 deg swing
if ot > = it then ac = 0
if ot < 10 then ac = 0                            'too cold safety
refresh
return

auto_mode:
'onHtmlReload create_page
'stat2$ = "Auto Mode Fan is "+ stat$
if ac = 1 then gosub auto_on else gosub auto_off
refresh
timer1 6000, auto_mode
return

auto_on:
onHtmlReload create_page
PIN.MODE 0, OUTPUT
PIN(0)= 0
stat$ = "on"
stat2$ = "Auto Mode Fan is "+ stat$
refresh
return

man_on:
timer1 0
onHtmlReload create_page
stat2$ = "Fan is Manual On"
PIN.MODE 0, OUTPUT
PIN(0)= 0
refresh
return

auto_off:
PIN.MODE 0, OUTPUT
PIN(0)= 1
stat$ = "off"
stat2$ = "Auto Mode Fan is "+ stat$
refresh
return

man_off:
timer1 0
stat2$ = "Fan is Manual Off"
PIN.MODE 0, OUTPUT
PIN(0)= 1
refresh
return

exitt:
cls
end
You do not have the required permissions to view the files attached to this post.
Post Reply