标题:
arduino使用温度传感器DHT11测量程序
[打印本页]
作者:
liushenge
时间:
2018-1-9 16:10
标题:
arduino使用温度传感器DHT11测量程序
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 2
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("/n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
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);
delay(2000);
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1