so I decided to install motorized ducts until I seen the price! $180 each in Canada! Then you need a control of sorts. I always look for reasons to play with Annex, so I set out
to make my own. I cut six pieces of pipe, threaded 6 pieces of 1/8" welding rod and bought 6 damper plates. I found 6 servo motors MG996R on ebay for cheap.
The output from the ESP is adequate for the servo motor's PWM sensor input, but the servo likes its own separate power source 4.5 - 6v.
The two power supplies must have a common ground. The old IDE hard drive external power supplies work good for this as they have 2 outputs. One is 5v for the servos, and the other is 12v
which is easily regulated down to 3.3/5v for the ESP.
All my six motors are connected in parallel.
The signal strength is to help find an ideal location for the ESP. I like this so much I will use it on all my projects.
See the Duct.mp4 video attached
Code: [Local Link Removed for Guests]
'Zims Duct control
'You need to create a file and upload it to ESP called "mode.txt" for position memory
onHtmlReload create_page
onhtmlchange create_page
gosub create_page
wait
create_page:
cls
pin.mode 5, output
servo.setup 1, 5
out = 0
in = 0
calc = 0
butt$ = "background-color:lightblue;text-align:center;display:block;width:310px;height:50px;font-size:24;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height:1"
butt2$ = "background-color:lightblue;text-align:center;display:block;width:200px;height:80px;font-size:24;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height:1"
tbox$ = "background-color:white;text-align:center;display:block;width:310px;height:50px;font-size:24;font-weight:bold"
tbox2$ = "background-color:white;text-align:center;display:block;width:60px;height:60px;font-size:24;font-weight:bold"
'file.save "/mode.txt", str$(0) ' you could uncomment this line for your first run, then recomment it. That would create the memory file
setmode = val(file.read$("/mode.txt"))
B$ = ""
B$ = B$ + |<!DOCTYPE html><html><body><style>|
B$ = B$ + |body {background-color: black;}|
B$ = B$ + |</style><center>|
B$ = B$ + |<center>|
B$ = B$ + |<p><font color = 'white', font size = '6'>Basement Duct Control</font></p>|
B$ = B$ + |</center>|
B$ = B$ + BUTTON$("Fully Closed", mode0, "but0")
B$ = B$ + cssid$("but0", butt$)+ | <br>|
B$ = B$ + BUTTON$("1/4 Open", mode1, "but1")
B$ = B$ + cssid$("but1", butt$) + |<br>|
B$ = B$ + BUTTON$("1/2 Open", mode2, "but2")
B$ = B$ + cssid$("but2", butt$) + |<br>|
B$ = B$ + BUTTON$("3/4 Open", mode3, "but3")
B$ = B$ + cssid$("but3", butt$) + |<br>|
B$ = B$ + BUTTON$("Fully Open", mode4, "but4")
B$ = B$ + cssid$("but4", butt$) + |<br>|
B$ = B$ + |<table align='center' width='310' height='70' bgcolor='lightgreen' border='1' cellpadding='8'>|
B$ = B$ + |<center><th>|
B$ = B$ + BUTTON$("Check Signal Strength <span>%</span>", sig, "but5")
B$ = B$ + cssid$("but5" , butt2$)+ |</center></th>|
B$ = B$ + |<center><th>|
B$ = B$ + TEXTBOX$(out ,"txtb2") 'signal strength
B$ = B$ + cssid$("txtb2" , tbox2$)+ |</center></th>|
B$ = B$ + |</table></center>|
B$ = B$ + |</center></body></html>|
HTML B$
if setmode = 0 gosub mode0
if setmode = 1 gosub mode1
if setmode = 2 gosub mode2
if setmode = 3 gosub mode3
if setmode = 4 gosub mode4
refresh
return
sig: ' This is optional to check your ESP AP signal strength. Very helpful to find a good location for ESP
mySSID$ = "ESP blabla" ' define your ESP8266 SSID here
wifi.scan
while wifi.networks(a$) = -1
wend
NL$ = chr$(10) ' this means New Line
for z=1 to word.count(a$, NL$) 'browse all the lines
z$ = word$(a$, z,NL$) 'extract line by line
s$ = word$(z$, 1, ",") ' extract the SSID (the 1st argument)
if (s$ = mySSID$) then ' if the SSID is the one we search
RSSI$ = word$(z$, 3, ",") ' extract the SSID (the 3rd argument)
'print s$, RSSI$
end if
next z
in = val(RSSI$)
calc = (in + 100) / 100 * 110 'formula to go from db to percent (with a little 10% tweak)
out = int(calc)
refresh
return
mode0:
file.save "/mode.txt", str$(0)
servo 1, 5 'closed
html cssid$("but0", "box-shadow: 12px 0px red;")
html cssid$("but1", "box-shadow: 3px 3px black;")
html cssid$("but2", "box-shadow: 3px 3px black;")
html cssid$("but3", "box-shadow: 3px 3px black;")
html cssid$("but4", "box-shadow: 3px 3px black;")
refresh
return
mode1:
file.save "/mode.txt", str$(1)
servo 1, 25 '1/4 open
html cssid$("but0", "box-shadow: 3px 3px black;")
html cssid$("but1", "box-shadow: 12px 0px red;")
html cssid$("but2", "box-shadow: 3px 3px black;")
html cssid$("but3", "box-shadow: 3px 3px black;")
html cssid$("but4", "box-shadow: 3px 3px black;")
refresh
return
mode2:
file.save "/mode.txt", str$(2)
servo 1, 50 '1/2 open
html cssid$("but0", "box-shadow: 3px 3px black;")
html cssid$("but1", "box-shadow: 3px 3px black;")
html cssid$("but2", "box-shadow: 12px 0px red;")
html cssid$("but3", "box-shadow: 3px 3px black;")
html cssid$("but4", "box-shadow: 3px 3px black;")
refresh
return
mode3:
file.save "/mode.txt", str$(3)
servo 1, 75 '3/4 open
html cssid$("but0", "box-shadow: 3px 3px black;")
html cssid$("but1", "box-shadow: 3px 3px black;")
html cssid$("but2", "box-shadow: 3px 3px black;")
html cssid$("but3", "box-shadow: 12px 0px red;")
html cssid$("but4", "box-shadow: 3px 3px black;")
refresh
return
mode4:
file.save "/mode.txt", str$(4)
servo 1, 100 'fully open
html cssid$("but0", "box-shadow: 3px 3px black;")
html cssid$("but1", "box-shadow: 3px 3px black;")
html cssid$("but2", "box-shadow: 3px 3px black;")
html cssid$("but3", "box-shadow: 3px 3px black;")
html cssid$("but4", "box-shadow: 12px 0px red;")
refresh
return