LDR Light Sensor on Raspberry Pi Pico

by cryp7o in Circuits > Raspberry Pi

1614 Views, 2 Favorites, 0 Comments

LDR Light Sensor on Raspberry Pi Pico

Presentation1.gif

 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

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;

Schematic Diagram

Screenshot 2023-09-27 165154.png
Screenshot 2023-09-27 165809.png

– 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)

Source Code

Screenshot 2023-09-27 165154.png


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)