Продолжение моей домашней поливалки мини подоконного парника 🙂
Пока что обновление прошивки для Ардуино Мини. Изменился интерфейс, убрал цветные кнопки (они слишком много ресурсов жрали), добавил кнопку включения подсветки, переработал алгоритм включения и выключения поливалки, а так же добавил энергосберегающий режим, но пока что только для платы Ардуино.
Предыдущие части:
Eсть прогресс, похоже моим расточкам очень нравится моя поливалка 🙂 но похоже им не хватает яркого летнего света, что бы активно рости и развиваться :(, ничего и эту проблему можно решить 🙂
Есть смысл добавить подсветку, так как уже осень, а растения любят солнце и тепло, попробуем их обмануть! В схему добавим управление подсветкой, поменяем подключение пина RX (принимающий сигналы от ESP8266 WiFi модуля) с 7го пина на 2й, который является нулевым прерыванием для платы Ардуино (так нужно для выведения ее из энергосберегающего состояния) и добавим фоторезистор, что бы поливалка знала когда включать подсветку, подсветка у меня достаточно мощненькая, ей требуется минимум 30 вольт 0.6A, а у нас система расчитана на напряжение одной литий-ионной батарейки – 3.7вольт, так что без инвертера DC-DC не обойтись! К счастью у меня такого добра хоть отбавляй…:
Последнее обновление прошивки, в комментариях не нуждается, там все написано, но пришлось переработать алгоритм считывания сенсоров и управлением автовключения и выключения (предыдущая прошивка имела баг не выключения поливалки, да да не используйте ее…)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
/* Autosprinkler, based on YL-38 Hygrometer Author: Elik745i Version 1.4c Oct2015, www.voltrans.az v1.4c added background (Day/Night) v1.4b added Lit control and photoresistor v1.4a added watchdog and power.down function (21mA idle mode now) v1.3h added sensor read, fine tuned code v1.3g Added UV Light control v1.3f fixed on/off time and web control v1.3e added voltage reading v1.3d added CSS v1.3c added pump control buttons, changed code to MIT one v1.3 bug fixing v1.2 bug fixing v1.1 added WIFI module ESP8266 */ #include <SoftwareSerial.h> #include <ESP8266pro.h> #include <ESP8266proServer.h> #include <Vcc.h> #include <JeeLib.h> ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog const int RST=12; //Reset Pin for WIFI module int H; //Hugrometer int Lt; //Lit int state; float v; float p; const int RX=2; //changed from 7 to 2 for sleep mode interrupt0 const int TX=8; //TX pin const int r=10; //buzzer pin const int k=11; //pump pin const int l=7; //UV LED pin const int t=A1; //photoresistor const int d=4; //Hygrometer pin const int LED=13; //indicator LED const int n=A0; //Hygrometer pin //measure power voltage const int TN = 1400; //tone const int minLux=40; // When to switch Lit ON const int minHyg=30; // When to switch SprinklerPump ON const float VccMin = 3.3; // Minimum expected Vcc level, in Volts. const float VccMax = 4.2; // Maximum expected Vcc level, in Volts. const float VccCorrection = 4.075/3.89; // Measured Vcc by multimeter divided by reported Vcc unsigned long previousMillis = 0; //check hygrometer unsigned long previousMillis1 = 0; //check hygrometer const long interval = 60000; //Sampling interval time mSec const long interval1 = 20000; //PumpON time mSec SoftwareSerial espSerial(RX, TX); // RX, TX ESP8266pro wifi(espSerial, Serial); ESP8266proServer server(wifi, onClientRequest); String requestPaths[ESP_MAX_CONNECTIONS]; const char* ssid = "sazz Wireless Network"; const char* password = "Samir2012A"; Vcc vcc(VccCorrection); void setup() { pinMode(LED, OUTPUT); espSerial.begin(9600); Serial.begin(57600); pinMode(RST, OUTPUT); digitalWrite(RST,LOW); delay(500); digitalWrite(RST,HIGH); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // Initialize ESP wifi.begin(); // Connect to WiFi network // In future ESP should automatically reconnect // to this network, if requried do { if (!wifi.stationConnect(ssid, password)) delay(10000); } while (wifi.stationIP() == NULL_IP); // Start server on port 80 server.start(80); // Get AP ip address String ip = wifi.stationIP(); Serial.println(); Serial.println("================================="); Serial.println("Server started: http:// "+ip); Serial.println("================================="); pinMode(d, OUTPUT); pinMode(k, OUTPUT); pinMode(l, OUTPUT); pinMode(n, INPUT); //input Hygrometer pinMode(t, INPUT); //input photoresistor digitalWrite(LED,HIGH); tone(r, TN, 200); digitalWrite(LED,LOW); digitalWrite(d,HIGH); //turn off hygrosensor delay(500); H = analogRead(n); H=map(H,0,1023,100,0); //for hygrometer processing digitalWrite(d,LOW); //turn off hygrosensor delay(100); Lt = analogRead(t); Lt = map(Lt,0,1023,0,100); //Lighting v = vcc.Read_Volts(); p = vcc.Read_Perc(VccMin, VccMax); } void loop() { // Process incoming requests server.processRequests(); unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= interval1 && state==1) { pumpwebOff(); state=0; } if(currentMillis - previousMillis >= interval) { previousMillis = currentMillis; checkSensors(); } if(state==0){ digitalWrite(r,LOW); //turn off speaker delay(100); Sleepy::loseSomeTime(interval); //go to sleep } } // Optional method to process remote response void printResponse(ESP8266proConnection* connection, char* buffer, int length, boolean completed) { Serial.print(buffer); } void onClientRequest(ESP8266proConnection* connection, char* buffer, int length, boolean completed) { if (strncmp(buffer, "GET ", 4) == 0) { // We found GET HTTP request char* p = strstr(buffer + 4, " "); *p = '\0'; // erase string after path requestPaths[connection->getId()] = (String)((char*)buffer + 4); } if (completed) { String path = requestPaths[connection->getId()]; if (path == "/") { connection->send(F( "HTTP/1.0 200 OK\r\n\r\n" "<head>" "<meta http-equiv='refresh' content='300'>" "<title>Sprinkler</title>" "</head>" "<body>" "<div id=\"changedDiv\" style=\" width: 450px; height: 450px; border-radius: 14px; box-shadow: rgb(0, 0, 0) 0px 0px 20px; opacity: 1;")); if(Lt >= minLux){ connection->send(F( "background: url(http://www.voltrans.az/wp-content/uploads/2015/10/sun_sky_1.jpg); background-size: 450px 450px; background-color: white; color: black;\">" )); } if(Lt < minLux){ connection->send(F( "background: url(http://www.voltrans.az/wp-content/uploads/2015/10/moon-background.png); background-size: 450px 450px; background-color: blue; color: yellow;\">" )); } connection->send(F( "<div style=\"padding-right:20px; padding-left:20px; padding-top:20px; padding-bottom:20px;\">" "<h2 align=\"center\">WiFi Plant Sprinkler</h2><br> Hygrometer = " )); //checkSensors(); connection->send(String(H)); connection->send(F( "<img src=\"http://www.voltrans.az/wp-content/uploads/2015/09/plant.png\" width=\"240\" height=\"240\" align=\"right\"></img>" )); connection->send(F( "% <br> Lighting = " )); connection->send(String(Lt)); connection->send(F( "Lux <br> Battery Voltage = " )); connection->send(String(v)); connection->send(F( "V <br> Charge Left = " )); connection->send(String(p)); if(digitalRead(k)==LOW){ connection->send(F( " %<input style=\"position:relative; top:50px; left:-5px;\" type=\"button\" onclick=\"window.location.href='/led0'\" value=\"Sprinkler is OFF\" />" )); }else{ connection->send(F( " %<input style=\"position:relative; top:50px; left:-5px;\" type=\"button\" onclick=\"window.location.href='/led1'\" value=\"Sprinkler is ON\" />")); } if(digitalRead(l)==LOW){ connection->send(F( "<br><br><input style=\"position:relative; top:50px; left:-5px;\" type=\"button\" onclick=\"window.location.href='/led2'\" value=\"UV Light is OFF\" />" )); }else{ connection->send(F( "<br><br><input style=\"position:relative; top:50px; left:-5px;\" type=\"button\" onclick=\"window.location.href='/led3'\" value=\"UV Light is ON\" />" )); } connection->send(F( "<a style=\"position:relative; top:150px; left:240px;\" href=\"http://www.voltrans.az\">www.voltrans.az</a>" "<br><a style=\"position:relative; top:150px; left:240px;\" href=\"http://www.voltrans.az/?p=1480\"> firmware v1.4c</a>" "</div>" "</div>" "</body>" "</html>" )); } else if (path.startsWith("/led")) { if (path.substring(4) == "0"){ pumpwebOn(); Serial.println("Turning Sprinkler ON"); connection->send(F( "HTTP/1.0 200 OK\r\n\r\n" "<html>" "<meta http-equiv='refresh' content='1; url=/' />" "</html>" )); } if (path.substring(4) == "1"){ pumpwebOff(); Serial.println("Turning Sprinkler OFF"); connection->send(F( "HTTP/1.0 200 OK\r\n\r\n" "<html>" "<meta http-equiv='refresh' content='1; url=/' />" "</html>" )); } if (path.substring(4) == "2"){ UVwebOn(); Serial.println("Turning UV Light ON"); connection->send(F( "HTTP/1.0 200 OK\r\n\r\n" "<html>" "<meta http-equiv='refresh' content='1; url=/' />" "</html>" )); } if (path.substring(4) == "3") { UVwebOff(); Serial.println("Turning UV Light OFF"); connection->send(F( "HTTP/1.0 200 OK\r\n\r\n" "<html>" "<meta http-equiv='refresh' content='1; url=/' />" "</html>" )); } } else { connection->send(F("HTTP/1.0 404 Not Found\r\n\r\n")); connection->send(F("<h1>4 0 4</h1>")); connection->send(F("Yes, this is true. :(")); } connection->close(); } } void checkSensors(){ digitalWrite(d,HIGH); //turn off hygrosensor delay(500); H = analogRead(n); H=map(H,0,1023,100,0); //for hygrometer processing digitalWrite(d,LOW); //turn off hygrosensor delay(100); Lt = analogRead(t); Lt = map(Lt,0,1023,0,100); //Lighting delay(500); v = vcc.Read_Volts(); p = vcc.Read_Perc(VccMin, VccMax); delay(500); Serial.print("VCC = "); Serial.print(v); Serial.println(" Volts"); Serial.print("VCC = "); Serial.print(p); Serial.println(" %"); Serial.print("Lighting = "); Serial.print(Lt); Serial.println(" LUX"); if(Lt < minLux && digitalRead(l)==LOW){ Serial.print("Not Enough Lit, Switching Lit ON: "); Serial.print(Lt); Serial.println(" Lux"); UVwebOn(); tone(r, TN, 200); delay(100); } if(Lt >= minLux){ Serial.print("Enough Lit, Switching Lit Off: "); Serial.print(Lt); Serial.println(" Lux"); UVwebOff(); //tone(r, TN, 200); delay(100); } if(H <= 5){ Serial.print("Alarm, sensor disconnected/on air!: "); Serial.println(H); //pumpwebOn(); //tone(r, TN, 200); //delay(100); alarm(); } if(H > 5 && H <= minHyg){ //less than 50%, dry soil Serial.print("Soil is dry,switching sprinkle ON: "); Serial.println(H); pumpwebOn(); tone(r, TN, 200); delay(100); } if(H > minHyg && H <= 90){ //less than 70%, somewhat moist Serial.print("Soil's a bit damp: "); Serial.println(H); } if(H > 90){ //less than 400, quite moist Serial.print("Soil is quite most: "); Serial.println(H); alarm(); } } void UVwebOn(){ digitalWrite(l, HIGH); delay(100); } void UVwebOff(){ digitalWrite(l, LOW); delay(100); } void pumpwebOn(){ digitalWrite(k, HIGH); state=1; delay(100); } void pumpwebOff(){ digitalWrite(k, LOW); delay(100); } void alarm(){ for( int z=1000;z<=5000;z++){ tone(r, z, 10); } for( int z=5000;z>=1000;z--){ tone(r, z, 10); } delay(100); } |
Библиотеки, которые вам понадобятся:
libraries
разархивировать в папку libraries директории, где находится Arduino IDE, я использовал последнюю версию, которую можно скачать отсюда.
вот так выглядит моя поливалка:
вот так выглядит интерфейс управления днем,
а так ночью:
ну пожалуй на последок остается добавить последние штрихи: датчик влажности воздуха, температуры и энергосберегающий режим для вайфай платы. 🙂 и завершить проект поливалки – мини теплицы 🙂
До связи!
Элик.