Código ON/OF
#fer
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //0x27F - 0X20F
#include "DHT.h"
#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int rele = 13;
int vcc = 11; //crear pines de 5v
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(rele,OUTPUT);
pinMode(vcc,OUTPUT);
dht.begin();
void loop() {
digitalWrite(vcc,HIGH);
int h = dht.readHumidity(); // Lee la humedad
int t = dht.readTemperature();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Humedad: ");
lcd.setCursor(8,0);
lcd.print(h);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temperatura: ");
lcd.setCursor(12,1);
lcd.print(t); // Escribe la atemperatura
lcd.print("C");
delay(2500);
if (t > 25)
digitalWrite(rele,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LAMPARA OFF");
delay(2000);
else
digitalWrite(rele,HIGH);
}
Control Key lcd dht
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define rele 3
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2);
const byte filas = 4; // número de filas '4'
const byte columnas = 4; // número de columans '4'
//Teclado matricial 4x4
char teclado [filas][columnas]={//variables del teclado
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte filaPines[filas]={11,10,9,8}; //configuración de filas del teclado matricial
byte columnaPines[columnas]={7,6,5,4}; // configuración de columnas del teclado matricial
Keypad teclar = Keypad (makeKeymap(teclado),filaPines, columnaPines, filas, columnas);
boolean inicio = false; // variables de control
char a[9];
int i=0;
int control=0;
int tempA=0;
int humdA=0;
String letra;
unsigned long long interv=2000,prev=0;
void setup()
dht.begin();
pinMode(rele, OUTPUT);
lcd.init();
//Encender la luz de fondo.
lcd.backlight();
// Escribimos el Mensaje en el LCD.
lcd.print("incubadora lucio y a ");
// lcd.begin(16,2);
Serial.begin(9600);
delay(3000);
lcd.clear();
void loop()
String ee = "T: ";
unsigned long long actual=millis();
if(actual-prev>=interv){
sensor();
ee.concat(tempA); ee.concat(" H: "); ee.concat(humdA);
}
lcd.setCursor(0,0);//Direccionaldo el cursor del LCD
char tecla = teclar.getKey();//
if(inicio){
String cc = "T ctrl: "; cc.concat(control);
lcd.print(cc);
lcd.setCursor(0,1);
lcd.print(ee);
if(tecla=='D'){
reset();
if(tempA>=control){
//digitalWrite(rele,HIGH);
digitalWrite(rele,LOW);
lcd.setCursor(14,1);
lcd.print("R1");
} else {
lcd.print(ee);
switch(tecla){
case '#':
lcd.clear();
control = atoi(a);
inicio = true;
//digitalWrite(rele,LOW);
digitalWrite(rele,HIGH);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if(atoi(a)<=50){
a[i] = tecla;
a[i+1]='\0';
i++;
letra.concat(tecla);
lcd.setCursor(0,1);
lcd.print(letra);
break;
case 'D':
reset();
break;
void reset(){
inicio = false;
for(int j=0; j<9; j++) {
a[j]='\0';
}
const int DHTPin = 5; // what digital pin we're connected to
DHT dht(DHTPin, DHTTYPE);
letra="";
lcd.clear();
digitalWrite(rele, HIGH);
void sensor(){
humdA = dht.readHumidity();
tempA = dht.readTemperature();
PiD-Codigo
/* Variables utilizadas en el controlador PID. */
unsigned long lastTime;
double Input, Output,Setpoint;
double errSum, lastErr;
double kp, ki, kd;
void Compute()
/* Cuanto tiempo pasó desde el último cálculo. */
unsigned long now = millis();
double timeChange = (double)(now - lastTime);
/* Calculamos todas las variables de error. */
double error = Setpoint - Input; errSum += (error * timeChange);
double dErr = (error - lastErr) / timeChange;
/* Calculamos la función de salida del PID. */
Output = kp * error + ki * errSum + kd * dErr;
/* Guardamos el valor de algunas variables para el próximo ciclo de cálculo. */
lastErr = error;
lastTime = now; }
/* Establecemos los valores de las constantes para la sintonización. */
void SetTunings (double Kp, double Ki, double Kd)
kp = Kp;
ki = Ki;
kd = Kd;