//Geovany Alfredo Interiano Rivera
//0318200602488
#include <LiquidCrystal.h>
#include <DHT.h>
#include <Servo.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int trig = 6;
int echo = 13;
Servo barrera;
int led = 8;
int buzzer = 9;
long tiempo;
int distancia;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
dht.begin();
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
barrera.attach(10);
barrera.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
float temperatura = dht.readTemperature();
float humedad = dht.readHumidity();
// Monitoreo permanente
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(temperatura);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Hum:");
lcd.print(humedad);
lcd.print("%");
delay(1000);
// ALERTA AMBIENTAL
if (temperatura > 35 || humedad < 35) {
digitalWrite(led, HIGH);
tone(buzzer, 1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ALERTA");
lcd.setCursor(0, 1);
lcd.print("AMBIENTAL");
delay(2000);
} else {
digitalWrite(led, LOW);
noTone(buzzer);
}
// MEDIR DISTANCIA
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
tiempo = pulseIn(echo, HIGH);
distancia = tiempo * 0.034 / 2;
// CONTROL DE ACCESO
if (distancia < 10) {
barrera.write(90);
String mensaje = "Acceso Autorizado Geovany Alfredo Interiano Rivera ";
for (int i = 0; i < mensaje.length() - 15; i++) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(mensaje.substring(i, i + 16));
delay(300);
}
delay(3000);
barrera.write(0);
}
}