释放双眼,带上耳机,听听看~!
所述ESP8266 ESP-01被用作从所述Web服务器以显示温度和湿度信息DHT11传感器。
目录
步骤1:零件清单
- ESP8266 ESP-01
- DHT11温湿度传感器
- 4.7k电阻
步骤2:ESP8266 + DHT11 传感器接线
步骤3:将代码上传到ESP8266
**将“ ssid ”和“ password ” 更改为您的无线网络**
编译并上传代码至ESP8266。
[Code-generic:1] #include"ESP8266WiFi.h" #include"DHT11.h" const char* ssid = "ssid"; // Your ssid const char* password = "password"; // Your Password int pin = 2; WiFiServer server(80); DHT11 dht11(pin); double Fahrenheit(double celsius) { return ((double)(9 / 5) * celsius) + 32; } double Kelvin(double celsius) { return celsius + 273.15; } void setup() { Serial.begin(115200); delay(10); Serial.println(); // Connect to WiFi network WiFi.mode(WIFI_STA); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { int err; float temp, humi; if ((err = dht11.read(humi, temp)) == 0) { Serial.print("temperature:"); Serial.print(temp); Serial.print(" humidity:"); Serial.print(humi); Serial.println(); } else { Serial.println(); Serial.print("Error No :"); Serial.print(err); Serial.println(); } WiFiClient client = server.available(); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println("Refresh: 5"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); client.println("n"); client.println("ESP8266 Temperature & Humidity DHT11 Sensor"); client.println("n"); client.println("
ESP8266 & DHT11 Sensor
"); client.println("Humidity / Temperature"); client.println("
"); client.print("Humidity (%) : "); client.println((float)humi, 2); client.print("Temperature (°C) : "); client.println((float)temp, 2); client.print("Temperature (°F) : "); client.println(Fahrenheit(temp), 2); client.print("Temperature (°K) : "); client.println(Kelvin(temp), 2); client.println("
“);
client.println(“www.elec-cafe.com”);
client.print(“n
步骤4:串行监视器
检查ESP8266 Module的IP地址。
步骤5:Web监视器
通过ip地址打开Internet浏览器以显示温度和湿度信息
(至“自动刷新5秒”的页面)
(至“自动刷新5秒”的页面)
我这个做出来之后网页所有文本都在同一行里,println和print一个效果
网站系统将源代码破坏了,访问这个链接查看最新的代码:https://www.makersns.com/21952.html