2013年4月6日 星期六

Arduino Humidity Sensor DHT11 Tutorial


Description

The dht11 humidity sensor is an economic way to sense the humidity of the air in arduino projects.
  • Good for 20-80% humidity readings with 5% accuracy
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)

Hardware Required:


Wiring

To wire your Humidity DHT11 Sensor to your Arduino, connect the following pins:
  • DHT11 Pin 1 (Vss) --> Arduino +5V
  • DHT11 Pin 2 (Signal) --> Arduino Pin 2
  • DHT11 Pin 2 (Signal) --> Arduino +5V via Resistor 4.7K
  • DHT11 Pin 3 --> N/C
  • DHT11 Pin 4 (GND) --> Arduino Ground
 
 
 
 
 
 
 

Example Code

#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

double Fahrenheit(double celsius)
{
 return 1.8 * celsius + 32;
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);


  delay(2000);
}



Download Files

Arduino DHT11 Code (DHT11_Arduino_Tutorial.ino, 1 Kb) [Download]
DHT11 Library (DHT11.rar, 3 Kb) [Download]

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...