Interfacing IR Proximity sensor To Toggle a relay with Raspberry Pi pico
# In this Project we will Interface a IRProximity sensor with Raspberry pi pico to toggle a
# If using a low active Relay upload this code.
# Relay
from machine import Pin
import time
IR_proximity= machine.Pin(16,Pin.IN,Pin.PULL_DOWN)#connected the IR sensor Output to GPIO Pin 16
Relay = Pin(17,Pin.OUT)# low active Relay is connected to GPIO Pin 17 via an NPN Transistor.
while True:
if IR_proximity.value()==1:#if IR Sensor outPut Is High
Relay.toggle()#change the Relay status OFF to ON/ON to OFF
time.sleep(0.5)
# If using High active relay ,upload this code
from machine import Pin
import time
IR_proximity= machine.Pin(16,Pin.IN,Pin.PULL_UP)#connected the IR sensor Output to GPIO Pin 16 and GND
Relay = Pin(17,Pin.OUT)# low active Relay is connected to GPIO Pin 17 via an NPN Transistor.
while True:
if IR_proximity.value()==1:#if IR Sensor outPut Is High
Relay.toggle()#change the Relay status OFF to ON/ON to OFF
time.sleep(0.5)
Comments
Post a Comment