from machine import Pin
from time import sleep
# Simulating IR sensor with a pushbutton
sensor = Pin(16, Pin.IN, Pin.PULL_UP) # GP16, pull-up enabled
led = Pin(15, Pin.OUT) # GP15 LED
print("IR Sensor Simulation Started...")
while True:
if sensor.value() == 0: # Button pressed = Object detected
led.on()
print("Object detected!")
else:
led.off()
print("No object")
sleep(0.2)