DHT 11 Send to Console 0% 0°C

Hi, could someone help me with an app for Photon? I am trying to use a DHT11 sensor, but the Photon sends 0% Hum. relative, and 0 ° C temperature to the console.
The code is:

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

int Hu,Te;
//An example of DHT11 for PHOTON
#define DHTPIN 	D2     // set pin

DHT dht(DHTPIN);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  //Read Humidity
  float h = dht.getHumidity();
  // Read temperature as Celsius
  float t = dht.getTempCelcius();
  
  Hu=(int)h;
  Te=(int)t;
  Serial.print(Hu);
  Serial.print(Te);
  Particle.publish("Te", String(Te) + " °C");
  delay(2000);
  Particle.publish("Hu", String(Hu) + "%");
  delay(2000);
}

image

The sensor is

Hi @utlaiotlabelectronic -

You can refer to the link below, they have a working example.

Or this one which includes BLYNK code:

Hope it helps.
Regards, Friedl.

1 Like

Hello, I have already tried this application, and I have used the same, very similar one with Arduino and it works well with Arduino, and I have 4 different sensors in case there were any damaged but they work very well I already tried many example apps and nothing.
I need to send data to one Html web page, which works perfectly I have tested it with voltage data and it works very well, a few years ago the application that I sent previously worked very well, but I don’t know what is the reason, when i try it again it no longer sent the variables, and I already checked the data in Putty and nothing

with arduino it’s similar, i just deleted the character strings since i don’t need them i just need to send the data of each variable

#include <DHT.h>
 
// Definimos el pin digital donde se conecta el sensor
#define DHTPIN 2
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11
 
// Inicializamos el sensor DHT11
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
  // Inicializamos comunicación serie
  Serial.begin(9600);
 
  // Comenzamos el sensor DHT
  dht.begin();
}
 
void loop() {
    // Esperamos 5 segundos entre medidas
  delay(5000);
 
  // Leemos la humedad relativa
  float h = dht.readHumidity();
  // Leemos la temperatura en grados centígrados (por defecto)
  float t = dht.readTemperature();
  // Leemos la temperatura en grados Fahreheit
  float f = dht.readTemperature(true);
 
  // Comprobamos si ha habido algún error en la lectura
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Error obteniendo los datos del sensor DHT11");
    return;
  }
 
  // Calcular el índice de calor en Fahreheit
  float hif = dht.computeHeatIndex(f, h);
  // Calcular el índice de calor en grados centígrados
  float hic = dht.computeHeatIndex(t, h, false);
 
  Serial.println(h);
  Serial.println(t);
}


thanks in advance, best regards

Have you tried a different library?
e.g. PietteTech_DHT?

For DHT11 you may need to increase the time in DHT.acquireAndWait(1000) to 2000 and also set DHTTYPE to DHT11.

BTW, to remove all doubt, can you also tell us how you have the sensor connected?

3 Likes

Hi ScruffR, I had already tried that example and all those that appear on the WEB IDE, but none, and as I mentioned, I have ruled out the possibility that the sensors are bad, I have tried the four that I have with Arduino and they work, the truth is that I no longer know what to do.

I didn’t say: “Have you tested a different sensor?”, tho’

To be specific:
Are you powering the sensor with 5V or 3.3V?
Have you got a 3pin or a 4pin sensor?
Do you have a sensor with builtin pull-up?
If not, have you got the pull-up in place?
What value?

2 Likes


The four sensors are 3-terminal powered at 3.3V, with arduino I tested it with both 5v and 3.3v, I know that a 10K resistor should be placed between the output pin and vcc when it has 4 pins but I don’t have those

image

image

image

thank you in advance

Hi ScruffR, Thank you very much, I already worked with the library you recommended, for some reason when I made a “Flash”, in the IDE it appeared successful but it did not load in the photon, the rgb led did not flash in a magenta color, for that I disconnected the photon, reconnected it, and reloaded the program.
image
So in the cloud
image

I thank everyone for your support
image

2 Likes

Good to hear you managed to resolve the problem

Regards, Friedl.

1 Like