#define BLYNK_TEMPLATE_ID "TMPL6EOqF9dlp"
#define BLYNK_TEMPLATE_NAME "PROJEK INFORMATIKA 1"
#define BLYNK_AUTH_TOKEN "OsEAWwVnMPnuLR5z914Bvr-eG1POG3QM"
#define BLYNK_PRINT Serial
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>
#include <DS3231.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // nama hotspot yang digunakan
char pass[] = ""; // password hotspot yang digunakan
#define CURRENT_SENSOR_PIN A0 // pin for non-invasive current sensor
#define TEMPERATURE_SENSOR_PIN 2 // pin for DS18820 temperature sensor
#define RELAY_PIN 2 // pin for relay control
#define RTC_SDA_PIN 20 // pin for DS3231 RTC module SDA
#define RTC_SCL_PIN 21 // pin for DS3231 RTC module SCL
#define WIFI_RX_PIN 10 // pin for ESP8266 Wi-Fi module RX
#define WIFI_TX_PIN 11 // pin for ESP8266 Wi-Fi module TX
#define LCD_RS_PIN 4 // pin for 16x2 LCD RS
#define LCD_EN_PIN 5 // pin for 16x2 LCD EN
#define LCD_D4_PIN 6 // pin for 16x2 LCD D4
#define LCD_D5_PIN 7 // pin for 16x2 LCD D5
#define LCD_D6_PIN 8 // pin for 16x2 LCD D6
#define LCD_D7_PIN 9 // pin for 16x2 LCD D7
DS3231 rtc;
DHT dht(TEMPERATURE_SENSOR_PIN, DHT22);
BlynkTimer timer;
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
rtc.begin();
dht.begin();
pinMode(RELAY_PIN, OUTPUT);
pinMode(LCD_RS_PIN, OUTPUT);
pinMode(LCD_EN_PIN, OUTPUT);
pinMode(LCD_D4_PIN, OUTPUT);
pinMode(LCD_D5_PIN, OUTPUT);
pinMode(LCD_D6_PIN, OUTPUT);
pinMode(LCD_D7_PIN, OUTPUT);
timer.setInterval(2500L, sendSensor);
}
void loop(){
Blynk.run();
timer.run();
}
void sendSensor(){
int currentConsumption = analogRead(CURRENT_SENSOR_PIN);
float temperature = dht.readTemperature();
if (isnan(temperature)) {
Serial.println("Failed to read from temperature sensor!");
return;
}
Blynk.virtualWrite(V0, currentConsumption);
Blynk.virtualWrite(V1, temperature);
Serial.print("Current Consumption : ");
Serial.print(currentConsumption);
Serial.print(" Temperature : ");
Serial.println(temperature);
if(temperature > 30){
// Blynk.email("[email protected]", "Alert", "Temperature over 28C!");
Blynk.logEvent("temp_alert","Temp above 30 degrees");
}
}
Loading
ds18b20
ds18b20