Interfacing Photo sensor(KY018) with Raspberry pi pico

 



from machine import Pin

import utime


#Pin 16 is configured with internal Pull Down resistor. The pin value will be 0(Low)

#when if LDR sensor is not Detected Darkness.

#If Pull Down is used,LDR Sensor should be between the GPIO and Vcc(3.3V)

LDR_sensor= Pin(16, Pin.IN, Pin.PULL_DOWN)

Light=Pin(25,Pin.OUT)

# Continuously runs the code under the while loop.

while True:

# Below value should be 0 if use a low active relay

 if LDR_sensor.value() == 1:

    print("Sensor Detected Darkness")

    print("Light is ON")

    print(LDR_sensor.value())

    Light.on()#change(Light.off) if use a low active relay

 else:

    print("Sensor Detected Brightness")

    print(LDR_sensor.value())

    print("Light is OFF")

    Light.off()#change(Light.on) if use a low active relay

    utime.sleep(0.5)

    

Comments

Popular posts from this blog

Proteus simulation 4x4 Matrix Keypad with Arduino and LCD screen

Digital Clock with Arduino and RTC Module and P10 LEDmatrix

Interfacing KY038 sound sensor with Raspberry pi Pico