#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
int suhu; //buat variabel untuk simpan suhu
int mode=0; //buat variabel mode untuk manual dan auto
/*************************************************************
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 "TMPL68cAQRBLB"
#define BLYNK_TEMPLATE_NAME "Kontrol kipas otomatis"
#define BLYNK_AUTH_TOKEN "xM9zz1z3fsdALM6pSLP1BMe90SQcBp2w"
// 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()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
suhu=data.temperature;
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
if(mode==1){
if(suhu<=28){
digitalWrite(25,LOW); // FAN 1 OFF
digitalWrite(33,LOW); // FAN 2 OFF
digitalWrite(32,LOW); // FAN 3 OFF
}
if(suhu>=29 && suhu<=30){
digitalWrite(25,HIGH); // FAN 1 ON
digitalWrite(33,LOW); // FAN 2 OFF
digitalWrite(32,LOW); // FAN 3 OFF
}
if(suhu>=31 && suhu<=32){
digitalWrite(25,HIGH); // FAN 1 ON
digitalWrite(33,HIGH); // FAN 2 ON
digitalWrite(32,LOW); // FAN 3 OFF
}
if(suhu>=33){
digitalWrite(25,HIGH); // FAN 1 ON
digitalWrite(33,HIGH); // FAN 2 ON
digitalWrite(32,HIGH); // FAN 3 ON
}
} //jika mode auto kondisi ini baru boleh dibaca
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0,suhu);
}
BLYNK_WRITE(V1) // FAN 1
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(25,pinValue);} //jika mode manual baru bisa
// process received value
}
BLYNK_WRITE(V2) // FAN 2
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(33,pinValue);}
// process received value
}
BLYNK_WRITE(V3) // FAN 3
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){digitalWrite(32,pinValue);}
// process received value
}
BLYNK_WRITE(V4) // BACA MODE DARI BLYNK
{
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); //FAN 1
pinMode(33,OUTPUT); //FAN 2
pinMode(32,OUTPUT); //FAN 3
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}