Advertisement
RuiViana

Irrigacao

Jul 1st, 2016
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <DHT.h>
  2. //#define DHT type 22 dht22 dht.22    //  <--------------- anulei
  3.  
  4. int i = 0; // para contar o n de acionamentos da bomba
  5.  
  6. #define led 5    // faltava definir este led (usei 5)
  7. #define DHT22PIN 2 //pino do DHT22
  8.  
  9. #define RELAY1 7 //pino do relé
  10.  
  11. #define DHTTYPE DHT22           // <-----------  Cria a instancia e tipo de sensor
  12. DHT dht(DHT22PIN, DHTTYPE);       // <------------ Define o pino
  13. //-------------------------------
  14. void setup()
  15. {
  16.   dht.begin();                     // <-----------     inicializa o Sensor
  17.   Serial.begin(115200);
  18.   Serial.println("DHT11 TEST PROGRAM ");
  19.   Serial.print("LIBRARYION: ");
  20.   Serial.println("DHT11LIB_VERSION");    // Faltava "   "
  21.   Serial.println();
  22.   pinMode(led, OUTPUT);         // Faltava definir pino led
  23.   pinMode(RELAY1, OUTPUT);
  24. }
  25. //-------------------------------
  26. void loop()
  27. {
  28.   Serial.println("\n");
  29.   //int chk = DHT11.read(DHT22PIN);
  30.   int chk = dht.readTemperature();      // <------------ Le temperatura no DHT11
  31.   Serial.print("Reador: ");
  32.   switch (chk)
  33.   {
  34.     case 0: Serial.println("OK"); break;
  35.     case -1: Serial.println("Checksum error"); break;
  36.     case -2: Serial.println("Time out error"); break;
  37.     default: Serial.println("Unknown error"); break;
  38.   }
  39.   Serial.print("Humidity ");
  40.   //Serial.println((float)DHT22.humidity, 2);
  41.   Serial.println((float) dht.readHumidity(), 2);    // <----------------------função le umiddade
  42.   Serial.print("Temperature: ");
  43.   //Serial.println((float)DHT22.temperature, 2);
  44.   Serial.println((float)dht.readTemperature(), 2);    // <----------------------função le temperatura
  45.  
  46.   // if (DHT22.temperature >= 28 || DHT22.humidity <= 90 )
  47.   if ( dht.readTemperature() >= 28 || dht.readHumidity() )// <----------Se temperatura e umoidade
  48.   {
  49.     Serial.print("Temperaturar Igual 28C \n");
  50.     digitalWrite(RELAY1, LOW); // Turns ON Relays 1
  51.     Serial.print("BombaDA \n");
  52.     delay(60000); // Wait 1 minute
  53.     digitalWrite(RELAY1, HIGH); // Turns Relay Off
  54.     Serial.print("BombaIGADA \n");
  55.   }
  56.   else
  57.   {
  58.     delay(60000); // Espera 1 minuto para nao dar diferenca de tempo se a bomba nao é acionada.}
  59.     Serial.print("\n");     // <----------------------faltava "
  60.     Serial.print(i);
  61.  
  62.     i++;
  63.     delay(540000); // send the temperature every 10 minutes 540000 + 60000 milliseconds (bomba acionada)
  64.     //pausa final: 10minutos. Calibrar pois o tempo dos intervalos se somam.
  65.   }
  66. }
  67.   //
  68.   // END OF FILE
  69.   //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement