#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// PIN DEFINITIONS
#define BUZZER 18
#define G_LED 5
#define R_LED 17
// WIFI & DATABASE SETTINGS
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// YOUR LIVE URL
String scriptURL = "https://script.google.com/macros/s/AKfycbyJRSciKLgf9YpHhKeU58o0uFY3WRANKzx5krJWgv-liKIBPNg0tOEtjErcL0ZZjB_3/exec";
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
pinMode(BUZZER, OUTPUT);
pinMode(G_LED, OUTPUT);
pinMode(R_LED, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Connecting...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
lcd.clear();
lcd.print("System Ready");
Serial.println("WiFi Connected!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// 1. Check the Google Script for updates
http.begin(scriptURL);
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println("Current Status: " + payload);
// 2. If a name (not "Waiting") is found
if (payload != "Waiting") {
processAttendance(payload);
}
}
http.end();
}
delay(3000); // Check every 3 seconds
}
void processAttendance(String name) {
// Visual and Audio Feedback
lcd.clear();
lcd.print("Welcome:");
lcd.setCursor(0, 1);
lcd.print(name);
digitalWrite(G_LED, HIGH);
tone(BUZZER, 1000, 500); // 1kHz beep for 0.5s
delay(4000); // Keep name on screen for 4 seconds
digitalWrite(G_LED, LOW);
// 3. Reset the Google Script to "Waiting" so it doesn't repeat
HTTPClient resetHttp;
String resetURL = scriptURL + "?name=Waiting";
resetHttp.begin(resetURL);
resetHttp.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
resetHttp.GET();
resetHttp.end();
lcd.clear();
lcd.print("Ready to Scan");
}