I have a DHT11 sensor on a 3-pin breakout board with a 10k resistor on the board between the Vcc and signal lines. This should be a very straight forward sensor with VCC connected to the Photon 2 3.3 pin; ground to ground and the signal wire is connected to D4.
Using the following code
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT_Particle.h>
#define DHTPIN D4 // Define the pin connected to the DHT sensor
#define DHTTYPE DHT11 // Define the type of DHT sensor
DHT DHT(DHTPIN, DHTTYPE); // Initialize the DHT sensor
void setup() {
Serial.begin(9600); // Start serial communication at a baud rate of 9600
DHT.begin(); // Initialize the DHT sensor
}
void loop() {
// Read humidity and temperature values
float humidity = DHT.getHumidity();
float temperature = DHT.getTempCelcius();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
} else {
// Print the results to the serial monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%, Temp: ");
Serial.print(temperature);
Serial.println(" Celsius");
}
delay(10000); // Wait for 30 seconds before reading again
}
I get the following results.
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Humidity: 0.00%, Temp: 0.00 Celsius
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Humidity: 0.00%, Temp: 0.00 Celsius
Humidity: 0.00%, Temp: 0.00 Celsius
Humidity: 0.00%, Temp: 0.00 Celsius
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Any ideas on why I can't pull simple temperature and humidity readings with the Photon 2 and this sensor? I've had the same results with another sensor, both are known good. I've also had the same results when trying a DHT22 and similar code.
I also loaded the sample code that comes with the library and get these values...
Humid: 160.00% - Temp: 128.00C 262.40F 401.15K - DewP: 143.98C - HeatI: 3629.76C
Thu Jan 11 02:28:39 2024
Failed to read from DHT sensor!
Humid: 176.00% - Temp: 128.00C 262.40F 401.15K - DewP: 147.39C - HeatI: 4043.13C
Thu Jan 11 02:28:50 2024
Failed to read from DHT sensor!
Humid: 0.00% - Temp: 0.00C 32.00F 273.15K - DewP: nanC - HeatI: -8.78C
Thu Jan 11 02:29:00 2024
Failed to read from DHT sensor!
Humid: 160.00% - Temp: 128.00C 262.40F 401.15K - DewP: 143.98C - HeatI: 3629.76C
Thu Jan 11 02:29:10 2024
Failed to read from DHT sensor!
Humid: 128.00% - Temp: 0.00C 32.00F 273.15K - DewP: 3.45C - HeatI: 21.45*C
Thu Jan 11 02:29:20 2024