proyectos:monitorclima_humedad_suelo
Diferencias
Muestra las diferencias entre dos versiones de la página.
Próxima revisión | Revisión previa | ||
proyectos:monitorclima_humedad_suelo [2022/06/25 22:05] – creado manuel.floresv | proyectos:monitorclima_humedad_suelo [2022/06/26 23:10] (actual) – [Referencias] manuel.floresv | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
+ | ====== Materiales ====== | ||
+ | - Arduino UNO | ||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | ===== Diagrama ===== | ||
+ | |||
+ | {{ : | ||
+ | ====== Codigo ====== | ||
+ | |||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | |||
+ | #define SCREEN_WIDTH 128 // OLED display width, | ||
+ | #define SCREEN_HEIGHT 64 // OLED display height, in pixels | ||
+ | #define OLED_RESET -1 | ||
+ | Adafruit_SSD1306 oled(SCREEN_WIDTH, | ||
+ | |||
+ | // | ||
+ | struct LED { | ||
+ | int pin; // Pin en arduino | ||
+ | boolean isON; // Esta encedido? | ||
+ | boolean state; | ||
+ | int sw; | ||
+ | boolean swstate; | ||
+ | boolean swoldstate; | ||
+ | boolean pressed; | ||
+ | }; | ||
+ | |||
+ | |||
+ | const int AirValue = 590; // Reemplazar este valor por lectura de sensor humerdad en el aire | ||
+ | const int WaterValue = 350; // | ||
+ | int MoistSoilValue = 0; | ||
+ | int MoistSoilPercent=0; | ||
+ | struct LED hSuelo={3, | ||
+ | |||
+ | // Refresh time every N miliseconds | ||
+ | unsigned long timeNow = 0; | ||
+ | unsigned long timePrev = 0; | ||
+ | unsigned int timeWait = 5000; | ||
+ | |||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | // | ||
+ | pinMode(hSuelo.pin, | ||
+ | digitalWrite(hSuelo.pin, | ||
+ | | ||
+ | // initialize OLED display with address 0x3C for 128x64 | ||
+ | if (!oled.begin(SSD1306_SWITCHCAPVCC, | ||
+ | Serial.println(F(" | ||
+ | while (true); | ||
+ | } | ||
+ | oled.clearDisplay(); | ||
+ | oled.display(); | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | timeNow = millis(); | ||
+ | |||
+ | // Si han pasado al menos timeWait(5000=5 Segundos) desde la ultima lectura del sensor | ||
+ | if (timeNow-timePrev >= timeWait ) | ||
+ | { | ||
+ | timePrev = timeNow; | ||
+ | | ||
+ | //Lee valores sensor de humedad de suelo | ||
+ | MoistSoilValue = analogRead(A0); | ||
+ | Serial.println(MoistSoilValue); | ||
+ | MoistSoilPercent = map(MoistSoilValue, | ||
+ | (MoistSoilPercent > 100) && (MoistSoilPercent=100); | ||
+ | (MoistSoilPercent < 0) && (MoistSoilPercent=0); | ||
+ | | ||
+ | Serial.print(MoistSoilPercent); | ||
+ | Serial.println(" | ||
+ | | ||
+ | refreshOLED(MoistSoilPercent); | ||
+ | | ||
+ | }//End if (timeNow-timePrev >= timeWait ) | ||
+ | } | ||
+ | |||
+ | //Funcion para actualizar pantalla OLED | ||
+ | void refreshOLED( int lSoilPercent ){ | ||
+ | oled.clearDisplay(); | ||
+ | |||
+ | oled.setCursor(0, | ||
+ | oled.setTextSize(1); | ||
+ | oled.setTextColor(WHITE); | ||
+ | oled.print(" | ||
+ | oled.setCursor(0, | ||
+ | oled.setTextSize(2); | ||
+ | oled.setTextColor(WHITE); | ||
+ | oled.print(" | ||
+ | oled.print(lSoilPercent); | ||
+ | oled.print(" | ||
+ | if (lSoilPercent < 60) { | ||
+ | hSuelo.state=LOW; | ||
+ | oled.print(" | ||
+ | }else{ | ||
+ | hSuelo.state=HIGH; | ||
+ | oled.print(" | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
====== Referencias ====== | ====== Referencias ====== | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * |
proyectos/monitorclima_humedad_suelo.1656194706.txt.gz · Última modificación: por manuel.floresv