#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27
const int portPin= 34;
int potValor = 0;
const int Led1= 4;
const int Led2= 16;
const int Led3= 17;
const int Led4= 5;
const int Led5= 18;
const int Led6= 19;
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
pinMode(Led4, OUTPUT);
pinMode(Led5, OUTPUT);
pinMode(Led6, OUTPUT);
Serial.begin(9600);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
delay(2000);
}
void loop() {
potValor = analogRead(portPin);
//Serial.println(potValor);
lcd.clear(); // clear display
lcd.setCursor(2, 0); // move cursor to (0, 0)
lcd.print("IOT Control"); // print message at (0, 0)
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.print("Viento: "); Serial.print(potValor/40, 1); Serial.println(" Km/h");
lcd.setCursor(0, 1);
lcd.print("Temp: " + String(data.temperature, 2) + " C");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("Humedad: " + String(data.humidity, 1) + " %");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("Viento: ");
lcd.print(potValor/40);lcd.print(" Km/h");
delay(2000);
if (potValor>=682){
digitalWrite(Led1, HIGH);
} else if(potValor < 682){
digitalWrite(Led1, LOW);
}
if (potValor>=1364){
digitalWrite(Led2, HIGH);
} else if(potValor < 1364){
digitalWrite(Led2, LOW);
}
if (potValor>=2046){
digitalWrite(Led3, HIGH);
} else if(potValor < 2046){
digitalWrite(Led3, LOW);
}
if (potValor>=2728){
digitalWrite(Led4, HIGH);
} else if(potValor < 2728){
digitalWrite(Led4, LOW);
}
if (potValor>=3410){
digitalWrite(Led5, HIGH);
} else if(potValor < 3410){
digitalWrite(Led5, LOW);
}
if (potValor>=3800){
digitalWrite(Led6, HIGH);
} else if(potValor < 3800){
digitalWrite(Led6, LOW);
}
delay(1000); // this speeds up the simulation
}