Hi
I'm trying to read from 4 dht11
The problem is that the information from the sensors do not change ,and when i power the arduino the first screen is empty until i push the button .
#include <dht.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
dht DHT1;
dht DHT2;
#define dht1pin 7 // 7 to dht1pin
#define dht2pin 8 // 8 to dht1pin
int relay_pin = 9; //9 to relay
int switchPin = 10; // momentary switch on 10, other side connected to ground
int Display = 0;
LiquidCrystal_I2C lcd (0x27, 16, 2);
byte IN[8]= { // Array of bytes
B00100, // B stands for binary formatter and the 5 numbers are the pixels
B00100,
B00100,
B00100,
B11001,
B10101,
B10011,
B10001,
};
byte OUT[8]= { // Array of bytes
B11100, // B stands for binary formatter and the 5 numbers are the pixels
B10100,
B11101,
B00101,
B00111,
B11100,
B01000,
B01000,
};
byte NEW[8]= { // Array of bytes
B11100, // B stands for binary formatter and the 5 numbers are the pixels
B10100,
B11100,
B00110,
B01001,
B01000,
B01001,
B00110,
};
void setup() {
lcd.init();
lcd.backlight();
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); //turn on pullup resistor
lcd.createChar(7, IN); // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported
lcd.createChar(8, OUT);
lcd.createChar(9, NEW); // Create a custom *C
dht begin();
lcd.setCursor(0,0);
lcd.print("Hello Nonta");
delay(3000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("ARDUINO IS ON");
delay(2000);
lcd.clear();
pinMode(relay_pin, OUTPUT);
digitalWrite(relay_pin, HIGH);
}
/////-----------------------------------------------------------------------------------------------
void loop() {
if (digitalRead(switchPin) == LOW){
delay(500); //delay to debounce switch
Display ++;
if(Display > 3){ //this is for the menu to circle
lcd.clear();
Display = 1;
}
switch (Display) {
case 1: {
DHT1.read11(dht1pin); //define dht1pin 7
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.write(7); // Writes a IN to the LCD
lcd.setCursor(1,0);
lcd.print("T:");
lcd.print(DHT1.temperature,1); //prints DHT1 the 1 is how many digits after ,
lcd.print((char)9);
lcd.setCursor(10,0);
lcd.print("H:");
lcd.print(DHT1.humidity,0);
lcd.print("%");
if (DHT1.temperature > 31){
digitalWrite(relay_pin, LOW);
lcd.setCursor(15,0);
lcd.print("A");
delay(10);
}
else{
digitalWrite(relay_pin, HIGH);
lcd.setCursor(15,0);
lcd.print("K");
delay(10);
}
lcd.setCursor(0,1);
lcd.write(8); // Writes a OUT to the LCD
DHT2.read11(dht2pin);
lcd.setCursor(1,1);
lcd.print("T:");
lcd.print(DHT2.temperature,1);
lcd.print((char)9);
lcd.setCursor(10,1);
lcd.print("H:");
lcd.print(DHT2.humidity,0);
lcd.print("%");
}
break;
case 2: {
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("sensor 3");
}
break;
case 3: {
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Sensor 4");
}
break;
}
}
}
``[/code]