工具

  • ESP8266核心板
  • DHT11温湿度检测模块
  • 杜邦线

实验连线

将ESP8266核心板的“D4”与DHT11模块的“out”相连,“3V”与“+”相连,“G”与“-”相连。

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#define BLINKER_WIFI

#include <Blinker.h>
#include <DHT.h>

char auth[] = "ecdc2388f56f";
char ssid[] = "CMCC-AAA";
char pswd[] = "123456789";

BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");

#define DHTPIN D4

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

float humi_read = 0, temp_read = 0;

void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
}

void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
dht.begin();
}

void loop()
{
Blinker.run();

float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
}

Blinker.delay(2000);
}

点灯软件控制
855774855af8de79e9a0dbaa5fb1515c.png