#define BLYNK_TEMPLATE_ID "TMPL6KvYWjW2r"
#define BLYNK_TEMPLATE_NAME "Control LED RGB"
#define BLYNK_AUTH_TOKEN "d8pkxHS6TbbJqHUsrZlAcunoYJHI2sbs"
// Comment this out to disable prints and save space
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "RTClib.h"
char auth[] = "d8pkxHS6TbbJqHUsrZlAcunoYJHI2sbs";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int i = 0;
#define BLYNK_PRINT Serial
BlynkTimer timer;
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Wire.h>
#define SERIAL_OPTION 0
LiquidCrystal_I2C lcd(0x27,16,2);
RTC_DS1307 RTC;
String note;
#define LDR_PIN 12
#define Pump 2
#define Lamp 15
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
// put your setup code here, to run once:
pinMode(LDR_PIN, INPUT);
pinMode(Pump, OUTPUT);
pinMode(Lamp, OUTPUT);
Serial.begin(9600);
if (SERIAL_OPTION) Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
//01234567890123456789
lcd.print(" Smart Farming ");
lcd.setCursor(0,1);
//01234567890123456789
lcd.print(" Water Sprinkler ");
lcd.print(" ");
delay(3000);
lcd.setCursor(0,0);
//01234567890123456789
lcd.print(" PDE-BASE ");
lcd.setCursor(0,1);
//01234567890123456789
lcd.print(" Group 2 ");
lcd.print(" ");
delay(3000);
lcd.setCursor(0,0);
//01234567890123456789
lcd.print(" Frederick DKK ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);
lcd.clear();
RTC.begin();
// RTC.adjust(DateTime(2022,9,30,18,13,40));
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now=RTC.now();
int analogValue = analogRead(12);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.println(lux);
if (lux < 500){
digitalWrite(Lamp, HIGH);
Serial.println("Keadaan gelap, lampu menyala");
}else {
digitalWrite(Lamp, LOW);
Serial.println("Keadaan terang, lampu mati");
}
if (SERIAL_OPTION) {
Serial.print(now.year()); Serial.print("/");
Serial.print(now.month()); Serial.print("/");
Serial.print(now.day()); Serial.print(" ");
Serial.print(now.hour()); Serial.print(":");
Serial.print(now.minute()); Serial.print(":");
Serial.print(now.second()); Serial.print("\n");
}
lcd.setCursor(0,0); lcd.print("DATE: ");
lcd.print(now.year()); lcd.print("/"); lcd.print(now.month()); lcd.print("/"); lcd.print(now.day());
lcd.setCursor(0,1); lcd.print("TIME: ");
lcd.print(now.hour()); lcd.print(":"); lcd.print(now.minute()); lcd.print(":"); lcd.print(now.second());
delay(1000);
if ((now.hour() == 7) && (now.minute() == 20) && (now.second() == 20)) {
digitalWrite(Pump, HIGH);
delay(100000);
Serial.println("Siram Tanaman Pagi");
}
else if ((now.hour() == 13) && (now.minute() == 20) && (now.second() == 20)) {
digitalWrite(Pump, HIGH);
delay(100000);
Serial.println("Siram Tanaman Siang");
}
else {
digitalWrite(Pump, LOW);
}
}