Particle DHT data faulty

Hello I have this DHT sensor hooked up to my Spark core.

And I get the data on my dashboard but the data is incorrect, both variables show me 0 whilst that can’t be. I don’t think the error is in my code. I just get 0 % and 0°c. Could my sensor be broken?

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT.h"
// DHT parameters
#define DHTPIN 2
#define DHTTYPE DHT11
// Variables
int temperature;
int humidity;

// DHT sensor
void setup() {
    // Start DHT sensor
void loop() {
    // Humidity measurement
    temperature = dht.getTempCelcius();
    // Humidity measurement
    humidity = dht.getHumidity();
    // Publish data
    Spark.publish("temperature", String(temperature) + " °C");
    Spark.publish("humidity", String(humidity) + "%");


This is the library

/* DHT library 
 * MIT license
 * written by Adafruit Industries
 * modified for Spark Core by RussGrue
 * */

#ifndef DHT_H
#define DHT_H

#include "application.h"
#include "math.h"

// how many timing transitions we need to keep track of. 2 * number bits + extra
#define MAXTIMINGS 85

#define DHT11 11
#define DHT22 22
#define DHT21 21
#define AM2301 21

class DHT {
		uint8_t data[6];
		uint8_t _pin, _type, _count;
		unsigned long _lastreadtime;
		boolean firstreading;
		float readTemperature();
		float convertFtoC(float);
		float convertCtoF(float);
		float convertCtoK(float);
		float computeHeatIndex(float tempFahrenheit, float percentHumidity);
		float computeDewPoint(float tempCelcius, float percentHumidity);
		float readHumidity(void);
		boolean read(void);

		DHT(uint8_t pin, uint8_t type, uint8_t count=6);
		void begin(void);
		float getHumidity();
		float getTempCelcius();
		float getTempFarenheit();
		float getTempKelvin();
		float getHeatIndex();
                float getDewPoint();


I’d recommend that you check your wiring as well or even better post a picture or diagram of how things are wired.

Did you install the 10K pull-up resistor on the data pin (pin 2, second from the left with the waffle side facing you)?

You could also give the PietteTech_DHT library a spin, since it’s interrupt driven it won’t block your code in case of a stalling sensor.

BTW: I’m a bit puzzled about this part

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

If you had the library imported by Particle IDE (as the comment states), your include should look like this #include "Adafrauit_DHT/Adafruit_DHT.h"
Or have you added a new set of files and copy-pasted the library code?

I’m using this type of DHT sensor with the resistor in it.

Well actually it was like you mentioned it, but in the compiler it gave me this error in a popup.

You are not including Adafruit_DHT.h even though it is part of this app.

Are you sure you want to continue?

If you want to include this file, please hit cancel and add

#include "Adafruit_DHT.h"

to the top of the main app file.

*****So I added the directory for the adafruit_dht and flashed it anyways but still the same.

The wiring is as following,

D tot digital 02
V to vin on the core 5V
G to the gnd on the core.

May try the sample code that comes with the Particle Build library

Select the demo sketch and press USE THIS EXAMPLE

I has come so far that I’ve tried another sensor and sketch and when I compile it all is good. It says the flashing worked.
But it I still get the same faulty data of the last sketch. I even reset it and still get the data from the former sketch or build.

Try to flash some other code (e.g. Tinker or Blink-an-LED) to ensure your old code is gone and then only flash the unaltered sample sketch of the library and check the serial debug output.