DHT11 Humidity sensor not reading.
I am using a keyestudio DHT11 humidity sensor. I have checked the wiring multiple times, so I think it is correct. The error that it gives me switches randomly between 16,12 and 16,16. I have attached a photo of the arduino and where the wires are connected.

2 Replies
#include <SimpleDHT.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 4;
SimpleDHT11 dht11(pinDHT11);
void setup() {
Serial.begin(9600);
}
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
// read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); return; }
Serial.print("Sample OK: "); Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" H");
// DHT11 sampling rate is 1HZ. delay(1500); } Also heres the current code setup just realised that the red and black wire were in the wrong spot in the photo. I have corrected it but it is still giving me an error (this time 16,255) the black wire is now in the ground slot and the red is in the 5v slot
// read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); return; }
Serial.print("Sample OK: "); Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" H");
// DHT11 sampling rate is 1HZ. delay(1500); } Also heres the current code setup just realised that the red and black wire were in the wrong spot in the photo. I have corrected it but it is still giving me an error (this time 16,255) the black wire is now in the ground slot and the red is in the 5v slot
the code works, you likely still have the wires in the wrong places or the sensor was damaged by having Vcc & ground swapped.