//-- Libreries #include //DHT and LCD libraries #include //-- Pins LCD and sensor #define I2C_ADDR 0x27 #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 #define DHT11_PIN 2 //Declaring where the DHT signal pin is wired //-- LCD functions LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //-- Environment sensor functions dht DHT; //Declaring the DHT as a dht type to use it later //-- LED pins declaration int redpin = 11; //select the pin for the red LED int bluepin = 10; // select the pin for the blue LED int greenpin = 9; // select the pin for the green LED //--FC32 pin declaration - soil moisture int msensor = A0; //--FAN pin declaration int fan = 3; //--auxiliar Variables int humedad = 0; //FC32 int humedadmap = 0; int minhumedad = 80; float tempe = DHT.temperature; //DHT 11 - read temperature float maxtempe = 35; float humrel = DHT.humidity; //DHT 11 - read humidity float maxhumrel = 90; int aux1 = 0; int aux2 = 0; // initial configuracion void setup() { Serial.begin(9600); // for led pinMode(redpin, OUTPUT); pinMode(bluepin, OUTPUT); pinMode(greenpin, OUTPUT); // for screen lcd.begin (16, 2); lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); lcd.setBacklight(HIGH); //Lighting backlight lcd.home (); // for fan pinMode(fan, OUTPUT); digitalWrite (fan, LOW); } // what is gooing to be done void loop() { //LEER VALORES //FC32 humedad = analogRead(msensor); humedadmap = map(humedad, 550, 10, 0 , 100); //hace regla de 3 /* Serial.print("Humedad: "); Serial.print (humedad); Serial.println("% "); delay (1000); */ //DTH11 int chk = DHT.read11(DHT11_PIN); tempe = DHT.temperature; humrel = DHT.humidity; /* Serial.print("Tem= "); Serial.println(DHT.temperature); Serial.print("Humidity= "); Serial.println(DHT.humidity); delay(1000); */ //FC32 compare if (humedadmap <= minhumedad) { digitalWrite(redpin, HIGH); digitalWrite(greenpin, LOW); digitalWrite(bluepin, LOW); delay(500); } else { // if ((humedadmap >= 0) && (humedadmap < minhumedad)) digitalWrite(redpin, LOW); digitalWrite(greenpin, HIGH); digitalWrite(bluepin, LOW); delay(500); } //SEND DHT11 VALUES TO LCD lcd.setCursor(0, 0); //Setting the position where you want to start writing the message (0,0) is top left lcd.print("TEMP:"); //Message to display lcd.setCursor(7, 0); //Start writing on the position (7,1) lcd.print(tempe); lcd.println(" C "); lcd.setCursor(0, 1); //Setting the position where you want to start writing the message (0,0) is top left lcd.print("HUMIDITY:"); //Message to display lcd.setCursor(9, 1); //Start writing on the position (9,1) lcd.print(humrel); lcd.println("% "); delay(4000); //Display time // DHT11 compare - ACTIVATE FAN if ((tempe >= maxtempe) || (humrel >= maxhumrel)) { digitalWrite(fan, HIGH); delay(3000); } if ((tempe < maxtempe) || (humrel < maxhumrel)) { digitalWrite(fan, LOW); delay(3000); } }