上課筆記
#include <SimpleDHT.h>
#include <BluetoothSerial.h>
BluetoothSerial BT;
//本例請將溫度計S腳接在GPIO 4
int pinDHT11 = 4;
SimpleDHT11 dht11(pinDHT11);
void setup() {
Serial.begin(115200);
BT.begin("test1030");//請改名
}
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000);
return;
}
//將溫濕度傳輸到藍芽裝置
BT.print((int)temperature);
BT.print(" *C,");
BT.print((int)humidity);
BT.println(" H");
delay(1000); //休息1秒
}
模擬器沒有這元件