#include <ESP32Servo.h>
#include <DHTesp.h>
#include <BlynkSimpleEsp32.h>
#include <WiFi.h>
#include <WiFiClient.h>


#define BLYNK_TEMPLATE_ID "TMPL6U1CPv2Zf"
#define BLYNK_TEMPLATE_NAME "ESP32DHT22"
#define BLYNK_AUTH_TOKEN "s5cHvv_kzarqRDHBOtm2GPGSCADkmm1Z"
#define BLYNK_PRINT Serial
char auth [] = BLYNK_AUTH_TOKEN;
char ssid [] ="Wokwi-GUEST";
char pass[] ="";
BlynkTimer timer;

#define pin_merah 17
#define pin_jingga 16
#define pin_hijau 5

DHTesp dhtSensor;
#define DHTPIN 23

float suhu;
float kelembapan;

int pin_buzzer =  26;

Servo servo_ac;
int p = 0;
int suhu_tetapan;
int kelembapan_referensi;

void atur_servo_penyalaan_lampu ()
{
  for (p = 0; p <= 180; p++)
  {
    if ( suhu_tetapan - suhu <= 1)
    {
      servo_ac.write (p);
      delay (15);
      digitalWrite (pin_merah, LOW);
      digitalWrite (pin_jingga, HIGH);
      digitalWrite (pin_buzzer, HIGH);
    } else {
      digitalWrite (pin_hijau, HIGH);
      digitalWrite (pin_jingga, LOW);
    }

    if ( suhu - suhu_tetapan >= 2)
    {
      servo_ac.write (p);
      delay (15);
      digitalWrite (pin_jingga, HIGH);
      digitalWrite (pin_merah, HIGH);
      digitalWrite (pin_buzzer, HIGH);
    } else {
      digitalWrite (pin_hijau, HIGH);
      digitalWrite (pin_jingga, LOW);
      digitalWrite (pin_merah, LOW);
    }
  }
}


void baca_suhu ()
{
  TempAndHumidity data = dhtSensor.getTempAndHumidity ();
  suhu = data.temperature;
  kelembapan = data.humidity;
  Serial.println ("Suhu = " + String (data.temperature, 1) + " c");
  Serial.println ("Kelembapan = " + String (data.humidity, 1) + "%");
  Blynk.virtualWrite (V0, suhu);
  Blynk.virtualWrite (V1, kelembapan);
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 8080);
  timer.setInterval (2500L, baca_suhu);
  servo_ac.attach(4);
  dhtSensor.setup (DHTPIN, DHTesp ::DHT22);
  pinMode (pin_merah, OUTPUT);
  pinMode (pin_jingga, OUTPUT);
  pinMode (pin_hijau, OUTPUT);
  pinMode (pin_buzzer, OUTPUT);
}

void loop()
{
  Blynk.run();
  timer.run();
  baca_suhu();
  atur_servo_penyalaan_lampu();
}
$abcdeabcde151015202530fghijfghij
Loading
esp32-devkit-c-v4