Introduction: LDR Light Sensor on Raspberry Pi Pico

 a light sensor, also known as LDR (Light-Dependant Resistor) or photo-resistor, connected to a Raspberry Pi Pico. to measure the intensity of the ambient light.

Supplies

Step 1: Princple

A photoresistor is a passive component that decreases resistance with respect to receiving luminosity on the component's sensitive surface. The resistance of a photoresistor decreases with an increase in incident light intensity;

Step 2: Schematic Diagram

– connect one end of the LDR to GP27 (=GPIO 27 or ADC1)(orange)

– connect the other end of the LDR to a GND (ground) pin(blue)

Step 3: Source Code


from machine import Pin  

import time            


ldr = machine.ADC(27)  # Initialize an ADC object for pin 27


while True:

   

    ldr_value = ldr.read_u16()  # Read the LDR value and convert it to a 16-bit unsigned integer

    print("LDR Value:", ldr_value)  # Print the LDR value to the console

      time.sleep(2)