personas:johnny:proyectos:indoor_diy_autosostenible
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previaPróxima revisiónAmbos lados, revisión siguiente | ||
personas:johnny:proyectos:indoor_diy_autosostenible [2019/06/19 07:43] – kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/09/25 05:05] – kz | ||
---|---|---|---|
Línea 48: | Línea 48: | ||
dht.begin(); | dht.begin(); | ||
// nombre del wifi y clave del wifi al cual se va a conectar el esp | // nombre del wifi y clave del wifi al cual se va a conectar el esp | ||
- | WiFi.begin(" | + | WiFi.begin(" |
while (WiFi.status() != WL_CONNECTED) { | while (WiFi.status() != WL_CONNECTED) { | ||
Línea 213: | Línea 213: | ||
+ | ==== Construcción física del indoor ==== | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | |||
+ | ====== Código para la ventilación usando timeAlarms ====== | ||
+ | |||
+ | <code c++> | ||
+ | |||
+ | // https:// | ||
+ | // Librerias | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // pin que controla | ||
+ | int pin = 13; | ||
+ | |||
+ | int alarma = 900; // cada 15 min | ||
+ | |||
+ | void setup() { | ||
+ | | ||
+ | Serial.begin(9600); | ||
+ | //fijamos el tiempo inicial del esp | ||
+ | // (08:30:00 25/05/17) | ||
+ | setTime(8, | ||
+ | | ||
+ | //Creamos las alarmas | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | Alarm.timerRepeat(alarma, | ||
+ | | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | pinMode(pin, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | digitalClockDisplay(); | ||
+ | Alarm.delay(1000); | ||
+ | } | ||
+ | |||
+ | // encender ventilador | ||
+ | void prenderVentilador(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | |||
+ | // encender ventilador | ||
+ | void apagarVentilador(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | // función que enciende el riego | ||
+ | void prenderSensorRiegoManana(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | // función que apaga el riego | ||
+ | void apagarSensorRiegoManana(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | void EveningAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void WeeklyAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void ExplicitAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void Repeats(){ | ||
+ | digitalWrite(pin, | ||
+ | Alarm.delay(60000); | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | Alarm.delay(1000); | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void OnceOnly(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void digitalClockDisplay() | ||
+ | { | ||
+ | // digital clock display of the time | ||
+ | Serial.print(hour()); | ||
+ | printDigits(minute()); | ||
+ | printDigits(second()); | ||
+ | Serial.println(); | ||
+ | } | ||
+ | |||
+ | void printDigits(int digits) | ||
+ | { | ||
+ | Serial.print(":" | ||
+ | if(digits < 10) | ||
+ | Serial.print(' | ||
+ | Serial.print(digits); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Código para el control automatizado de las luces ====== | ||
+ | |||
+ | Este código posee dos funciones que segun el estado se la planta se pueden cambiar para vegetativo o floración. Es un proyecto en platformio | ||
+ | |||
+ | <code c++> | ||
+ | /* | ||
+ | Este código toma la hora de internet usando un servidor NTP y | ||
+ | enciende algo. Tomadpo de aqui https:// | ||
+ | |||
+ | !!! importante | ||
+ | You need to adjust the UTC offset for your timezone in milliseconds. | ||
+ | Refer the list of UTC time offsets. | ||
+ | https:// | ||
+ | |||
+ | For UTC -5.00 : -5 * 60 * 60 : -18000 | ||
+ | For UTC +1.00 : 1 * 60 * 60 : 3600 | ||
+ | For UTC +0.00 : 0 * 60 * 60 : 0 | ||
+ | |||
+ | here -> const long utcOffsetInSeconds = 3600; | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const char *ssid = "el nombre de la red"; | ||
+ | const char *password = "el password de la red"; | ||
+ | const long utcOffsetInSeconds = -18000; // colombia UTC -5 | ||
+ | char daysOfTheWeek[7][12] = { | ||
+ | " | ||
+ | }; | ||
+ | // Define NTP client to get time | ||
+ | WiFiUDP ntpUDP; | ||
+ | NTPClient timeClient(ntpUDP, | ||
+ | int ledTrigger = D6; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | WiFi.begin(ssid, | ||
+ | while(WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | Serial.print(" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | timeClient.begin(); | ||
+ | pinMode(LED_BUILTIN, | ||
+ | pinMode(ledTrigger, | ||
+ | } | ||
+ | |||
+ | void statusWIFI() { | ||
+ | // cuando esta pegado a internet el status es 3 | ||
+ | // la idea de esto es que mande un color u otro si tiene internet o no | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.status()); | ||
+ | } | ||
+ | |||
+ | void lucesVegetativo() { | ||
+ | // 18 horas luz, 6 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // se prenden a las 6 de la mañana y se apagan a las 12 de la noche | ||
+ | if ( hours < 6 ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void lucesFloracion() { | ||
+ | // 12 horas luz, 12 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // a las 6 de la mañana se prenden y a las 6 de la tarde se apagan | ||
+ | if ( (hours >= 6) && (hours < 18) ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // the loop function runs over and over again forever | ||
+ | void loop() { | ||
+ | timeClient.update(); | ||
+ | Serial.print(daysOfTheWeek[timeClient.getDay()]); | ||
+ | Serial.print(", | ||
+ | Serial.print(timeClient.getHours()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getMinutes()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getSeconds()); | ||
+ | Serial.println("" | ||
+ | statusWIFI(); | ||
+ | // | ||
+ | lucesFloracion(); | ||
+ | delay(1000); | ||
+ | |||
+ | /* | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | */ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | el platformio.ini | ||
+ | <code json> | ||
+ | ;PlatformIO Project Configuration File | ||
+ | ; | ||
+ | ; Build options: build flags, source filter | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; Please visit documentation for the other options and examples | ||
+ | ; https:// | ||
+ | |||
+ | [env: | ||
+ | platform = espressif8266 | ||
+ | board = d1_mini_lite | ||
+ | framework = arduino | ||
+ | lib_deps = NTPClient | ||
+ | |||
+ | </ | ||
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz