Problem Dht22 + esp8266

Hello,
I have a problem with the dht22 sensor. Shows me incorrect values in cayenne iot and console. I mentioned that I changed the sensor dht22 and esp8266 because I thought they broke but the problem persists. What do you suggest I do?

#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTPIN 12
#define DHTTYPE DHT22 // DHT 22 (AM2302)

// WiFi network info.
char ssid = “…”;
char wifiPassword = “…”;

// Cayenne authentication info.
char username = “…”;
char password = “…”;
char clientID = “…”;

unsigned long lastMillis = 0;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
float temp = dht.readTemperature(true);
float hum = dht.readHumidity();
Cayenne.virtualWrite(0, temp, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(1, hum, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);

}


Thanks a lot.

you are missing dht.begin(); in void setup()

1 Like

Thank you very much! All it’s ok now. Have a great day!!! :slight_smile: