Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

DHT11 AND ESP8266

Status
Not open for further replies.

bravehamid

New Member
Hi, good afternoon
I have a dht11 and esp8266(wemos d1 mini) when they connect together and source with the usb that I give to my esp8266 it works fine but when they are connect to source my board, dht11 does not work but esp works good. where is it the problem?
 
As pms said 10 k pullup, and if thats not it tray a 100nf across the Dht power.
 
Ok, does the library file need to be told what crystal frequency you are using?
 
Which pin on the ESP are you connecting to the DATA pin on the sensor.
 
I couldn't get the library to work reliably so I wrote my own code.
It's a little long due to adding timeout and error checking.
Calling readDHT will return true if it's successful.

Mike.
Code:
#define DHT D4
uint8_t DHTbuf[5]; 
uint8_t error;

uint8_t readDHT(){
  error=false;
  pinMode(DHT,OUTPUT);
  digitalWrite(DHT, LOW); 
  delay(2);
  digitalWrite(DHT, HIGH); 
  delayMicroseconds(40);
  pinMode(DHT,INPUT_PULLUP);
  waitLow();
  if(error){     //is sensor pulling low
    Serial.println("DHT not present");
    return false;             //no, so return
  }
  uint8_t i,j;
  waitHigh();
  waitLow();
  for(i=0;i<5;i++){
    for(j=0;j<8;j++){
      waitHigh();
      delayMicroseconds(40);
      DHTbuf[i]<<=1;
      if(digitalRead(DHT)==1)
        DHTbuf[i]++;
      waitLow();
    }
  }
  uint8_t sum = DHTbuf[0] + DHTbuf[1] + DHTbuf[2] + DHTbuf[3];
  if (DHTbuf[4] != sum) 
    return false;
  return !error;
}

void waitLow(){
  if(error)
    return;
  uint16_t timeout=2000;
  while(digitalRead(DHT)==1 && --timeout>0);
  if(timeout>0)
    return;
  error=true;
}

void waitHigh(){
  uint16_t timeout=2000;
  if(error)
    return;
  while(digitalRead(DHT)==0 && --timeout>0);
  if(timeout>0)
    return;
  error=true;
}
 
Nice work Pommie.

I didn't know you were taking such detailed requests.
Now, I've been meaning to write code to pull return laser signal strength from the Garmin Lidar Lite v3. It is beyond the basic functionality of the LidarLite library so it needs a scratch-built solution.
 
No No ,my code is corrected becouse it's work with usb power when it's connected to power external not send data from dht11.
my dht11 connected to D5(gpio14)
 
Try just flashing the LED to make sure it's executing the code when not powered via USB.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top