Herramientas de usuario

Herramientas del sitio


proyectos:monitorclima_humedad_suelo

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Próxima revisión
Revisión previa
proyectos:monitorclima_humedad_suelo [2022/06/25 22:05] – creado manuel.floresvproyectos:monitorclima_humedad_suelo [2022/06/26 23:10] (actual) – [Referencias] manuel.floresv
Línea 1: Línea 1:
 +====== Materiales ======
 +  - Arduino UNO
 +  - [[https://www.amazon.com/gp/product/B07T1Y8T1V| Sensor de humedad de suelo capacitivo]]
 +  - [[https://www.amazon.com/gp/product/B01IUVHB8E/|Bomba dosificadora para acuario de 12V]]
 +  - [[https://www.amazon.com/dp/B08H1ZD5VZ|Tubo de silicona de 2mm]] 
 +  - [[https://www.amazon.com/gp/product/B07F3KY8NF| Pantalla OLED de 28x64 I2C]]
 +===== Diagrama =====
 +
 +{{ :proyectos:arduino-oled-soil_bb.png?800 |}}
 +====== Codigo ======
 +
 +<code c>
 +#include <Wire.h>
 +#include <Adafruit_GFX.h>
 +#include <Adafruit_SSD1306.h>
 +
 +
 +#define SCREEN_WIDTH 128 // OLED display width,  in pixels
 +#define SCREEN_HEIGHT 64 // OLED display height, in pixels
 +#define OLED_RESET -1
 +Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 +
 +//Estructura para guardar estados de led y bomba
 +struct LED {
 +  int pin;        // Pin en arduino
 +  boolean isON;   // Esta encedido? 
 +  boolean state;  // Estado LOW/HIGH
 +  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;  //Reemplazar este valor por lectura de sensor humerdad en agua
 +int MoistSoilValue = 0;
 +int MoistSoilPercent=0;
 +struct LED hSuelo={3,false,HIGH,2,LOW,LOW,false}; //Sensor de humerdad de suelo HIGH for NO (Relay Normally Open)
 +
 +// Refresh time every N miliseconds
 +unsigned long timeNow = 0;
 +unsigned long timePrev = 0;
 +unsigned int timeWait = 5000;
 +
 +
 +void setup() {
 +  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
 +
 +  //Initialize Soil Pump
 +  pinMode(hSuelo.pin, OUTPUT);
 +  digitalWrite(hSuelo.pin, hSuelo.state);
 +  
 +  // initialize OLED display with address 0x3C for 128x64
 +  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
 +    Serial.println(F("SSD1306 allocation failed"));
 +    while (true);
 +  }
 +  oled.clearDisplay();
 +  oled.display();
 +  delay(2000); // wait for initializing
 +}
 +
 +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);  //Read soil sensor
 +    Serial.println(MoistSoilValue);
 +    MoistSoilPercent = map(MoistSoilValue, AirValue, WaterValue, 0, 100);
 +    (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,0);  //  X,Y
 +    oled.setTextSize(1);
 +    oled.setTextColor(WHITE);
 +    oled.print("Hum. Suelo:   Bomba:");// 21 char with fontsize 1 and 20 with font 2 
 +    oled.setCursor(0,20);  //  X,Y
 +    oled.setTextSize(2);
 +    oled.setTextColor(WHITE);
 +    oled.print(" ");
 +    oled.print(lSoilPercent);
 +    oled.print(" ");
 +    if (lSoilPercent < 60) { 
 +      hSuelo.state=LOW; hSuelo.isON=true;
 +      oled.print("ON");
 +    }else{
 +      hSuelo.state=HIGH; hSuelo.isON=false;
 +      oled.print("OFF");
 +    }
 +
 +   digitalWrite(hSuelo.pin, hSuelo.state);
 +   oled.display();
 +}
 +</code>
  
 ====== Referencias ====== ====== Referencias ======
   * https://www.automatizacionparatodos.com/sensor-de-humedad-de-suelo-con-arduino/   * https://www.automatizacionparatodos.com/sensor-de-humedad-de-suelo-con-arduino/
 +  * https://create.arduino.cc/projecthub/55369/wireless-soil-moisture-probe-with-helium-and-dfrobot-c620b9
 +  * https://create.arduino.cc/projecthub/muhammad-aqib/how-to-use-oled-display-with-arduino-arduino-oled-tutorial-233985
 +  * https://randomnerdtutorials.com/guide-for-oled-display-with-arduino/
 +  * https://arduinogetstarted.com/tutorials/arduino-relay
 +  * 
proyectos/monitorclima_humedad_suelo.1656194706.txt.gz · Última modificación: por manuel.floresv