const int irSensor1Pin = 2; // Pin where IR sensor is connected
void setup() {
// Start serial communication at a baud rate of 9600
Serial.begin(9600);
// Set the IR sensor pin as an input
pinMode(irSensor1Pin, INPUT);
}
void loop() {
// Read the state of the IR sensor
int sensor1State = digitalRead(irSensor1Pin);
// Print the value to the serial monitor
if(sensor1State == LOW) {
Serial.println("Object Detected"); // Print when object is detected
} else {
Serial.println("No Object"); // Print when no object is detected
}
// Wait for 500 milliseconds before reading again
delay(500);
}