#define IR_SENSOR_PIN D0 // IR sensor output pin #define LED_PIN D2 // LED pin void setup() { pinMode(IR_SENSOR_PIN, INPUT); // Set IR sensor pin as input pinMode(LED_PIN, OUTPUT); // Set LED pin as output Serial.begin(115200); // Start serial communication } void loop() { int sensorState = digitalRead(IR_SENSOR_PIN); // Read IR sensor state if (sensorState == LOW) { // Object detected (LOW if active low sensor) digitalWrite(LED_PIN, HIGH); // Turn ON LED Serial.println("Object detected!"); } else { digitalWrite(LED_PIN, LOW); // Turn OFF LED Serial.println("No object detected."); } delay(100); // Small delay for stability }