// Untuk menyambungkan Wokwi dengan Blynk
#define BLYNK_TEMPLATE_ID "TMPLbsKX-AK2"
#define BLYNK_DEVICE_NAME "Jemuran"
#define BLYNK_AUTH_TOKEN "xcpyhC4B773HbedyfxbprWHpTDz6Zocm"
#define BLYNK_PRINT Serial
// Mengdefinisikan komponen" menggunakan pin berapa
#define SERVO_PIN 15
#define DHT_PIN 14
#define LED_PIN 2
#define MOTION_PIN 25
// Library wifi, blynkESP32, ServoESP32, DHTEsp
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#include "DHTesp.h"
// SSID, WIFI dari wokwi dan auth[] dari blynk token
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// class
DHTesp dhtSensor;
Servo myservo;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
myservo.attach(SERVO_PIN);
pinMode(LED_PIN, OUTPUT);
pinMode(MOTION_PIN, INPUT);
}
// tipe data untuk setiap variabel
float batas_temp = 28.00;
float batas_humidity = 90.00;
int pos;
int motion;
String temp;
String humidity;
void loop()
{
Blynk.run();
motion = digitalRead(MOTION_PIN);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temp = float(data.temperature);
humidity = float(data.humidity);
if (float(data.temperature) < batas_temp && float(data.humidity) > batas_humidity )
{
Blynk.logEvent("info2", "Kemungkinan akan turun hujan!");
Serial.println("Temp: " + temp + "°C");
Serial.println("Humidity: " + humidity + "%");
Serial.println("Kemungkinan hujan akan turun");
digitalWrite(LED_PIN, HIGH);
Serial.println("------------------");
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(2);
}
} else {
if ( motion == LOW ) {
Blynk.logEvent("info2", "Pakaian dijemur kembali");
Serial.println("Temp: " + temp + "°C");
Serial.println("Humidity: " + humidity + "%");
Serial.println("Pakaian dijemur kembali");
digitalWrite(LED_PIN, LOW);
Serial.println("------------------");
for (pos = 180; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(10);
}
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(2);
}
}
else {
Blynk.logEvent("info2", "Diluar masih hujan!");
Serial.println("Diluar masih hujan!");
Serial.println("------------------");
}
}
delay(1000);
}