-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy path6.2.2-DHT11.ino
More file actions
46 lines (41 loc) · 877 Bytes
/
6.2.2-DHT11.ino
File metadata and controls
46 lines (41 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
OpenJumper Examples
DHT11 Moudle
www.openjumper.com
*/
#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(DHT11.humidity);
Serial.print("Temperature (oC): ");
Serial.println(DHT11.temperature);
delay(1000);
}