temperature sensor

Just another example of usefulness. This is a humidity and temperature sensor. Just powered by USB.

It consists of the following components:

It can be extended as follows. Connect a buzzer, alarm will sound when temperature or humidity falls outside a presettable threshold. Or better: connect it to the internet, for example to Pachube.

One Thought on “temperature sensor

  1. yoganerd on November 6, 2011 at 3:24 pm said:


    #include <Wire.h>
    #include <SeedGrayOLED.h>
    #include <avr/pgmspace.h<
    #define DHT22_PIN 0 // ADC0
    byte read_dht22_dat()
    {
    byte i = 0;
    byte result=0;
    for(i=0; i< 8; i++){
    while(!(PINC & _BV(DHT22_PIN))); // wait for 50us
    delayMicroseconds(30);

    if(PINC & _BV(DHT22_PIN))
    result |=(1<<(7-i));
    while((PINC & _BV(DHT22_PIN))); // wait '1' finish
    }
    return result;
    }
    void setup()
    {
    DDRC |= _BV(DHT22_PIN);
    PORTC |= _BV(DHT22_PIN);

    Wire.begin();
    SeeedGrayOled.init(); //initialize SEEED OLED display
    SeeedGrayOled.clearDisplay(); //Clear Display.
    SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
    SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
    SeeedGrayOled.setGrayLevel(12);

    delay(2000); // Recommended delay before sensor can be used
    }

    void loop()
    {
    SeeedGrayOled.setTextXY(0,0);
    SeeedGrayOled.setGrayLevel(12);
    byte dht22_dat[5];
    byte dht22_in;
    byte i;
    float humdity,temperature;
    // start condition
    // 1. pull-down i/o pin from 18ms
    PORTC &= ~_BV(DHT22_PIN);
    delay(18);
    PORTC |= _BV(DHT22_PIN);
    delayMicroseconds(40);

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

    dht22_in = PINC & _BV(DHT22_PIN);

    if(dht22_in){
    Serial.println("sc 1 not met");
    return;
    }
    delayMicroseconds(80);

    dht22_in = PINC & _BV(DHT22_PIN);

    if(!dht22_in){
    SeeedGrayOled.putString("sc 2 not met");
    return;
    }
    delayMicroseconds(80);
    // now ready for data reception
    for (i=0; i<5; i++)
    dht22_dat[i] = read_dht22_dat();

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

    byte dht22_check_sum = dht22_dat[0]+dht22_dat[1]+dht22_dat[2]+dht22_dat[3];
    // check check_sum
    if(dht22_dat[4]!= dht22_check_sum)
    {
    SeeedGrayOled.putString("checksum error");
    }
    humdity=((float)(dht22_dat[0]*256+dht22_dat[1]))/10;
    temperature=((float)(dht22_dat[2]*256+dht22_dat[3]))/10;
    SeeedGrayOled.putNumber(humdity);
    SeeedGrayOled.putString("% ");
    SeeedGrayOled.putNumber(temperature);
    SeeedGrayOled.putString("C ");
    delay(2000);
    }

Leave a Reply

Post Navigation