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]

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...