#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
int suhu; // variabel suhu
int kelembapan; // variabel kelembapan
int mode; // variabel mode
/*************************************************************
This sketch shows how to write values to Virtual Pins
NOTE:
BlynkTimer provides SimpleTimer functionality:
http://playground.arduino.cc/Code/SimpleTimer
App project setup:
Value Display widget attached to Virtual Pin V5
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPL8pScDPEg"
#define BLYNK_DEVICE_NAME "LED AND TEMPERATURE"
#define BLYNK_AUTH_TOKEN "RWhO-4ehYJIJtL3AL_xSklRzINN4CK-E"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
// 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 myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
suhu=data.temperature;
kelembapan;
Blynk.virtualWrite(V0, suhu);
Blynk.virtualWrite(V1, kelembapan);
if(mode==1){
if(suhu<=28){
digitalWrite(25, LOW); //LED_HIJAU
digitalWrite(33, LOW); //LED_KUNING
digitalWrite(32, LOW); //LED_MERAH
}
if(suhu>=30 && suhu<=35){
digitalWrite(25, HIGH); //LED_HIJAU
digitalWrite(33, LOW); //LED_KUNING
digitalWrite(32, LOW); //LED_MERAH
}
if(suhu>=36 && suhu<=40){
digitalWrite(25, LOW); //LED_HIJAU
digitalWrite(33, HIGH); //LED_KUNING
digitalWrite(32, LOW); //LED_MERAH
}
if(suhu>=41){
digitalWrite(25, LOW); //LED_HIJAU
digitalWrite(33, LOW); //LED_KUNING
digitalWrite(32, HIGH); //LED_MERAH
}
}
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(32,pinValue);}
// process received value
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(33,pinValue);}
// process received value
}
BLYNK_WRITE(V4)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(25,pinValue);}
// process received value
}
BLYNK_WRITE(V5)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
mode=pinValue;
// process received value
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(25, OUTPUT); // LED_HIJAU
pinMode(33, OUTPUT); // LED_KUNING
pinMode(32, OUTPUT); // LED_MERAH
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}