Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. #include <OneWire.h>                
  2. #include <DallasTemperature.h>
  3. OneWire ourWire(2);                //Se establece el pin 2  como bus OneWire
  4.  
  5. DallasTemperature sensors(&ourWire); //Se declara una variable u objeto para nuestro sensor
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. //sensors.begin();   //Se inicia el sensor
  10. pinMode(9, OUTPUT);
  11. pinMode(A0, INPUT); // Entrada de datos del sensor YL-69
  12.     }
  13.  
  14. void loop() {
  15.   sensors.requestTemperatures();   //Se envía el comando para leer la temperatura
  16.   float temp= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC
  17.  
  18.   Serial.print("Temperatura= ");
  19.   Serial.print(temp);
  20.   Serial.println(" Cº");
  21.   delay(300);  //  <-------------------------------------------------------- TIEMPO DEL INTERVALO EN QUE SE MIDE LA TEMPERATURA
  22.  
  23.  
  24.   if (temp>=21.0){
  25.       digitalWrite (9, HIGH);
  26.       Serial.print("\nBOMBA DE AGUA ENCENDIDA!!!\n");
  27.       delay(1000); // <-------------------------------------------------------- TIEMPO QUE SALE EL AGUA    
  28.       }  
  29.   else {
  30.       digitalWrite (9, LOW);
  31.     }
  32.  
  33.   int SensorValue = analogRead(A0); //TOMA MUESTRA
  34.  
  35.   Serial.print(SensorValue); Serial.print(" - ");  
  36.     if(SensorValue >= 1000) {
  37.        Serial.println("El sensor no está en el suelo o está DESCONECTADO");
  38.           }
  39.     if(SensorValue < 1000 && SensorValue >= 600) {
  40.       Serial.println("Sensor  indica sequedad en el suelo");
  41.         }
  42.     if(SensorValue < 600 && SensorValue >= 370) {
  43.    Serial.println("Sensor indica  Humedad en el suelo");
  44.         }
  45.     if(SensorValue < 370) {
  46.       Serial.println("Sensor indica que actualmente está en contacto con el agua");
  47.       }
  48. delay(1000); // <--------------------------------------------------------   INTERVALO DE MEDICIÓN DE HUMEDAD
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement