/**
ESP32 + DHT22 Example for Wokwi
https://wokwi.com/arduino/projects/322410731508073042
*/
/* Fill-in information from Blynk Device Info here */
//#define BLYNK_TEMPLATE_ID "TMPL3v8MH4REN"
//#define BLYNK_TEMPLATE_NAME "AquaMaster"
//#define BLYNK_AUTH_TOKEN "9BFaOd87xrkN4tudGsISQaR_dg5e-MdI"
// #define BLYNK_TEMPLATE_ID "TMPL3wpuGOyyt"
// #define BLYNK_TEMPLATE_NAME "Quickstart Template"
// #define BLYNK_AUTH_TOKEN "DFONlrcJcTEhvNZ2NCgeLC0MUp4m4u4Z"
#define BLYNK_TEMPLATE_ID "TMPL3wpuGOyyt"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "szzD-DoQ1CS-R9GluslkZKvb_rjowwrT"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#include <Wire.h> /*~ Librería I2C ~*/
#include <LiquidCrystal_I2C.h> /*~ Librería LCD ~*/
LiquidCrystal_I2C lcd ( 0x27, 16, 2 );
int led2=4;
int led1=2;
#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)// button V0
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
digitalWrite(led1,value);
// Update state
}
// This function is called every time the device is connected to the Blynk.Cloud
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);// uptime value display V2
}
void setup() {
lcd.init ( );
lcd.setCursor ( 0, 0 );
lcd.print ( "Irrigation System" );
lcd.setCursor ( 0, 1 );
lcd.print ( " using IOT " );
delay ( 1000 );
lcd.clear();
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Serial.begin(115200);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);// optional
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);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void DHT_sensor()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
Blynk.virtualWrite(V1,String(data.humidity, 1));
Blynk.virtualWrite(V3,String(data.temperature, 2));
lcd.setCursor ( 0, 0 );
lcd.print ( "Temp: " );
lcd.print ( String(data.temperature, 2)+ "°C");
lcd.setCursor ( 0, 1 );
lcd.print ( "Humidity:" );
lcd.print ( String(data.humidity, 1) + "%");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}
void loop() {
Blynk.run();
timer.run();
DHT_sensor();
}