Learn interfacing Light Dependent Resistor LDR in Raspberry Pi. We will learn how LDR works. LDR is a type of resistor whose resistance varies according to the surrounding light. Resistance will increase with the increase in light intensity. LDR also known as Photoresistor, are available in 5mm, 7mm, 10mm, and many other sizes. So, let’s start.
Step 1: Required Components
Step 2: Circuit Time
Make the circuit as per the given diagram. Connect one leg of LDR to VCC +5v. Now, connect the long leg of the capacitor and another leg of LDR on the same track of breadboard. The ground short leg of the capacitor.
Step 3: Code Time
This is code for interfacing LDR in Raspberry Pi. First of all, we have to import the LightSensor code for LDR from the gpiozero library. Assign GPIO pin to variable LDR and also pass the GPIO pin number as an argument to the LightSensor method. While loop print’s value of LDR.
Step 4: Run code to Raspberry Pi
Run the Python program in your Raspberry Pi after setting components as per the circuit diagram. The LDR will give resistance to Raspberry Pi and Raspberry Pi. The screenshot of the output is given below.
For running python code in Raspberry Pi, visit: raspberrypi.org/documentation/usage/python/