LDR Light Sensor Raspberry Pi

 ðŸŸ¦ 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

Raspbery Pi
Raspberry Pi Pinout Diagram

LDR
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

  1. LDR senses light intensity
  2. In bright light → resistance decreases
  3. In darkness → resistance increases
  4. Sensor module converts this to digital signal
  5. Raspberry Pi reads signal from GPIO17
  6. In darkness → LED turns ON
  7. 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

  1. Import GPIO and time libraries
  2. Define LDR pin as GPIO17
  3. Define LED pin as GPIO18
  4. Set GPIO mode to BCM
  5. Set LDR as input
  6. Set LED as output
  7. Read LDR sensor value
  8. If LOW → dark detected → LED ON
  9. Else → LED OFF
  10. 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.

à´¤ുà´Ÿà´•്à´•à´•്à´•ാർക്à´•ാà´¯ുà´³്à´³ ഇലക്à´Ÿ്à´°ോà´£ിà´•്à´¸് ലളിതമാà´¯ി പഠിà´•്à´•ാം.

Empowering students in Kerala with hands-on technical skills.