#include "DHT.h" #include #include #include #define BLYNK_PRINT Serial #define DHTPIN D0 // Digital pin connected to the DHT sensor #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 /* Fill in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPLWrxBiYNN" #define BLYNK_TEMPLATE_NAME "XIAO32 00" #define BLYNK_AUTH_TOKEN "YOUR_BLYNK_AUTH_TOKEN" DHT dht(DHTPIN, DHTTYPE); BlynkTimer timer; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "Color"; char pass[] = "YOUR_WIFI_PASS_HERE"; void sendSensor() { int btn = digitalRead(D1); float h = dht.readHumidity(); float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.println(F("°C ")); Serial.print(F("BottonState: ")); Serial.println(btn); if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V1, btn); Blynk.virtualWrite(V2, h); Blynk.virtualWrite(V3, t); } void setup() { // Debug console Serial.begin(9600); dht.begin(); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); timer.setInterval(1000L, sendSensor); } void loop() { Blynk.run(); timer.run(); sendSensor(); }