DHT22 Returning Value of -7.00 on Photon w/ RelayShield

Hi folks,

After a bit of hassle I got the DHT to sort of work with the recommended “PietteTech_DHT/PietteTech_DHT.h” library. It was hanging and breathing green on the acquire and wait function, so I deleted it and the example switch case error reporting statements and I could get the program to loop and take readings.

However, now I’m only getting -7.0 as a return value for the other polling functions for temp/hum/dew point, etc.

That return value looks similar to what another user reported here:

What’s it mean?

Things I’ve tried:
Switching pins (D0,D2). Can’t use D3 - 6.
Switching the DHTTYPE from DHT22 to AM2302.
Creating a new sketch from the library example with the library automatically included to rule out library inclusion issues.

Hardware:
Photon
RelayShield
I have the SMAKN DHT22 that comes with a built in resistor (or two), and some presoldered pins. It was stated to be 3 - 5v capable.

Things I haven’t tried:
Powering with higher voltage.

Any other recommendations? Thanks in advance!

Could you provide an image (good resolution to see the exact wiring)?
Then I could copy that setup and try.

Welp, was tired of messing with it, so I gave the SMAKN thing 6v (my bench power supply only has 4.5 and 6 :confused: and let the magic smoke out; something fried inside. It was stated to handle 3 - 5.5v, so I guess that’s fair. Amazon is shipping a new one, without the ‘convenient’ pre-soldered resistor(s) and pins.

Thanks for offering to help.

Pitty that you deleted the image, but since I’m a mod, I could still see your problem.
I’d say it was actually the pins not being solderd in. Just having the Photon sitting on the header pins will never give you enough reliable contact to do anything with it.

I didn’t want to waste your time since I’d already fried the DHT22 by that point. As far as the headers, for a better test I should have soldered them on, you’re right, though that Photon is meant for something else not requiring headers. Thing is, when it was attached to my project, the headers were soldered on and I was getting the same thing. Hoping for better results this afternoon. Thanks again!

Not just as a test. Without them soldered on, there’s a very very slim chance you’ll be able to take readings at all. Also, I noticed that the D7 LED was on, which it shouldn’t be according to the code. Could it be that there was something else running?

The actual project was soldered, regardless, your advice is sound. I’ll solder my connections when testing in the future.

As far as the code, the image was taken with my project full code, but then I flashed the DHT_SIMPLE and tested that too, but got the same readings.

Thanks for your comments!

Running a code example from the Piette DHT library from October 2014.

This is a new unit from SMAKN without any pre-soldered stuff. I took @ScruffR and @Moors7 's advice and soldered the headers on, but I’m still getting -7.000000. Pretty sure I have a 10k resistor on there (its hard to tell, but its in #2, pulling signal up to 3.3v). Wired like these here.

Halp?

/*
 * FILE:        DHT_simple.ino
 * VERSION:     0.3
 * PURPOSE:     Example that uses DHT library with two sensors
 * LICENSE:     GPL v3 (http://www.gnu.org/licenses/gpl.html)
 *
 * Samples one sensor and monitors the results for long term
 * analysis.  It calls DHT.acquireAndWait
 *
 * Scott Piette (Piette Technologies) scott.piette@gmail.com
 *      January 2014        Original Spark Port
 *      October 2014        Added support for DHT21/22 sensors
 *                          Improved timing, moved FP math out of ISR
 */

#include "PietteTech_DHT/PietteTech_DHT.h"

#define DHTTYPE  DHT22       // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   2           // Digital pin for communications

//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
int n;      // counter

void setup()
{
    Serial.begin(9600);
    while (!Serial.available()) {
        Serial.println("Press any key to start.");
        delay (1000);
    }
    Serial.println("DHT Example program using DHT.acquireAndWait");
    Serial.print("LIB version: ");
    Serial.println(DHTLIB_VERSION);
    Serial.println("---------------");
}

// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
    DHT.isrCallback();
}

void loop()
{
    Serial.print("\n");
    Serial.print(n);
    Serial.print(": Retrieving information from sensor: ");
    Serial.print("Read sensor: ");
    //delay(100);
  
    
    Serial.print("Humidity (%): ");
    Serial.println(DHT.getHumidity(), 2);

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

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

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

    Serial.print("Dew Point (oC): ");
    Serial.println(DHT.getDewPoint());

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

    n++;
    delay(2500);
}

Solved. It was the library. I loaded the AdafruitDHT library an code example and it worked like intended.

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

//#include "Adafruit_DHT.h"

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

#define DHTPIN 2     // what pin we're connected to

// 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

DHT dht(DHTPIN, DHTTYPE);

void setup() {
	Serial.begin(9600); 
	Serial.println("DHTxx test!");

	dht.begin();
}

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

// 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();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}

// Compute heat index
// Must send in temp in Fahrenheit!
	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();

	Serial.print("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr());
}
1 Like

That’s odd.
The Piettetech library is the most stable one for my DHT sensors, I had lockups with the others.

However, good to know, you got yours running :+1:

2 Likes

That’s why I started with it. But I had lockups with it and the example code, and then couldn’t get good data returned from the sensor(s). So I don’t know, the Adafruit one just worked.

Its running like a champ and I was able to finally do install after messing around for a few days figuring this stuff out. Thanks again.

I am using both, they are both pretty stable, IMHO.

I had the same problem occur using an AOSONG AM2302 … I found this thread searching for a solution.
In the end, I re-did my breadboard and re-flashed the same code; afterwards it worked perfectly.
My assumption is that one of the hardware connections was not quite right and that was the cause of my problem.

Hope this helps!