// Define pins
#define IR_SENSOR_PIN 2 // Pin connected to IR sensor output
#define LED_PIN 13 // Pin connected to LED
void setup() {
// Initialize the serial monitor
Serial.begin(9600);
// Set IR sensor pin as input
pinMode(IR_SENSOR_PIN, INPUT);
// Set LED pin as output
pinMode(LED_PIN, OUTPUT);
Serial.println("IR Sensor Test Initialized");
}
void loop() {
// Read the IR sensor
int irSensorValue = digitalRead(IR_SENSOR_PIN);
if (irSensorValue == LOW) { // Object detected (assuming LOW output when detected)
Serial.println("40");
digitalWrite(LED_PIN, HIGH); // Turn on the indicator LED
} else {
Serial.println("40");
digitalWrite(LED_PIN, LOW); // Turn off the indicator LED
}
delay(20); // Wait 200ms before next reading
}