#define BLYNK_TEMPLATE_ID "TMPLagRGsDtX"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "85gaRFGhc9TQEbaupu63qdeSZ4hoYoVz"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
//Change the virtual pins according the rooms
#define IR1 V0
#define IR2 V1
//------------------------------------------------------------------------------
// This function is called every time the device is connected to the Blynk.Cloud
// Request the latest state from the server
BLYNK_CONNECTED() {
Blynk.syncVirtual(IR1);
Blynk.syncVirtual(IR2);
}
int irsensor1 = 13;
int irsensor2 = 12;
enum DaysOfTheWeek {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
if (!rtc.begin()) {
Serial.println("Failed to find RTC");
Serial.flush();
abort();
}
pinMode(irsensor1,INPUT);
pinMode(irsensor2,INPUT);
Serial.println("Hello, ESP32-S2!");
}
void printCurrentTime(DateTime now) {
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(getDayOfWeekString(now.dayOfTheWeek()));
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
String getDayOfWeekString(int dayOfWeek) {
switch (dayOfWeek) {
case Sunday:
return "Sunday";
case Monday:
return "Monday";
case Tuesday:
return "Tuesday";
case Wednesday:
return "Wednesday";
case Thursday:
return "Thursday";
case Friday:
return "Friday";
case Saturday:
return "Saturday";
default:
return "Invalid day";
}
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Reading1:" + String(digitalRead(irsensor1)));
Serial.println("Reading2:" + String(digitalRead(irsensor2)));
if(digitalRead(irsensor1)==0)
{
DateTime now = rtc.now();
printCurrentTime(now);
Serial.println("Object1!");
delay(5000); // this speeds up the simulation
}
if(digitalRead(irsensor2)==0)
{
DateTime now = rtc.now();
printCurrentTime(now);
Serial.println("Object2!");
delay(5000); // this speeds up the simulation
}
Blynk.run();
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
ir1:GND
ir1:VCC
ir1:DAT
ir2:GND
ir2:VCC
ir2:DAT
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW