import machine
import utime
# Define GPIO pins
IR_SENSOR_PIN = machine.Pin(16, machine.Pin.IN) # IR Sensor (Input)
RED_LED_PIN = machine.Pin(17, machine.Pin.OUT) # Red LED (Obstacle detected)
GREEN_LED_PIN = machine.Pin(18, machine.Pin.OUT) # Green LED (No obstacle)
while True:
if IR_SENSOR_PIN.value(): # Obstacle detected
print("Obstacle Detected!")
RED_LED_PIN.value(1) # Turn ON Red LED
GREEN_LED_PIN.value(0) # Turn OFF Green LED
else: # No obstacle
print("No Obstacle")
RED_LED_PIN.value(0) # Turn OFF Red LED
GREEN_LED_PIN.value(1) # Turn ON Green LED
utime.sleep(0.5) # Delay of 500ms