const int sensorPin = 3; // Connect the OUT pin to D3
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging (optional)
pinMode(sensorPin, INPUT); // Set the sensor pin as an input
}
void loop() {
int sensorValue = digitalRead(sensorPin); // Read the digital value from the sensor
if (sensorValue == HIGH) {
Serial.println("Obstacle detected!"); // Print a message when an obstacle is detected (optional)
// Your code to respond to obstacle detection goes here
} Serial.println(sensorValue);
// Delay to avoid rapid multiple readings (adjust as needed)
delay(500);
}