// 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 "TMPL6wvRB2-MD"
#define BLYNK_TEMPLATE_NAME "Project kipas otomatis"
#define BLYNK_AUTH_TOKEN "Wz0Hb3Y_ojeWTbsGhuREuRmjGLIwkJLC"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include "DHTesp.h"
const int DHT_PIN = 16;
DHTesp dhtSensor;
int suhu; //variable suhu
int mode; //variable mode
#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");
suhu=data.temperature;
Blynk.virtualWrite(V0, suhu);
if(mode==1){
if(suhu<=28){
digitalWrite(14, LOW); //FAN 1 OFF
digitalWrite(12, LOW); //FAN 2 OFF
digitalWrite(13, LOW); //FAN 3 OFF
}
if(suhu>=29 && suhu<=30){
digitalWrite(14, HIGH); //FAN 1 ON
digitalWrite(12, LOW); //FAN 2 OFF
digitalWrite(13, LOW); //FAN 3 OFF
}
if(suhu>=31 && suhu<=32){
digitalWrite(14, HIGH); //FAN 1 ON
digitalWrite(12, HIGH); //FAN 2 ON
digitalWrite(13, LOW); //FAN 3 OFF
}
if(suhu>=33){
digitalWrite(14, HIGH); //FAN 1 ON
digitalWrite(12, HIGH); //FAN 2 ON
digitalWrite(13, HIGH); //FAN 3 ON
}
}
}
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){
digitalWrite(14,pinValue);}
// process received value
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){
digitalWrite(12,pinValue);}
// process received value
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(mode==0){
digitalWrite(13,pinValue);}
// process received value
}
BLYNK_WRITE(V4)
{
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);
pinMode(14, OUTPUT); //FAN 1
pinMode(12, OUTPUT); //FAN 2
pinMode(13, OUTPUT); //FAN 3
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);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}