Project

โ— Beginner ยท KY-018 LDR Light Sensor

Reading Light Level with KY-018 LDR Sensor on Raspberry Pi Pico

Overview

Learn how to use the KY-018 LDR light sensor with a Raspberry Pi Pico to measure brightness. This project is useful for automatic lights, light-activated alarms, and day/night detection.

Instructions

Step by step

1. Connect the LDR VCC pin to 3.3V. 2. Connect the LDR GND pin to GND. 3. Connect the LDR S pin to GP26. 4. Run the code and open the Serial/console output. 5. Change the light level in the simulator. 6. A higher value means brighter light. 7. A lower value means darker light.

Code

Source code

code
from machine import ADC, Pin
import utime

ldr = ADC(Pin(26))

while True:
    light_value = ldr.read_u16()

    print("Light level:", light_value)

    utime.sleep(1)

Related

More projects with this sensor