Shop OBEX P1 Docs P2 Docs Learn Events
DHT11 Temp/Humidity sensor — Parallax Forums

DHT11 Temp/Humidity sensor

Gary WilkersonGary Wilkerson Posts: 3
edited 2011-04-08 17:55 in BASIC Stamp
Has anyone interfaced to this sensor? I'm having problems reading the 40 bit stream. Any examples would be appreciated.

Gary

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-11 19:04
    Looks like this is big with the arduina crowd.
    Details are sketchy. Found a datasheet of sorts and a page with arduina code.
    It's "9600", but I don't know if their convention is 'True' or 'Inverted'.
    Are you using a BS2 of some sort?
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-03-15 15:50
    You can find related advice near the bottom of this page on Earth Measurements.
    http://www.emesystems.com/BS2index.htm
  • Gary WilkersonGary Wilkerson Posts: 3
    edited 2011-03-22 18:28
    PJ and Kirk,

    Sorry for the delay responding; I had to make an unexpected trip to Chicago. It is big with the Arduina crowd, I was attracted to the price. I am using a BS2. I think the problem I'm having is parsing the string.

    I'll take a look at the emesystems link.

    Thanks!
    Gary
  • JAGOJAGO Posts: 49
    edited 2011-03-30 11:35
    Hi Gary,

    I hope you are ok, i have the same problem with the DHT11 sensor, i try to connect to the basic stamp 2, but i can't... i would like to know if you solve the problem or not??? i'm continue trying with the sensor if i have good news... i'll notify you.

    Greetings
  • JAGOJAGO Posts: 49
    edited 2011-03-30 12:16
    This is the code of the sensor DHT11 for arduino.. it's writed in C, i try to traduce to PBASIC, if any have some idea to do this is welcome...

    Best regards..

    #define DHT11_PIN 0 // ADC0

    byte read_dht11_dat()
    {
    byte i = 0;
    byte result=0;
    for(i=0; i< 8; i++){


    while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
    delayMicroseconds(30);

    if(PINC & _BV(DHT11_PIN))
    result |=(1<<(7-i));
    while((PINC & _BV(DHT11_PIN))); // wait '1' finish


    }
    return result;
    }


    void setup()
    {
    DDRC |= _BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);

    Serial.begin(19200);

    Serial.println("Ready");
    }

    void loop()
    {
    byte dht11_dat[5];
    byte dht11_in;
    byte i;
    // start condition
    // 1. pull-down i/o pin from 18ms
    PORTC &= ~_BV(DHT11_PIN);
    delay(18);
    PORTC |= _BV(DHT11_PIN);
    delayMicroseconds(40);

    DDRC &= ~_BV(DHT11_PIN);
    delayMicroseconds(40);

    dht11_in = PINC & _BV(DHT11_PIN);

    if(dht11_in){
    Serial.println("dht11 start condition 1 not met");
    return;
    }
    delayMicroseconds(80);

    dht11_in = PINC & _BV(DHT11_PIN);

    if(!dht11_in){
    Serial.println("dht11 start condition 2 not met");
    return;
    }
    delayMicroseconds(80);
    // now ready for data reception
    for (i=0; i<5; i++)
    dht11_dat = read_dht11_dat();

    DDRC |= _BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);

    byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
    // check check_sum
    if(dht11_dat[4]!= dht11_check_sum)
    {
    Serial.println("DHT11 checksum error");
    }

    Serial.print("Current humdity = ");
    Serial.print(dht11_dat[0], DEC);
    Serial.print(".");
    Serial.print(dht11_dat[1], DEC);
    Serial.print("% ");
    Serial.print("temperature = ");
    Serial.print(dht11_dat[2], DEC);
    Serial.print(".");
    Serial.print(dht11_dat[3], DEC);
    Serial.println("C ");

    delay(2000);
    }
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-30 13:57
    Either of you DHT11 fans have a proper datasheet for it?
  • JAGOJAGO Posts: 49
    edited 2011-03-31 08:53
    Hi PJ,

    this is the datasheet for this sensor..http://www.robotshop.com/PDF/dht11.pdf

    thanks
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-31 16:41
    Conceivably this could be done with PULSIN.

    Each bit is preceded by a 50us low time with the following
    high time determining the data_bit's value, a "0" is 26-28us and
    a "1" is 70us.

    I doubt that any Stamp is fast enough to
    decide 0-or-1 (or 0-or-not0) on the fly.
    You have to establish a VAR array, take in those times/transitions
    and then interpret the results (later.)

    A bit transmission always begins with the 50us (!!) low time - that's the
    time you/it has to stash in RAM the PULSIN val result and get ready for
    the next incoming data_bit/pulse_time.

    I may be wrong, but a BS2sx or BS2px will be required for the speed
    and the scratchpad RAM.
    (It's very SX'able and Propeller easy.)

    Post Edit -- If you don't take in the 8 error check bits at the end, then you cut your RAM requirements from 40bytes to 32. [It's a byte for the pulsin_time taken by each data_bit (40 or 32.)]
  • Gary WilkersonGary Wilkerson Posts: 3
    edited 2011-04-08 17:55
    PJ,

    I think you're right. I didn't consider the speed of the processor and it being unable to respond to/ detect the states.

    Need to look further, thanks for the help.

    Gary
Sign In or Register to comment.