// Pin definition const int digitalPin = D1; // Sensor D0 -> XIAO D1 (P27) int lastState = 1; // Initial state (no detection) void setup() { Serial.begin(115200); pinMode(digitalPin, INPUT); Serial.println("IR Goal Detection System"); } void loop() { int currentState = digitalRead(digitalPin); // Detect transition (object passing) if (lastState == 1 && currentState == 0) { Serial.println("GOAL!! ⚽"); } else { // No detection Serial.println("0"); } // Update previous state lastState = currentState; delay(50); }