Wrong reading value for DH22 & get stuck after running for a while

i am using the DH22 temperature and humidity sensor, the diagram is followed as below
the resistor is 10k.
and the real prototyping is followed as

I used the idDHT22 library and flash the example to the spark core, the https://build.spark.io/build/552d27aa35214344c500101c#.
the application runs however with two issues.

  1. through the serial port, the output is like

Retrieving information from sensor: Read sensor: OK
Humidity (%): 921.60
Temperature (oC): 640.00
Temperature (oF): 1184.00
Temperature (K): 913.15
Dew Point (oC): 1433.56
Dew Point Slow (oC): 2105.25

  1. after running for a while the sensor output will stop for some reason, I guess it is stuck in the problem in this part

while (DHT22.acquiring())

and because of the problem stuck, I even can’t flash the new code into the spark core unless with good luck
does anyone experience the same issue ?

currently I am using the code provided by the library.

#include "idDHT22/idDHT22.h"

// declaration for DHT11 handler
int idDHT22pin = D4; //Digital pin for comunications
void dht22_wrapper(); // must be declared before the lib initialization

// DHT instantiate
idDHT22 DHT22(idDHT22pin, dht22_wrapper);

void setup()
	while(!Serial.available()) {
	    Serial.println("hit a key");
	Serial.println("idDHT22 Example program");
	Serial.print("LIB version: ");
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht22_wrapper() {
void loop()

	Serial.print("\nRetrieving information from sensor: ");
	Serial.print("Read sensor: ");
	while (DHT22.acquiring())
	int result = DHT22.getStatus();
	switch (result)
			Serial.println("Error\n\r\tChecksum error");
			Serial.println("Error\n\r\tISR Time out error");
			Serial.println("Error\n\r\tResponse time out error");
			Serial.println("Error\n\r\tData time out error");
			Serial.println("Error\n\r\tDelta time to small");
			Serial.println("Error\n\r\tNot started");
			Serial.println("Unknown error");
	Serial.print("Humidity (%): ");
	Serial.println(DHT22.getHumidity(), 2);

	Serial.print("Temperature (oC): ");
	Serial.println(DHT22.getCelsius(), 2);

	Serial.print("Temperature (oF): ");
	Serial.println(DHT22.getFahrenheit(), 2);

	Serial.print("Temperature (K): ");
	Serial.println(DHT22.getKelvin(), 2);

	Serial.print("Dew Point (oC): ");

	Serial.print("Dew Point Slow (oC): ");


Give the Piettetech library a shot. It’s probably the most reliable one out there. Others have been know to have blocking/crashing issues, whereas the Piettetech one seems to work nicely.

We can’t see your code like that. You’ll have to copy&paste it. Take a look at the formatting guides before you do so please.


I’ve been using the Adafruit_DHT.h library with great success…

you may also want to consider also putting a decoupling capacitor on the DHT sensor (across Vin and ground on your sensor). You may be getting some ripple when the Core’s WiFi kicks in.

Hi, @BulldogLowell , how much the capacitor do i need ? and is this capacitor in between the 3.3 v PIN and GND pin?

hi,@Moors7, I have uploaded the code examples from the DH22 library provided by the spark.
Are you referring to this library, https://github.com/piettetech/PietteTech_DHT ?

Yes, this one :

I’d start with 100nF and go up from there if i didn’t see the problem go away.

you could also try your delay( ) before you read the sensor… let the power come up before you take a reading. though I’m not sure if delay( ) is truely blocking on the Core, It’s a small mod that will cost you nothing.

@helxsz From your picture it looks like you are using a DHT11 sensor. Make sure you are defining the DHTTYPE correctly.

#define DHTTYPE DHT11

The timings are different for the DHT22 and DHT11. This could also explain why your numbers are too high, the DHT11 returns a different format than the DHT22.

1 Like

I don’t know what are are working on I just wanted to provide a “share” to the community, incase you are looking for a sensor that won’t give you headaches down the road.

imho the DHT22 good sensor for tinkering, and that’s about it. I evaluated a bunch of sensors early this year and all the DHT22 sensors got hung up eventually (regardless of the different libraries of code). I got some to just all together break, granted I was pretty tough on them in our temp and RH chamber (-20 - 70C ~30-95% RH cycled continuously for about a month). Also they where the least repeatable of the sensors I evaluated (sensor to sensor difference). Honeywells are good sensors but expensive, the winner of my testing (and the one I am using for my day job) is the si7021 by silicon labs. It uses i2c and “just worked” it was very accurate and had better pricing than honeywell… The best part… It never “hung” not once in 1 month of testing, no special library, just Wire., it just happily provided temp and RH everytime I polled it (once a second). I will be ordering sensor boards in about a week (tiny board with a si7021 and a 4 pin 0.1 pin header (VCC, SCL, SDA, GND) holler if you want one.


Hi @helxsz

Maybe it is not as obvious as it could be, but the libraries you see in the web-based IDE are in fact user-contributed libraries not provided by the Spark team. Most of the libraries are really high-quality ports from similar Arduino libraries but sometimes people have differing setups or goals so results can differ. Lots of folks have had good results with @mtnscott 's library for these DHT parts.

As @jerome has rightly pointed out, the DHT series of sensors are somewhat on the low-end of what you can get today.

1 Like

I agree, they are from a long ago era of Arduino parts for breadboarding. There are many other sensors today that have much better accuracy and I agree with @jerome’s comments that I2C is a solid interface for communicating with onboard sensors. For off-board sensors the Dallas line of temperature sensors are very good inexpensive sensors and the Wire library is more robust.

Many vendors make humidity and temperature sensors, Silicon Labs, Sensirion, Bosch, Measurement Specialities. They are all SMD. This is why people learn using the DHT and AM series sensors. Not many breakouts using the SMD sensors - and the ones available are very expensive compared to the part itself, and typically not the current part.

@jerome what sensors did you test ? I was going to use the Silicon Labs si7006 series for my project, do you have any experience with the Bosch BME? It’s new and offers pressure, temp, and humidity in one package.

I will be removing my (way less reliable) idDHT library since the piettetech one is much better. :smile:


Hi, @jerome, I want to try the si7021 sensor, but hard to find it in UK with breakout, :frowning:
@mtnscott, Bosch BME seems good, but might be costly

They are impossible to find anywhere with a breakout :frowning: That’s why I had to make one… I don’t have any experience with the BME. There should be a break-out board sharing zone somewhere… (maybe there is I will need to google it) I have made quite a few boards to integrate with the sparkcore for my own use.

1 Like

i can find the breakout in China, guess what, 3 dollars for each . I think the factories there make them for the DIY.


Interesting topic - breakout boards.

I wonder if anyone is interested in the following -

RTC w/ battery backup - MCP7940
EEPROM - 64Kb - 24LC64F
4-bits of I/O attached to LED’s - PCA9536

All connected on I2C, 4 pins (3.3v, GND, SCL, SDA).

I put it together to support a project that needed battery backed RTC, high cycle EEPROM and LED’s.

Most of the breakouts are based on older chips, not really anything you can turn into a product - as less expensive parts are typically the newer parts.

PM me if your interested.


Your DHT22 (or 11) should still work… with about ±1F° accuracy if you have the library setup correctly and appropriate power. The sensor likes 3.3 to about 6V (from memory) so you could also look to power it from your Vin instead of 3V3 pin; powering it with 5Volts instead.

…things to try while you wait for your little envelope from the PRC.

1 Like

Any experience with your chinese breakout so far?