DHT12 溫度.濕度感測器

https://yhhuang1966.blogspot.com/2015/08/arduino-dht11.html
https://github.com/Bobadas/DHT12_library_Arduino
/*
 * 2018.06.12
 * 按照DHP11接角位
 * 左1 3V
 * 左2 D0
 * 左3 空
 * 左4 GND
 */
#include "DHT.h"
#define DHTPIN D0 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 test!");
  dht.begin();
  }

void loop() {
  delay(1000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
    }
  Serial.print("濕度: ");
  Serial.print(h);
  Serial.print("%\t");

  Serial.print("溫度: ");
  Serial.print(t);
  Serial.print("*C\t");

  Serial.println(" ");
  }

沒有留言:

張貼留言