Greetings, I was working on a project with Arduino UNO and DHT22, reads temperature and humidity, makes some calculus and send the results to an 16x2 LCD screen
When I connected it to my desktop computer the LCD started working fine, but the measures are NAN for both values. But sometimes it sends some weird values like 12,7 Celsius and 3287,7% humidity (my temperature is around 25°) and then in the next measurement it goes back to NAN again, randomly
-
I have checked connections and everything seems to be in order
-
I have checked with another DHT22, same results
-
I tried this circuit before (for the first time) with a friend's laptop as a power source and it worked perfectly
I have checked this with many sample codes and the conclusion is that the problem should be either the power source of my computer , or both of my DHT22 are failing
Or maybe I just messed up the libraries?
This is the code I'm now using as a test
#include <LiquidCrystal.h>
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#include <DHT.h>
#define DHTPIN 7 //Pin 7 of Arduino UNO
#define DHTTYPE DHT22 //Define sensor as DHT22
DHT dht(DHTPIN, DHTTYPE);
float t;
float h;
void setup()
{
lcd.begin(16, 2);
dht.begin();
}
void loop()
{
delay(2500); //Tiempo de espera entre una lectura y otra. Para el DHT22 son 2 segundos
t = dht.readTemperature(); //Reads temperature
h = dht.readHumidity(); //Reads humidity
lcd.setCursor(0, 0); //Shows temperature
lcd.write("Temp.: ");
lcd.print(t);
lcd.write(" C");
lcd.setCursor(0, 1); //Shows humidity
lcd.write("Hume.: ");
lcd.print(h);
lcd.write(" %");
}
EDIT: problem solved, I added dht.begin(); in void_setup(). Thanks everyone for the help!
