#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <HCSR04.h>
byte triggerPin = 12;
byte echoPin = 11;
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
int mov;
const int PIR_PIN = 7;
String mov_est;
int time = 1000;
int timeSetUp = 1500;
void setup() {
pinMode (PIR_PIN, INPUT);
dht.begin();
HCSR04.begin(triggerPin, echoPin);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.println("Bienvenidos ");
lcd.setCursor(5, 1);
lcd.print("a la USAT");
delay(timeSetUp);
lcd.clear();
}
void loop() {
// SENSORES
float t = dht.readTemperature(); // DHT temperatura
float h = dht.readHumidity(); // DHT humedad
mov = digitalRead(7); // PIR
if (mov == HIGH) {
mov_est = "Si";
} else {
mov_est = "No";
}
double* distances = HCSR04.measureDistanceCm(); // HCSR04
// LCD_I2C
mostrarInfoLCD("Temperatura",t,"C",0); // DHT temperatura
mostrarInfoLCD("Humedad",h,"%",3); // DHT humedad
mostrarInfoLCD("Movimiento",mov_est,"detectado",1); // PIR
mostrarInfoLCD("Distancia",distances[0],"cm",5); // HCSR04
}
void mostrarInfoLCD (String description, double value, String unit, int row) {
mostrarInfoLCD(description,String(value, 2),unit,row);
}
void mostrarInfoLCD (String description, String value, String unit, int row) {
lcd.setCursor(0,0);
lcd.print(description);
lcd.print(":");
lcd.setCursor(row,1);
lcd.print(value);
lcd.print(" ");
lcd.print(unit);
delay(time);
lcd.clear();
}