🟦 1. Introduction
An LDR (Light Dependent Resistor) is a sensor used to detect light intensity. Its resistance changes based on the amount of light falling on it. This makes it useful for automatic lighting and smart control systems.
🟦 2. Components
- Raspberry Pi
- LDR Sensor Module
- LED
- 220Ω Resistor
- Breadboard
- Jumper Wires
🟦 3. Circuit and connections
| Raspberry Pi Pinout Diagram |
| LDR Diagram |
🔌 Connections:
- VCC → 3.3V (Pin 1)
- GND → GND (Pin 6)
- DO → GPIO17 (Pin 11)
- LED + → GPIO18 (Pin 12)
- LED – → GND (via 220Ω resistor)
🟦 4. Detailed Step By Step Circuit working
- LDR senses light intensity
- In bright light → resistance decreases
- In darkness → resistance increases
- Sensor module converts this to digital signal
- Raspberry Pi reads signal from GPIO17
- In darkness → LED turns ON
- In light → LED turns OFF
🟦 5. Libraries to be included
import RPi.GPIO as GPIO
import time
🟦 6. Code
import RPi.GPIO as GPIO
import time
ldr = 17
led = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(ldr, GPIO.IN)
GPIO.setup(led, GPIO.OUT)
while True:
if GPIO.input(ldr) == 0: # Dark condition
GPIO.output(led, True)
print("Dark - LED ON")
else:
GPIO.output(led, False)
print("Light - LED OFF")
time.sleep(0.1)
🟦 7. Detailed Step By Step Code working
- Import GPIO and time libraries
- Define LDR pin as GPIO17
- Define LED pin as GPIO18
- Set GPIO mode to BCM
- Set LDR as input
- Set LED as output
- Read LDR sensor value
- If LOW → dark detected → LED ON
- Else → LED OFF
- Add delay for smooth operation
🟦 8. Tips
- Adjust sensitivity using onboard potentiometer
- Avoid direct shadow blocking
- Use proper resistor for LED protection
- Place sensor in open light area
🟦 9. Uses
- Automatic street lights
- Smart home lighting
- Light intensity monitoring
- Energy saving systems
🟦 10. Conclusion
The LDR sensor is a simple and effective way to detect light levels. This project helps in building automatic lighting systems using Raspberry Pi.