Antes de nada agradecerte toda la ayuda que me estas dando!
Me di cuenta de lo de los valores y lo corregí y le he seguido añadiendo cosas y me funciona todo, lo unico que cuando recibo los datos no terminan de ser correctos, por ejemplo, cuando tapo la LDR para que me varien los lumenes tambien me varia la temperatura... esa es la unica pega que tengo de momento.
#include <LCD5110_Graph.h>
#include <Keypad.h>
#include <DHT11.h>
int LDR;
int LM35;
float milivol;
int valor;
float luz;
int sp_luz;
float hum;
int sp_hum;
float temp;
int sp_temp;
int pinboton=50;
int boton=0;
int salida;
int confirm;
int ventilador=10;
int leds=11;
int extractor=12;
int humificador=13;
float hume;
float tempe;
int numero=0;
int valtemp,valhum,valluz=0;
int key1,key2,key3;
int y0;
float y;
float k;
void setup()
{
Serial.begin(9600);
myGLCD.InitLCD(contrast);
pinMode(pinboton,INPUT);
pinMode(ventilador,OUTPUT);
pinMode(leds,OUTPUT);
pinMode(humificador,OUTPUT);
pinMode(extractor,OUTPUT);
k=-1;
y0=127;
//Consignas predefinidas
sp_temp=25;
sp_hum=30;
sp_luz=400;
}
////////////RECIBIR_TEMPERATURA//////////////
float lectura_lm35()
{
valor = analogRead(A7);
milivol = (valor / 1023.0) * 5000;
LM35 = milivol / 10;
delay(50);
return LM35;
}
////////////RECIBIR_HUMEDAD//////////////
float lectura_dht11()
{
dht11.read(hume,tempe);
delay(50);
return hume;
}
////////////RECIBIR_ILUMINACION//////////////
float lectura_ldr()
{
LDR=analogRead(A0);
LDR=analogRead(A0);
LDR=analogRead(A0);
// ilum = ((long)(1024-LDR)*A*10)/((long)B*Rc*LDR);
delay(50);
return LDR;
}
//////////////MENU_PRINCIPAL/////////////////
void pantalla1(){
temp=lectura_lm35();
hum=lectura_dht11();
luz=lectura_ldr();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("ORNYCLEAN",CENTER,0);
myGLCD.drawLine(0,10,83,10);
myGLCD.print("T= C",0,15);
myGLCD.print("H= %",0,25);
myGLCD.print("L= lumenes",0,35);
myGLCD.printNumI((temp),15,15);
myGLCD.printNumI((hum),15,25);
myGLCD.printNumI((luz),15,35);
myGLCD.update();
}
/////////////MENU_CONSIGNAS///////////////
void pantalla2(){
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("CONSIGNAS",CENTER,0);
myGLCD.drawLine(0,10,83,10);
myGLCD.print("T= C",0,15);
myGLCD.print("H= %",0,25);
myGLCD.print("L= lumenes",0,35);
myGLCD.printNumI((sp_temp),15,15);
myGLCD.printNumI((sp_hum),15,25);
myGLCD.printNumI((sp_luz),15,35);
myGLCD.update();
}
//////////ENVIAR_TEMPERATURA////////////
//int recibir_temperatura()
int pantalla3(){
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("TEMPERATURA",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.print("Pulse A para",CENTER,18);
myGLCD.print("introducir",CENTER,28);
myGLCD.print("valor",CENTER,38);
myGLCD.update();
if(numero==0){
confirm=Teclado.getKey();
if(confirm=='A'){
numero++;
salida=0;
myGLCD.clrScr();
myGLCD.update();}
}
myGLCD.setFont(SmallFont);
myGLCD.print("TEMPERATURA",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.update();
do{
if(numero==1){
key1=Teclado.getKey();
if(key1){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key1-48),20,20);
myGLCD.update();
numero++; }
}
if(numero==2){
key2=Teclado.getKey();
if(key2){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key2-48),35,20);
myGLCD.update();
numero++; }
}
if(numero==3){
key3=Teclado.getKey();
if(key3){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key3-48),50,20);
myGLCD.update();
numero++; }
}
if(Teclado.getKey()=='*'){
valtemp=(((key1-48)*100)+((key2-48)*10)+(key3-48));
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("GUARDADO",CENTER,20);
//Serial.println(valtemp);
myGLCD.update();
numero,key1,key2,key3=0;
delay(1500);
myGLCD.clrScr();
myGLCD.update();
salida++;
numero=0;
}
}while(salida==0 && numero!=0);
return valtemp;
}
//////////ENVIAR_HUMEDAD////////////////
//int recibir_humedad()
int pantalla4(){
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("HUMEDAD",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.print("Pulse A para",CENTER,18);
myGLCD.print("introducir",CENTER,28);
myGLCD.print("valor",CENTER,38);
myGLCD.update();
if(numero==0){
confirm=Teclado.getKey();
if(confirm=='A'){
numero++;
salida=0;
myGLCD.clrScr();
myGLCD.update();}
}
myGLCD.setFont(SmallFont);
myGLCD.print("HUMEDAD",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.update();
do{
if(numero==1){
key1=Teclado.getKey();
if(key1){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key1-48),20,20);
myGLCD.update();
numero++; }
}
if(numero==2){
key2=Teclado.getKey();
if(key2){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key2-48),35,20);
myGLCD.update();
numero++; }
}
if(numero==3){
key3=Teclado.getKey();
if(key3){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key3-48),50,20);
myGLCD.update();
numero++; }
}
if(Teclado.getKey()=='*'){
valhum=(((key1-48)*100)+((key2-48)*10)+(key3-48));
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("GUARDADO",CENTER,20);
//Serial.println(valhum);
myGLCD.update();
numero,key1,key2,key3=0;
delay(1500);
myGLCD.clrScr();
myGLCD.update();
salida++;
numero=0;
}
}while(salida==0 && numero!=0);
return valhum;
}
///////////////ENVIAR_ILUMINACION//////////////////
//int recibir_iluminacion()
int pantalla5(){
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("ILUMINACION",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.print("Pulse A para",CENTER,18);
myGLCD.print("introducir",CENTER,28);
myGLCD.print("valor",CENTER,38);
myGLCD.update();
if(numero==0){
confirm=Teclado.getKey();
if(confirm=='A'){
numero++;
salida=0;
myGLCD.clrScr();
myGLCD.update();}
}
myGLCD.setFont(SmallFont);
myGLCD.print("ILUMINACION",CENTER,5);
myGLCD.drawLine(0,13,83,13);
myGLCD.update();
do{
if(numero==1){
key1=Teclado.getKey();
if(key1){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key1-48),20,20);
myGLCD.update();
numero++; }
}
if(numero==2){
key2=Teclado.getKey();
if(key2){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key2-48),35,20);
myGLCD.update();
numero++; }
}
if(numero==3){
key3=Teclado.getKey();
if(key3){
myGLCD.setFont(BigNumbers);
myGLCD.printNumI((key3-48),50,20);
myGLCD.update();
numero++; }
}
if(Teclado.getKey()=='*'){
valluz=(((key1-48)*100)+((key2-48)*10)+(key3-48));
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("GUARDADO",CENTER,20);
//Serial.println(valluz);
myGLCD.update();
numero,key1,key2,key3=0;
delay(1500);
myGLCD.clrScr();
myGLCD.update();
salida++;
numero=0;
}
}while(salida==0 && numero!=0);
return valluz;
}
//////////CONTROL_PANTALLA///////////
void control_pantalla(){
if (digitalRead(pinboton)==HIGH && boton <5)
{
boton ++;
}
else if (pinboton && boton >4)
{
boton =0;
}
if (boton == 0)
{
pantalla1();
}
else if (boton == 1)
{
pantalla2();
}
else if (boton == 2)
{
sp_temp=pantalla3();
}
else if (boton == 3)
{
sp_hum=pantalla4();
}
else if (boton == 4)
{
sp_luz=pantalla5();
}
delay(100);
}
///////////CONTROL_VENTILADOR//////////////
void control_ventilador(){
if(temp <= sp_temp){
digitalWrite(ventilador,LOW);
}
else if(temp > sp_temp){
digitalWrite(ventilador,HIGH);
}
}
/////////////CONTROL_LUCES//////////////
void control_luces(){
y=y0+k*(sp_luz - luz);
y=constrain(y,0,255);
analogWrite(leds,y);
}
////////////CONTROL_HUMEDAD//////////////
void control_humedad(){
if(hum < sp_hum){
digitalWrite(humificador,HIGH);
digitalWrite(extractor,LOW);
}
if(hum > sp_hum){
digitalWrite(humificador,LOW);
digitalWrite(extractor,HIGH);
}
}
/////////////////////////////////
void loop(){
control_pantalla();
//control_ventilador();
//control_luces();
//control_humedad();
Serial.print(boton);
}
Si te fijas en las tres lecturas que hago, hay unos delay(50), con la idea de estabilizar un poco cada lectura pero nada.
Suprimo algunas partes para que quepa el mensaje xD