#define BLYNK_TEMPLATE_ID "TMPL6tvxo7Vsk"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "WLycV07YqWdAloxm4Je4ze9alyHZqudS"
#define BLYNK_PRINT Serial
#include <LiquidCrystal_I2C.h>
#include <DHTesp.h>
#include <WiFi.h>
#include "RTClib.h"
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
LiquidCrystal_I2C lcd(0x27, 20, 4);
const int DHT_PIN = 15;
#define ldrpin 32
const float GAMMA = 0.7;
const float RL10 = 50;
int volumeAir, siram;
DHTesp dhtSensor;
RTC_DS1307 rtc;
const int DIR = 19;
const int STEP = 18;
const int REV = 200;
const int DER = 2;
const int STIP = 34;
const int RIR = 25;
const int LIR = 26;
void bacaSensor() {
// Existing code from Kode Program 1
}
BLYNK_WRITE(V9) {
volumeAir = param.asInt();
}
BLYNK_WRITE(V0) {
siram = param.asInt();
}
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
lcd.init();
lcd.backlight();
lcd.println("Kelompok 7");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(STIP, OUTPUT);
pinMode(DER, OUTPUT);
pinMode(RIR, INPUT);
pinMode(LIR, INPUT);
timer.setInterval(1000L, bacaSensor);
}
void loop() {
Blynk.run();
timer.run();
Serial.println("Area Scanning");
if ((digitalRead(RIR) == 1) && (digitalRead(LIR) == 1)) {
forward();
}
if ((digitalRead(RIR) == 0) && (digitalRead(LIR) == 1)) {
turnRight();
}
if ((digitalRead(RIR) == 1) && (digitalRead(LIR) == 0)) {
turnLeft();
}
if ((digitalRead(RIR) == 0) && (digitalRead(LIR) == 0)) {
stop();
}
}
void forward() {
// Existing code from Kode Program 2
Serial.println("Vehicle initiated to go forward");
}
void turnRight() {
// Existing code from Kode Program 2
delay(5000);
Serial.println("Vehicle initiated to turn right");
}
void turnLeft() {
// Existing code from Kode Program 2
delay(5000);
Serial.println("Vehicle initiated to turn left");
}
void stop() {
// Existing code from Kode Program 2
Serial.println("Vehicle initiated to go backward");
}