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]

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...