I made a circuit that takes humidity and temperature from DHT22 sensor and displays it on Lcd Screen. Simple enough but i get this error "Failed to read from DHT". That happens because i have this code
if (isnan(t) || isnan(h)) {
delay(100);
Serial.println("Failed to read from DHT");
} else {
delay(100);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
//lcd.print("Temp: ") ;
//lcd.print(t);
//lcd.setCursor(0, 1);
//lcd.print("Hum: ") ;
//lcd.print(h);
}
So the values are NaN . But 1 minute before it worked fine, and now again it doesnt. Everything is soldered the right way and nothing is false. Lcd is wired ok and it works but i dont get values from DHT22.
Here are some pics to help you out.
In the third Image we see its working. And now its not! is the DHT sensor broken?
#include "DHT.h"
#include <LiquidCrystal.h>`
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT22 test!");
lcd.begin(16, 2)
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
lcd.print("Hum: ");
lcd.print(h);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(t);
}
}
Thats my code by the way
#include "DHT.h"
#include <LiquidCrystal.h>
#define DHTPIN 2 #define DHTTYPE DHT22 // DHT 22 (AM2302) LiquidCrystal lcd(12, 11, 5, 4, 3, 2); DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHT22 test!"); lcd.begin(16, 2) dht.begin(); } void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { lcd.print("Hum: "); lcd.print(h); lcd.setCursor(0, 1); lcd.print("Temp: "); lcd.print(t); } }`