#define BLYNK_TEMPLATE_ID "TMPL6zTG4BTtu"
#define BLYNK_TEMPLATE_NAME "Wokwi Blynk"
#define BLYNK_AUTH_TOKEN "VPm_uaZv2izpd9tZ0sDIBfElSyfsn27o"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
#include <Adafruit_NeoPixel.h>
#define PIN_WS2812B 16 // The ESP32 pin GPIO16 connected to WS2812B
#define NUM_PIXELS 30 // The number of LEDs (pixels) on WS2812B LED strip
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
//Name of router and password
const char* ssid="Wokwi-GUEST";
const char* password="";
const int DHT_PIN = 15;
DHTesp dhtSensor;
BlynkTimer timer;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
ws2812b.begin(); // initialize WS2812B strip object (REQUIRED)
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
WiFi.begin(ssid,password);
Serial.println("connecting to wifi.......");
//conect divice wifi
while (WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("connected");
Serial.print("WiFi Address: ");
Serial.println(WiFi.localIP());
Blynk.begin(BLYNK_AUTH_TOKEN,ssid,password);
timer.setInterval(1000L,TemprAndHumidity);
}
void TemprAndHumidity(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
delay(2000);
Blynk.virtualWrite(V2,data.temperature);
Blynk.virtualWrite(V3,data.humidity);
}
BLYNK_WRITE(V5){
int status =param.asInt();
ws2812b.clear();
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
delay(500);
}
// turn off all pixels for two seconds
ws2812b.clear();
ws2812b.show();
delay(2000);
// turn on all pixels to red at the same time for two seconds
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0)); // it only takes effect if pixels.show() is called
}
ws2812b.show();
delay(1000);
// turn off all pixels for one seconds
ws2812b.clear();
ws2812b.show();
delay(1000);
}
void loop() {
// Clears the trigPin
Blynk.run();
timer.run();
}