2016/09/01

Arduino DHT11取得空氣中濕度及溫度

DHT11的Library是參考A DHT11 Class for Arduino

我買的DHT11是如下圖

腳位接法如下:


VCC接5V
DATA接Pin 2
GND接GND


程式碼:
#include <dht11.h>

#define PIN 2

dht11 DHT;

// the setup function runs once when you press reset or power the board
void setup() {
 Serial.begin(9600);
}

// the loop function runs over and over again until power down or reset
void loop() {
 int status = DHT.read(PIN);
 if (status == 0) {
  Serial.print((double)DHT.humidity, 2);
  Serial.print(",");
  Serial.println((double)DHT.temperature, 2);
  delay(1000);
 }
}



執行結果:






參考資料:
http://playground.arduino.cc/Main/DHT11Lib