Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Regulador de Temperatura
MATERIALES
ARDUINO UNO REV3
MODULO DHT11
MODULO RELAY 2CH 5VDC
COOLER DE 12V
RESISTENCIAS
BOTONES
PROTOBOARDS
CABLES UTP
BATERIAS DE 9V
PROGRAMACIO
N
B10101,
#include <DHT.h> B01110,
#include <LiquidCrystal.h> B11111,
const int dht11Pin = 8; // pin desde el B01110,
sensor B10101,
const int botonMasPin = 9; // pin desde B00100,
el boton mas B00000,
const int botonMenosPin = 10; // pin };
desde el boton menos byte fanOff[8] = {
const int relayPin = 11; // pin al relay B01110,
// variables para trabajar con los B10001,
botones B10001,
boolean lastBotonMas = LOW; B10001,
boolean currentBotonMas = LOW;
boolean lastBotonMenos = LOW; B10001,
boolean currentBotonMenos = LOW; B10001,
// variables medidas B01110,
float temperatura = 0; B00000,
float humedad = 0; };
float indiceCalor = 0; byte barra[8] {
// temperatura de control B11111,
int temperaturaControl = 0; B11111,
long previousMillis = 0; // tiempo en B11111,
milisegundos para tarea en segundo B11111,
plano B11111,
long interval = 2000; // intervalo de B11111,
tiempo para obtener medidas B11111,
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // B11111,
objeto lcd };
DHT dht11(dht11Pin, DHT11); // objeto void setup()
DHT11 {
// caracteres personalizados //Serial.begin(9600);
byte grados[8] = { lcd.begin(16, 2); // inicializa el LCD
B00110, lcd.clear();
B01001, // configurar pines
B01001, pinMode(dht11Pin, INPUT);
B00110, pinMode(relayPin, OUTPUT);
B00000, pinMode(botonMasPin, INPUT);
B00000, pinMode(botonMenosPin, INPUT);
B00000, digitalWrite(relayPin, HIGH);
B00000, // crear caracteres
}; lcd.createChar(0, grados);
byte flechas[8] = { lcd.createChar(1, flechas);
B00100, lcd.createChar(2, fanOn);
B01110, lcd.createChar(3, fanOff);
B11111, lcd.createChar(4, barra);
B00000, // barra de progreso inicializar da
B00000, tiempo para que el sensor se estabilize
B11111, lcd.setCursor(0,0);
B01110, lcd.print("Inicializando...");
B00100, for (int i = 0; i <= 15; i++) {
}; lcd.setCursor(i, 1);
byte fanOn[8] = { lcd.write((byte)4);
B00100, delay(250);
} temperaturaControl--;
delay(250); //Serial.println(temperaturaControl);
lcd.clear(); lastBotonMenos = HIGH;
delay(500); }
// obtener temperatura - humedad - }
indice de calor else { lastBotonMenos =
// pausa de dos segundos para digitalRead(botonMenosPin);
estabilizar el DHT11 }
temperatura = lcd.setCursor(6,1);
dht11.readTemperature(); // obtiene la lcd.write((byte)1);
temperatura ambiente en ºC lcd.setCursor(7,1);
humedad = dht11.readHumidity(); // lcd.print(temperaturaControl);
obtiene la humedad ambiente lcd.setCursor(10,1);
indiceCalor = lcd.print("Fan");
dht11.computeHeatIndex(dht11.readTe if (temperatura > temperaturaControl) {
mperature(true), humedad); // calcula el lcd.setCursor(15,1); lcd.write((byte)2);
indice de calor digitalWrite(relayPin, LOW);
// comprueba la lectura, si falla vuelve }
a intentar else {
if (isnan(humedad) || lcd.setCursor(15,1);
isnan(temperatura)) { lcd.write((byte)3);
//debugging digitalWrite(relayPin, HIGH);
//Serial.println("Fallo la lectura del }
sensor..."); // en segundo plano obtener medidas
return; cada 2 segundos unsigned long
} currentMillis = millis(); if(currentMillis -
// establece la temperatura de control previousMillis > interval) {
temperaturaControl = temperatura + 1; // se ejecuta en segundo plano
desplegarInformacion(); // guardar el utlimo instante de lectura
} previousMillis = currentMillis;
void loop() // obtener temperatura - humedad -
{ indice de calor
// leer entrada de usuario temperatura =
currentBotonMas = dht11.readTemperature();
digitalRead(botonMasPin); // obtiene la temperatura ambiente en
currentBotonMenos = ºC
digitalRead(botonMenosPin); humedad = dht11.readHumidity(); //
// subir temperatura de control obtiene la humedad ambiente
if (currentBotonMas == HIGH && indiceCalor =
lastBotonMas == LOW) { dht11.computeHeatIndex(dht11.readTe
delay(15); // debouncing time mperature(true), humedad); // calcula el
if (digitalRead(botonMasPin)) { indice de calor
temperaturaControl++; // comprueba la lectura, si falla vuelve
// Serial.println(temperaturaControl); a intentar
lastBotonMas = HIGH; if (isnan(humedad) ||
} isnan(temperatura)) {
} //debugging
else { lastBotonMas = //Serial.println("Fallo la lectura del
digitalRead(botonMasPin); } sensor...");
// bajar temperatura de control return;
if (currentBotonMenos == HIGH && }
lastBotonMenos == LOW) { desplegarInformacion();
delay(15); // debouncing time }
if (digitalRead(botonMenosPin)) { }
/**
* desplegar informacion en el LCD
*/
void desplegarInformacion()
{
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.setCursor(2, 0);
lcd.print((int)temperatura);
lcd.setCursor(4, 0);
lcd.write((byte)0);
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.setCursor(2, 1);
lcd.print((int)humedad);
lcd.setCursor(4, 1);
lcd.print("%");
lcd.setCursor(6, 0);
lcd.print("IC:");
lcd.setCursor(9, 0);
lcd.print(indiceCalor);
}