DHT22 returns temp = 0, hum = 6553

Hi @BenHadman and @Blacksmithash.
I too have exactly the same problem with my DHT22 AM2302 sensor. Do any of you manage to fix this?
I tried my DHT11 sensor and had a similar problem. It only returned hum = 255% and temp = 0.
Regards

Hi again!
Changing the library from <Adafruit_DHT.h> to <Adafruit_DHT_Particle.h> fixed my problem with the DHT22 AM2302 sensor.
I hope this works for you as well!
Regards

2 Likes

Neither of use could fix it!
I’ve opted to a new sensor type.

Got it to work! Thanks!
Weird - because I already tried that and the example code for it… I was about to try a different sensor.

1 Like

What did you do to fix? care to share the code and wiring?
Desperate to get this working.

I know the feeling. Code below. Note that I’ve incorporated the Udibots online trending app.

// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT_Particle.h>

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#define DHTPIN D2           // Using D2 as the Data pin

#ifndef TOKEN
#define TOKEN " NOT ACTUALLY THE TOKEN "  // Put here your Ubidots TOKEN 
#endif

Ubidots ubidots(TOKEN, UBI_TCP); // Comment this line to use another protocol.
//Ubidots ubidots(TOKEN, UBI_HTTP); // Uncomment this line to use HTTP protocol.
//Ubidots ubidots(TOKEN, UBI_UDP); // Uncomment this line to use UDP protocol

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11		// DHT 11 
#define DHTTYPE DHT22		// DHT 22 (AM2302)
//#define DHTTYPE DHT21		// DHT 21 (AM2301)


// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// This is the authorisation code for sending data to Blynk. Don't show anyone.
char auth[] = " BLYNK AUTHORISATION CODE ";

// Tell the DHT code what pin and sensor we have
DHT dht(DHTPIN, DHTTYPE);

//  Value for loop if you want to send particle to sleep
//int loopCount;

//  Code for creating a virtual pin we're writing to
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // process received value
}

BLYNK_WRITE(V2)
{
    int pinValue = param.asInt(); // assign incoming value from pin V2 to a variable
    // process received value
}


void setup() {
	Serial.begin(9600); 
	Serial.println("DHT22 test!");
	Particle.publish("state", "DHT22 test start");

//  Start the DHT sensor
	dht.begin();
	//loopCount = 0; THIS IS NOT REALLY REQUIRED BUT I'VE LEFT IT IN.
//  Wait time for settling
	delay(5000);

//  Start Blynk code and give it authority
    Blynk.begin(auth);
    
    ubidots.setDebug(true); // Uncomment this line to print debug messages
    
}

void loop() {
    
// Wait a few seconds between measurements.
	delay(2000);
    Blynk.run();
    

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
	float h = dht.getHumidity();
// Read temperature as Celsius
	float t = dht.getTempCelcius();

	
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}
	
  
//  Write values to virtual pins
    Blynk.virtualWrite(V1, t);
    Blynk.virtualWrite(V2, h);

    ubidots.add("Variable_Name_One", t); // Change for your variable name.
    ubidots.add("Variable_Name_Two", h);
    
    bool bufferSent = false;
    bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id

    if(bufferSent){
    // Do something if values were sent properly
    Serial.println("Values sent by the device");
    }
    

//  Write values to  serial display
	Serial.print("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.println(Time.timeStr());
	String timeStamp = Time.timeStr();
	Particle.publish("readings", String::format("{\"Hum(\%)\": %4.2f, \"Temp(°C)\": %4.2f}", h, t));
	delay(10000);
	
	/*loopCount++;
	if(loopCount >= 6){
	  Particle.publish("state", "Going to sleep for 5 minutes");
	  delay(1000);
	  System.sleep(SLEEP_MODE_DEEP, 300);  
	}*/

}

Thanks so much for sharing, i got to work with your code!

Excellent.
The strange thing for me is that I had tried this example code before.

I had the same issue and the solution worked for me as well. Just changed the library to <Adafruit_DHT_Particle.h> and it worked.

Updated all my photons from 2.1.0 to 2.2.0 and now all my DHT22 sensors read 0 temp and 6553 humidity. I’m unable to roll back the firmware.
I have tired both libraries and nothing works now :frowning:
Just hosed my whole network of sensors :frowning:
Any help?

Update: This is what solved my issue for now