| 1 |
.PS |
| 2 |
# ColdControl1.m4 |
| 3 |
#https://www.researchgate.net/journal/Sensors-1424-8220/publication/361484962_Design_of_a_Smart_IoT-Based_Control_System_for_Remotely_Managing_Cold_Storage_Facilities/links/6806de36df0e3f544f442241/Design-of-a-Smart-IoT-Based-Control-System-for-Remotely-Managing-Cold-Storage-Facilities.pdf |
| 4 |
|
| 5 |
log_init |
| 6 |
sinclude(ics.m4) |
| 7 |
sinclude(../ics.m4) |
| 8 |
sinclude(UNO.m4def) |
| 9 |
sinclude(../UNO.m4def) |
| 10 |
sinclude(tst.dim) |
| 11 |
s_init(ColdControl) |
| 12 |
divert(-1) |
| 13 |
|
| 14 |
define(`ESP8266',`[ Chip: box wid 9*lg_pinsep ht 16*lg_pinsep |
| 15 |
foreach_(`x',`Pin`'eval(m4Lx+15): line from Chip.ne+(0,(m4Lx-16)*lg_pinsep) \ |
| 16 |
right pinlen "eval(m4Lx+15)" above; "x" rjust at last line.start', |
| 17 |
3V3,GND,TX(GPIO1),RX(GPIO3),D8(GPIO15),D7(GPIO13),D6(GPIO12), |
| 18 |
D5(GPIO14),GND,3V3,D4(GPIO2),D3(GPIO0),D2(GPIO4),D1(GPIO5),D0(GPIO16)) |
| 19 |
foreach_(`x',`Pin`'m4Lx: line from Chip.nw+(0,-m4Lx*lg_pinsep) \ |
| 20 |
left pinlen "m4Lx" above; "x" ljust at last line.start', |
| 21 |
AO(ADC0),RSV,RSV,SD3(GPIO10),SD2(GPIO9),SD1(MOSI), CMD(CS),SDO(MISO), |
| 22 |
CLK(SCLK),GND,3V3,EN,RST,GND,VIN) ]') |
| 23 |
|
| 24 |
define(`LEDQ',`[ B:dot; resistor(up_ dimen_,,E); rlabel(,R) |
| 25 |
diode(up_ dimen_/2 from Here+(0,-dimen_/5),L) |
| 26 |
{ em_arrows(,135,dimen_/3) with .Tail at last [].nw}; dot |
| 27 |
{ground(,,S,0); "GND" at last line.s below ljust} |
| 28 |
Q: bi_tr(up_ dimen_*5/4,,,E) with .E at Here; "BC547" at last [].e ljust |
| 29 |
line from Q.B left_ dimen_/3 |
| 30 |
resistor(down_ to (Here,B),,E); llabel(,R); line to B |
| 31 |
T: Q.C ]') |
| 32 |
|
| 33 |
define(`Relay',`[ |
| 34 |
C: relaycoil(S,,,ifelse(`$2',,U,D)) |
| 35 |
B: box wid elen_ ht C.ht at C ifelse(`$2',,+,-)(elen_/4,0) |
| 36 |
`"Relay"' at B.n above |
| 37 |
ifelse(`$2',,`C1: 1/4 < B.nw, B.ne >; C2: 1/4 < B.sw, B.se > |
| 38 |
S1: 5/6 < B.nw, B.ne >; S2: 5/6 < B.sw, B.se > |
| 39 |
S: dswitch(ifinstr(`$1',R,`down_ from S1 to S2,R',`up_ from S2 to S1,'),WBCD)', |
| 40 |
`C1: 3/4 < B.nw, B.ne >; C2: 3/4 < B.sw, B.se > |
| 41 |
S1: 1/6 < B.nw, B.ne >; S2: 1/6 < B.sw, B.se > |
| 42 |
S: dswitch(ifinstr(`$1',R,`up_ from S2 to S1,R',`down_ from S1 to S2,'),WBCD)') |
| 43 |
"G5Q-1A" at 1/2<C2,S2> below |
| 44 |
]') |
| 45 |
|
| 46 |
define(`Fan',`[ |
| 47 |
C: circle at (0,0) ifelse(`$1',,,`diam `$1'') |
| 48 |
arc from (Rect_(C.rad,-30)) to (Rect_(C.rad,210)) with .c at (0,-C.rad) |
| 49 |
arc to (Rect_(C.rad,90)) with .c at (Rect_(C.rad,150)) |
| 50 |
arc to (Rect_(C.rad,-30)) with .c at (Rect_(C.rad,30)) |
| 51 |
]') |
| 52 |
|
| 53 |
define(`pins',`for_(1,`$1',1, |
| 54 |
`ifinstr(`$2',L, |
| 55 |
`L`'m4x:line left_ del from ((m4x*2-1)/(2*(`$1')))<last box.nw, last box.sw>') |
| 56 |
ifinstr(`$2',R, |
| 57 |
`R`'m4x:line right_ del from ((m4x*2-1)/(2*(`$1')))<last box.ne,last box.se>') |
| 58 |
')') |
| 59 |
|
| 60 |
define(`thermometer',`[eleminit_(`$1') |
| 61 |
tx = rp_len; ty = tx/6 |
| 62 |
{box ht_ ty rad ty/2 wid_ rp_len-ty} |
| 63 |
{circle diam 2*ty fill_(0) at rvec_(rp_len-ty,0)} |
| 64 |
{box ht_ last box.ht_ wid_ last box.wid_/4 \ |
| 65 |
at rvec_(rp_len-ty*5/2,0) fill_(0)} |
| 66 |
for i=1 to 5 do {{ move to rvec_(ty*i/2,0) |
| 67 |
line from rvec_(0,-ty/2) to Here }} |
| 68 |
]') |
| 69 |
|
| 70 |
define(`thsen',`[ |
| 71 |
B: box ht boxwid*5/6 |
| 72 |
pins(4,L) |
| 73 |
"T \& RH" above at B.n; "DHT22" below rjust at B.se |
| 74 |
for j=1 to 5 do { |
| 75 |
box wid B.wid/10 ht B.wid/15 at B.nw+((j-1/2)*B.wid/5,-(1/2)*B.ht/4) |
| 76 |
for i=2 to 4 do { |
| 77 |
box wid B.wid/10 ht B.wid/12 at B.nw+((j-1/2)*B.wid/5,-(i-1/2)*B.ht/4) |
| 78 |
} |
| 79 |
} |
| 80 |
]') |
| 81 |
|
| 82 |
define(`S8',`[ |
| 83 |
B: box wid dimen_*3.2 ht dimen_*2 |
| 84 |
foreach_(`x',`move to B.nw-(0,(m4Lx-1/2)*B.ht/5) |
| 85 |
ifelse(x,nul,,{"x" ljust}; L`'m4Lx: line left_ del)', |
| 86 |
UART\_R/T,UART\_TXD,UART\_RXD,nul,BCAL\_IN) |
| 87 |
foreach_(`x',`move to B.ne-(0,(m4Lx-1/2)*B.ht/5) |
| 88 |
ifelse(x,nul,,{"x" rjust}; R`'m4Lx: line right_ del)', |
| 89 |
ALARMLOC,nul,PWM\_1KHZ,nul,DVCC\_OUT) ]') |
| 90 |
|
| 91 |
define(`s_pin', |
| 92 |
`Pin`$2': line from Chip.se-(`$1'*lg_pinsep,0) down_ pinlen |
| 93 |
rs_box(`$2') with .e at last line.c-(textoffset,0) |
| 94 |
rs_box(`$3') with .s at last line.start+(0,textoffset)') |
| 95 |
|
| 96 |
define(`RC1602A',`[ Chip: box ht 6*lg_pinsep wid 14*lg_pinsep |
| 97 |
foreach_(`x',`Pin`'eval(m4Lx+1): line from Chip.ne-(m4Lx*lg_pinsep,0) \ |
| 98 |
up_ pinlen |
| 99 |
rs_box(eval(m4Lx+3)) with .e at last line.c-(textoffset,0) |
| 100 |
rs_box(x) with .n at last line.start-(0,textoffset)', RS,R/W,E) |
| 101 |
line from 3rd last"".nw+(-1bp__,0) down_ 3rd last "".ht/2 |
| 102 |
line from last"".nw+(-1bp__,0) down_ last "".ht |
| 103 |
Pin3: line from Chip.ne-(4*lg_pinsep,0) up_ pinlen |
| 104 |
rs_box(3) with .e at last line.c-(textoffset,0) |
| 105 |
rs_box(Vo) with .n at last line.start-(0,textoffset) |
| 106 |
foreach_(`x',`Pin`'eval(m4Lx+6): line from Chip.ne-((m4Lx+5)*lg_pinsep,0) \ |
| 107 |
up_ pinlen |
| 108 |
rs_box(eval(m4Lx+6)) with .e at last line.c-(textoffset,0) |
| 109 |
rs_box(x) with .n at last line.start-(0,textoffset)', |
| 110 |
DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7) |
| 111 |
Pin1: line from Chip.w left_ pinlen |
| 112 |
rs_box(1) with .s at last line.c+(0,textoffset) |
| 113 |
rs_box(VSS) with .w at Chip.w+(textoffset,0) |
| 114 |
Pin2: line from Chip.e right_ pinlen |
| 115 |
rs_box(2) with .s at last line.c+(0,textoffset) |
| 116 |
rs_box(VDD) with .e at Chip.e-(textoffset,0) |
| 117 |
foreach_(`trm',`s_pin(patsubst(trm,:,`,'))',6:16:K,7:15:A/VEE,8:A:A1,9:K1:K) |
| 118 |
]') |
| 119 |
|
| 120 |
define(`Ammonia',`[ |
| 121 |
B: box; "MQ-3" at B.se rjust below |
| 122 |
line left_ del then up_ del from 3/4<B.sw,B.nw>; "5 V" above |
| 123 |
"VCC" at last line.start ljust |
| 124 |
line left_ del from 1/4<B.sw,B.nw> |
| 125 |
{"GND" at last line.start ljust} |
| 126 |
ground(,,S); "GND" at last line.s ljust |
| 127 |
C: circle diam B.ht*7/8 at B.e-(B.ht/2,0) |
| 128 |
circle diam B.ht*5/8 at C |
| 129 |
circle diam B.ht*3/8 at C |
| 130 |
circle diam B.ht/4 at C |
| 131 |
Out: 1/6<B.se,B.ne>; "out" at Out below ljust |
| 132 |
"C${}_2$H${}_4$" at B.n+(0,2bp__) above |
| 133 |
]') |
| 134 |
|
| 135 |
divert(0)dnl |
| 136 |
|
| 137 |
finalscale = 0.72 |
| 138 |
textht = 0.1/finalscale |
| 139 |
textoffset = 1.5bp__ * 2 |
| 140 |
ifpostscript(,latexcommand({\scriptsize\sf)) |
| 141 |
|
| 142 |
define(`pinlen',`20bp__') |
| 143 |
define(`lg_pinsep',(1.2*lg_pinsep)) |
| 144 |
del = lg_pinsep |
| 145 |
|
| 146 |
ESP: ESP8266; `"ESP8266"' at ESP.Chip.se below rjust |
| 147 |
line from ESP.Pin24.end right del then down ESP.Pin24.y-ESP.Pin16.y |
| 148 |
ground(,,S); "GND" at last line.s below |
| 149 |
dot(at ESP.Pin17.end+(del,0)); line to ESP.Pin17.end |
| 150 |
"3.3 V" at ESP.Pin25.end ljust |
| 151 |
LEQ1: LEDQ with .B at ESP.Chip.nw+(dimen_+del,dimen_/2) |
| 152 |
line from LEQ1.B to (ESP.Pin30.end,LEQ1.B) then to ESP.Pin30.end |
| 153 |
LEQ2: LEDQ with .B at ESP.Chip.ne+(del*3/2,dimen_/2+del) |
| 154 |
line from LEQ2.B to (ESP.Pin29.end.x+del,LEQ1.B.y+del) |
| 155 |
continue to (Here,ESP.Pin29) then to ESP.Pin29.end |
| 156 |
line from LEQ1.T up 2*del then right_ ESP.Pin30.end.x-LEQ1.T.x +6*del \ |
| 157 |
then down_ del; right_ |
| 158 |
R1: Relay(R) with .C1 at Here |
| 159 |
R2: Relay with .B.n at R1.B.s+(0,-dimen_) |
| 160 |
line from R1.S.end to R2.S.end; dot(at last line.c); line right_ del |
| 161 |
"220 V" ljust |
| 162 |
line from R1.C.V1 to R2.C.V2; dot(at last line.c); line left_ del |
| 163 |
"5 V" rjust |
| 164 |
line from LEQ2.T right_ R2.C2.x-LEQ2.T.x-3*del |
| 165 |
continue to (Here.x,R2.C2.y-del) then right_ R2.C2.x-Here.x then to R2.C2 |
| 166 |
line from R1.S1 up del then right_ 2*del |
| 167 |
|
| 168 |
Hum: [F: Fan; box wid F.wid ht F.ht at F; pins(3,LR)] with .L1.end at Here |
| 169 |
"Hum. unit" at Hum.s below |
| 170 |
line from R2.S2 down del then right_ 2*del |
| 171 |
|
| 172 |
Con: [B: box; pins(3,LR) |
| 173 |
circle diam B.ht/3 with .n at 1/4 < B.nw, B.ne > |
| 174 |
circle diam B.ht/3 with .n at 3/4 < B.nw, B.ne > |
| 175 |
circle diam B.ht/3 with .s at 3/4 < B.sw, B.se > |
| 176 |
circle diam B.ht/3 with .s at 1/4 < B.sw, B.se > ] \ |
| 177 |
with .L3.end at Here |
| 178 |
"Control unit" at Con.s below |
| 179 |
|
| 180 |
line from ESP.Pin23.end to (R2.w.x+4*del,ESP.Pin23.y) |
| 181 |
T1: box wid boxht with .w at Here; "T1" at T1.e ljust "DS1822" ljust |
| 182 |
"out" at T1.w ljust |
| 183 |
T2: box wid boxht with .w at (T1.w,ESP.Pin28) |
| 184 |
"T2" at T2.e ljust "DS1822" ljust; "out" at T2.w ljust |
| 185 |
line from ESP.Pin26.end right del then up T2.w.y-ESP.Pin26.y then to T2.w |
| 186 |
line from T2.s to T1.n; dot(at last line.c); ground(,,S,0) |
| 187 |
"GND" at Here+(dimen_*5/6,0) |
| 188 |
line from 1/4 <T2.nw,T2.sw> left del; "5 V" above |
| 189 |
line from 1/4 <T1.nw,T1.sw> left del; "5 V" above |
| 190 |
|
| 191 |
thermometer(up_ T2.ht*3/4) at 3/4<T2.w,T2.e> |
| 192 |
thermometer(down_ T1.ht*3/4) at 3/4<T1.w,T1.e> |
| 193 |
|
| 194 |
M1: thsen with .L2.start at (T1.w.x,ESP.Pin21.y-2*del) |
| 195 |
ground(at M1.L4.end,,S); "GND" at last line.s below |
| 196 |
"5 V" above at M1.L1.end |
| 197 |
line from M1.L2.end left del |
| 198 |
continue to (Here,ESP.Pin22) then to ESP.Pin22.end |
| 199 |
M2: thsen with .n at M1.s+(0,-2*del) |
| 200 |
ground(at M2.L4.end,,S); "GND" at last line.s below |
| 201 |
"5 V" rjust at M2.L1.end |
| 202 |
line from M2.L2.end left 2*del |
| 203 |
continue to (Here,ESP.Pin21) then to ESP.Pin21.end |
| 204 |
|
| 205 |
CO2: S8 with .B.nw at (M2.L1.end.x-2*del,M2.s.y-dimen_) |
| 206 |
"G0" at CO2.s above; "G$+$" at CO2.n below |
| 207 |
`"Senseair S8"' at CO2.B.se rjust below |
| 208 |
line up del from CO2.n; "5 V" above |
| 209 |
line down del from CO2.s; ground(,T,S); "GND" at last line.s below |
| 210 |
line from CO2.R1.end up del |
| 211 |
Spkr:speaker(U,dimen_*2/3) with .In1 at Here |
| 212 |
"CO${}_2$" at Spkr.n+(0,10bp__) "Alarm" |
| 213 |
line down del*3/2 from Spkr.In3; ground(,T,S) |
| 214 |
"GND" at last line.s below |
| 215 |
line from CO2.L1.end to (CO2.L1.end,ESP.Pin20) then to ESP.Pin20.end |
| 216 |
line from CO2.L2.end left del |
| 217 |
continue to (Here,ESP.Pin19) then to ESP.Pin19.end |
| 218 |
line from CO2.L3.end left 2*del |
| 219 |
continue to (Here,ESP.Pin18) then to ESP.Pin18.end |
| 220 |
|
| 221 |
LCD: RC1602A with .Pin14.start \ |
| 222 |
at (ESP.Pin7.end.x-4*del,ESP.s.y-dimen_-del*3/2) |
| 223 |
{"LCD" at 1/2<LCD.Chip.sw,LCD.PinK1.start> below |
| 224 |
`"RC1602A-GHW-ESX"' at LCD.Chip.se+(10bp__,0) rjust below} |
| 225 |
RV: potentiometer(right_ dimen_) with .T1 at LCD.Pin15.end |
| 226 |
{"RV" at RV.R.c+(0,-dimen_/12) below |
| 227 |
"1" at RV.R.c+(dimen_/4,0) above ljust} |
| 228 |
line from RV.End to (LCD.Pin2.end,RV.End); dot |
| 229 |
line from LCD.Pin2.end to Here chop 0 chop -del; "5 V" ljust |
| 230 |
line from RV.Start to (LCD.Pin1.end,RV.Start); dot |
| 231 |
line from LCD.Pin1.end to Here; ground(,,S); "GND" at last line.s below |
| 232 |
|
| 233 |
line from ESP.Pin27.end right_ 2*del;continue to (Here.x,LCD.Pin12.end.y+del) |
| 234 |
continue to (LCD.Pin12,Here) then to LCD.Pin12.end |
| 235 |
line from ESP.Pin11.end left del then down ESP.Pin11.y-ESP.s.y; "3.3 V" ljust |
| 236 |
line from ESP.Pin15.end left del; dot |
| 237 |
line from ESP.Pin10.end left 2*del then down ESP.Pin10.y-ESP.s.y |
| 238 |
ground(,T,S); "GND" at last line.s below |
| 239 |
line from ESP.Pin14.end left 2*del; dot |
| 240 |
line from ESP.Pin9.end to (LCD.Pin13,ESP.Pin9) then to LCD.Pin13.end |
| 241 |
line from ESP.Pin7.end to (LCD.Pin14,ESP.Pin7) then to LCD.Pin14.end |
| 242 |
|
| 243 |
LEQ3: LEDQ with .B at (ESP.Pin1.end.x-del,LEQ1.B.y) |
| 244 |
line from LEQ3.B to (LEQ3.B,ESP.Pin4) then to ESP.Pin4.end |
| 245 |
R3: Relay(,R) with .se at LEQ3.Q.B-(2*del,0) |
| 246 |
line from R3.C1 up del; continue to (LEQ3.T,Here) then to LEQ3.T |
| 247 |
line from R3.S2 down_ del; "220 V" below |
| 248 |
line from R3.C2 down_ del; "5 V" below |
| 249 |
line from R3.S1 up_ del then left_ R3.S1.x-R3.w.x+del then down R3.ht+3*del |
| 250 |
F1: Fan with .n at Here |
| 251 |
ground(at F1.s,,S); "GND" at last line.s below |
| 252 |
"Ventilation" at F1.e ljust "unit" ljust |
| 253 |
|
| 254 |
line from ESP.Pin5.end left_ 7*del |
| 255 |
A1: Ammonia with .Out at Here |
| 256 |
A2: Ammonia with .Out at A1.Out-(0,dimen_*2) |
| 257 |
line from A2.Out right_ del; continue to (Here,ESP.Pin6) then to ESP.Pin6.end |
| 258 |
|
| 259 |
line from ESP.Pin8.end left_ 5*del; continue to (Here,ESP.s) \ |
| 260 |
then left_ del |
| 261 |
LightS: [ B: box ht boxwid; "BH1750" at B.se rjust below |
| 262 |
circle diam B.ht/5 at B.nw+(B.ht/5,-B.ht/5) |
| 263 |
circle diam B.ht/5 at B.sw+(B.ht/5, B.ht/5) |
| 264 |
foreach_(`x', |
| 265 |
`Pin`'m4Lx: line right_ pinlen from B.se+(0,(m4Lx-1/2)*B.ht/5) "m4Lx" above |
| 266 |
"x" at last line.start rjust',ADDR,SDA,SCL,GND,VCC) |
| 267 |
] with .Pin2.end at Here |
| 268 |
{"Light" at LightS.B.n above} |
| 269 |
line from LightS.Pin3.end to (LCD.Pin13,LightS.Pin3); dot |
| 270 |
line from LightS.Pin5.end up del; "5 V" above |
| 271 |
line from LightS.Pin4.end down LightS.Pin4.y-LightS.s.y |
| 272 |
{dot(at (Here,LightS.Pin1))} |
| 273 |
ground(,,S); "GND" at last line.s below |
| 274 |
|
| 275 |
ifpostscript(,latexcommand(}%)) |
| 276 |
.PE |