DHT11 doesn't work on raspberry pi 3 stretch.


This is my DHT11, and my connection is:

DHT11   <->   Rasp3  
VCC    <->   5V  
GND    <->   GND  
DOUT   <->   Pin#7 (GPIO 4)

and my code is on here

and the results from the code are always

Data not good, skip

I confirmed there's no error on DHT11 module.
I tested on Arduino Uno, it worked well.

How can I solve this?

ps.There's an ADC Converter MCP3208 on my circuit, which I suspect to be the cause of error.

2 Answers 2


This looks similar to what I did with a DHT11 temperature sensor with first a Raspberry Pi 3 and then with an Arduino.

The Arduino code is at this URL: https://github.com/RichardChambers/anduino_uno/blob/master/project01/dht11_sensor.ino

One thing that I did was to write the DHT11 function, onewireReadDHT11() in my source code, so that I could collect statistics on how the read function was working. What I found was that the counter value check needed to be around 25 for a Raspberry Pi 3. However for an Arduino the comparison value was much less. You may need to increase that value to more than 30 for a Raspberry Pi.

So an edited version of your read_dht11_dat() function with the if statement modified follows. The if statement checks the value of the variable counter which is really the width of the pulse received.

One thing you can do is to print the actual data received out as hex values and check that if the dht11_dat[] data is all zeros or all ones.

void read_dht11_dat() {
    uint8_t laststate = HIGH;
    uint8_t counter = 0;
    uint8_t j = 0, i;
    float f;

    dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;

    pinMode(DHTPIN, OUTPUT);
    digitalWrite(DHTPIN, LOW);
    digitalWrite(DHTPIN, HIGH);


    pinMode(DHTPIN, INPUT);

    for (i = 0; i < MAXTIMINGS; i++) {
        counter = 0;
        while(digitalRead(DHTPIN) == laststate) {
            if (counter ==255) break;

        laststate = digitalRead(DHTPIN);

        if (counter == 255)

        if ((i >= 4) && (i % 2 == 0)) {
            dht11_dat[j/8] <<= 1;
            if (counter > 25)       // this check is how long the pulse width is low.
                dht11_dat[j/8] |= 1;

    if ((j >= 40) && (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF ))) {
        f = dht11_dat[2] * 9. / 5. + 32;
        printf("Humidity = %d.%d %% Temperature = %d.%d C (%.1f F)\n",
               dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f);
    } else {
        printf("Data not good, skip \n");

DO NOT connect 5V to the Pi - you will blow it up.
The DHT11 will work from 3.3V.
You NEED a resistor ~4.7kΩ from 3.3V to DOUT - the device you pictured may have a resistor from VCC to DOUT.

You can use ANY pin.

NOTE There is an Overlay for the DHT22 (I have not used this myself).

Name:   dht11
Info:   Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors
  • Yes, there's a register from VCC to DOUT. I charged 3.3V from Pi 3 to DHT11. But it doesn't work.
    – Josh
    Jan 26, 2018 at 1:23
  • Without code it is not possible to say WHAT doesn't work.
    – Milliways
    Jan 26, 2018 at 2:39
  • There's on my code on my post. I solved this problem by activating 1-Wire. But it doesn't work completely. thx :D
    – Josh
    Jan 26, 2018 at 5:17
  • 1
    @Hyuck-JunLee the DHT11 temperature sensor does not use the 1 Wire protocol. See my explorations linkedin.com/pulse/… Jan 26, 2018 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.