#include "DHT.h"
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6GW4Ru06z"
#define BLYNK_TEMPLATE_NAME "LDR"
#define BLYNK_AUTH_TOKEN "u0Kl6vovL8sz4Mb9e2hfm-bHyAwQ8Yfh"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>
int LED1 = 12;
int LED2 = 13;
int ledPin = 27; // choose the pin for the LED
int inputPin = 14; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
String LINE_TOKEN = "cfp0uNoRffA7IkFABKljTju7hzRTiFDrVMUkiUQqLTW";
char auth[] = "u0Kl6vovL8sz4Mb9e2hfm-bHyAwQ8Yfh";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
void sendLineNotification(const char* message) {
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer " + LINE_TOKEN);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("message=" + String(message));
String payload = http.getString();
Serial.println("HTTP Response Code: " + String(httpCode));
Serial.println("Response: " + payload);
http.end();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(F(" *** Furnace Controlling Project ***"));
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
dht.begin();
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan (t) || isnan (f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
t = dht.readTemperature(); //Baca suhu
Serial.print("Suhu : ");
Serial.print(t); //Tampilkan suhu
Serial.println(" °C");
if (t < 18){ //Jika suhu < 18*C, maka
digitalWrite(LED1, HIGH); //LED hijau menyala
Serial.println("LED HIJAU ON");
Serial.println("Turn Furnace ON");
digitalWrite(LED2, LOW);
}
else if(t > 22){ //Jika suhu <= 22*C, maka
digitalWrite(LED2, HIGH); //LED merah menyala
Serial.println("LED MERAH ON");
Serial.println("Turn Furnace OFF");
digitalWrite(LED1, LOW);
}
delay(1000);
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}