const int IR_SENSOR_PIN =A2; // IR sensor output connected to GPIO 2 const int LED_PIN = D4; // LED anode connected to GPIO 3 through resistor void setup() { pinMode(IR_SENSOR_PIN, INPUT); // IR sensor is input pinMode(LED_PIN, OUTPUT); // LED is output Serial.begin(115200); // Serial monitor (optional) } void loop() { int irValue = digitalRead(IR_SENSOR_PIN); Serial.print("IR Sensor: "); Serial.println(irValue); if (irValue == 0) { // Object detected (many IR sensors pull LOW when triggered) digitalWrite(LED_PIN, HIGH); // Turn LED ON } else { digitalWrite(LED_PIN, LOW); // Turn LED OFF } delay(100); // Debounce delay }