/*
This example shows how value can be pushed from Arduino to
the Blynk App.
WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library
App dashboard setup:
Value Display widget attached to V5
Value Display widget attached to V4
*/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL2JkPfp5wk"
#define BLYNK_TEMPLATE_NAME "Trabalho Persiana Automática"
#define BLYNK_AUTH_TOKEN "2vrcb4l-cXW97ct5h1bYSBdmOJ2l9MC3"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define LED_PIN 12
#define sensor 21
#define servo 2
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 15 // What digital pin we're connected to
int servo + 0;
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
int pinValue = 0;
BLYNK_WRITE(V12)
{
pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("V12 Slider value is: ");
Serial.println(pinValue);
}
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(t) || isnan(h)) {
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(V5, h);
Blynk.virtualWrite(V4, t);
}
void setup(){
{
// Debug console
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT); // Define o LED como saída
dht.begin();
pinMode(sensor, INPUT);
}
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
digitalWrite(LED_PIN, pinValue);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (digitalRead(LED_PIN) == HIGH) {
// Só lê o sensor DHT22 se o LED estiver ligado
}
if (isnan(t) || isnan(h)) {
Serial.println("Erro ao ler o DHT22!");
}
else {
Serial.print("Temperatura: ");
Serial.print(t);
Serial.println(" *C");
Serial.print("Umidade: ");
Serial.print(h);
Serial.println(" %");
}
{
delay(5000); // Aguarda 2 segundos antes da próxima leitura
}
Blynk.run();
timer.run();
}