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 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
LDR x 1
Breadboard x 1
Raspberry Pi x 1
1µf capacitor x 1
Step 2: Circuit Time
Make the circuit as per the given diagram. Connect one leg of LDR to VCC +5v. Now, connect 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 LightSensor code for LDR form gpiozero library. Assign GPIO pin to variable ldr and also pass the GPIO pin number as an argument to 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 circuit diagram. The LDR will give resistance to Raspberry Pi and Raspberry Pi. Screenshot of output is given as below.
For running python code in Raspberry PI, visit: raspberrypi.org/documentation/usage/python/