ahlam2
August 28, 2022, 9:41pm
1
hi,I'm using a esp8266 MOD with dht22 but i can't get any readings,this is following code and what i get on the serial moniter.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#define DHTPIN 6
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("Device Started");
Serial.println("-------------------------------------");
Serial.println("Running DHT!");
Serial.println("-------------------------------------");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t) ) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
delay(3000);
}
![image|690x280](upload://hGFYaxHuwUQ3EUVSQ8JQJcpeIT4.png)
any help!!!
LarryD
August 28, 2022, 9:48pm
3
Cannot see your image.
Add a delay to loop( ) to slow things down a bit:
delay(2000);
Try:
float hum; //Stores humidity value
float temp; //Stores temperature value
. . .
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
}
ahlam2
August 28, 2022, 9:58pm
4
tried it but nothing change
LarryD
August 28, 2022, 10:03pm
5
Before going further, please confirm that you can upload a simple sketch like Blink to your controller.
Let’s see your wiring ?
ahlam2:
return;
Probably not a good idea to return from loop(). If you remove this statement what happens?
system
Closed
February 24, 2023, 10:50pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.