อุปกรณ์
1.NodeMcu V3 CH340 Lua WIFI ESP8266-12E
2.DHT11 เซ็นเซอร์วัดอุณหภูมิและความชื้น พร้อม PCB แถมสายไฟ
โค้ด
#include "DHT.h"
DHT dht;
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
dht.setup(2);
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);
delay(1000);
}
-----------------------------------------------------------------------------
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h"
DHT dht;
char auth[] = "M-Ee2Vubx7Pf5DbN8_5SFvSAjkSCNB_0";
char ssid[] = "MR DOM";
char pass[] = "audomidea2019";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
dht.setup(D4);
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity(); // ดึงค่าความชื้น
float temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);
Blynk.run();
delay(100);
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, humidity);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น