//Incluimos las librerias
#include "DHTesp.h"
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Arduino.h>
#define PPM_PIN 4
//Declaramos el variable que almacena el pin a conectar el DHT11
int pinDHT = 15;
//Instanciamos el DHT
DHTesp dht;
//Inicializamos los pines conectados de la pantalla de cristal liquido al esp32
LiquidCrystal lcd(22,23,5,18,19,21);
void setup() {
Wire.begin(23, 22);
Serial.begin(115200);
//Inicializamos el dht
dht.setup(pinDHT, DHTesp::DHT22);
// Inicializamos el display de 16 x 2
lcd.begin(16, 2);
}
void loop() {
//Configuramos el MQ135
int16_t ppmValue = analogRead(PPM_PIN);
//Conversor de voltaje de 5v a 3.3v
int mappedppmValue = (ppmValue/4.095);
//Obtenemos el arreglo de datos (humedad y temperatura)
float t = dht.getTemperature();
float h = dht.getHumidity();
//Nos posicionamos en la posiciocion 0,0 del display
lcd.setCursor(0,0);
//Escribimos la palabra Temperatura
lcd.print("Temperatura: "+ String(t) + " " + "Humedad: "+ String(h) + "%");
delay(100);
//Movemos el texto de derecha a izquierda
lcd.scrollDisplayLeft();
lcd.setCursor(0,2);
lcd.print("PPM: "+ String(mappedppmValue));
if ((mappedppmValue) <= 199 && (mappedppmValue) >= 0) {
lcd.print(" NORMAL");
}
if ((mappedppmValue) >= 200 && (mappedppmValue) <= 300) {
lcd.print(" PRESENCIA DE C02");
}
if ((mappedppmValue) > 301 && (mappedppmValue) <= 500) {
lcd.print(" BUTANO");
}
if ((mappedppmValue) > 500) {
lcd.print(" DANGER");
}
}