DHT11 TEMPERATURE AND HUMIDITY SENSOR

#include <SimpleDHT.h>

//www.elegoo.com
//2016.12.9

#include <SimpleDHT.h>

// for DHT11, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11;

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

void loop() {
  // start working...
  Serial.println("=================================");
  Serial.println("Sample DHT11...");
  
  // read with raw sample data.
  byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
    Serial.print("Read DHT11 failed");
    return;
  }
  
  Serial.print("Sample RAW Bits: ");
  for (int i = 0; i < 40; i++) {
    Serial.print((int)data[i]);
    if (i > 0 && ((i + 1) % 4) == 0) {
      Serial.print(' ');
    }
  }
  Serial.println("");
  
  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" %");
  
  // DHT11 sampling rate is 1HZ.
  delay(1000);
}

Did everything as it was stated even went back and did previous projects to see if it had anything to do with data lines. Still same result looping failure. Think it may have something to do with the timing of the internal clocks. Tried resetting still the same results. Makes more sense seeing how every once in awhile it will post results with a normal trigger of a clock pulse seeing how 3 clock states are used leading level and trailing. Read that if you inject a signal you must reset the clocks using a logic zero while doing so.

Hi,
Welcome to the forum.

What doesn't your code do?
Does it compile?
You did everything stated, where?

Have you got the right leads on the DHT11, as there are four leads.

Have you got the pull-up resistor fitted, or are you using a DHT11 mounted on a PCB with resistor fitted?

Tom.... :slight_smile: