#include #include // ====== YOUR WIFI INFO ====== const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; // ====== IR SENSOR PIN ====== const int irSensorPin = D2; // Use a digital pin like D2 (GPIO2) // ====== WEB SERVER ====== WebServer server(80); // ====== HTML PAGE ====== String htmlPage = R"rawliteral( IR Beam Sensor (Digital)

IR Beam Sensor (Digital)

Status: Reading...

)rawliteral"; // ====== SERVER HANDLERS ====== void handleRoot() { server.send(200, "text/html", htmlPage); } void handleStatus() { int sensorValue = digitalRead(irSensorPin); // Adjust logic depending on your sensor: some output LOW when blocked, some HIGH String state = (sensorValue == LOW) ? "BLOCKED" : "CLEAR"; server.send(200, "text/plain", state); } // ====== SETUP ====== void setup() { Serial.begin(115200); delay(1000); Serial.println(); Serial.println("Starting IR Beam Sensor (Digital)..."); pinMode(irSensorPin, INPUT); WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nWiFi Connected!"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); // Start web server server.on("/", handleRoot); server.on("/status", handleStatus); server.begin(); Serial.println("Web server started."); } // ====== LOOP ====== void loop() { server.handleClient(); }