Skip to main content

๐Ÿ”ฆ Interfacing LDR (Light Sensor) with Raspberry Pi 3

 

๐Ÿ”น Overview

An LDR (Light Dependent Resistor) is a sensor that detects light intensity. It is used in automatic lighting systems, smart homes, and robots. In this tutorial, we will connect an LDR sensor to Raspberry Pi 3 and read light levels.


๐Ÿ› ️ Components Required

✔️ Raspberry Pi 3
✔️ LDR Sensor
✔️ 10Kฮฉ Resistor
✔️ MCP3008 (ADC)
✔️ Breadboard & Jumper Wires


๐Ÿ”Œ Circuit Diagram

The Raspberry Pi does not have an inbuilt Analog-to-Digital Converter (ADC), so we use the MCP3008 ADC to read the LDR values.


๐Ÿ”— MCP3008 to Raspberry Pi Connections

MCP3008 PinConnection
VDD3.3V (Raspberry Pi)
VREF3.3V
AGNDGND
CLKGPIO 11 (SPI_CLK)
DOUTGPIO 9 (SPI_MISO)
DINGPIO 10 (SPI_MOSI)
CSGPIO 8 (SPI_CE0)
DGNDGND

๐Ÿ”— LDR Connections

LDR PinConnection
One leg3.3V
Second legMCP3008 Channel 0 (CH0) via 10Kฮฉ resistor to GND

๐Ÿ“œ Python Code to Read LDR Sensor

Save the following Python script as ldr_sensor.py and run it on Raspberry Pi.

python
import spidev import time # Open SPI bus spi = spidev.SpiDev() spi.open(0, 0) # Bus 0, Device 0 spi.max_speed_hz = 1350000 def read_adc(channel): adc = spi.xfer2([1, (8 + channel) << 4, 0]) data = ((adc[1] & 3) << 8) + adc[2] return data try: while True: light_level = read_adc(0) # Read from channel 0 print("Light Intensity:", light_level) time.sleep(1) except KeyboardInterrupt: spi.close() print("\nProgram stopped.")

๐Ÿ’ก How It Works

  1. The MCP3008 ADC converts the analog LDR signal to a digital value.
  2. The SPI communication sends data to Raspberry Pi.
  3. The script reads the light intensity and prints it on the screen.

๐ŸŽฏ Applications

✅ Automatic street lights
✅ Smart home automation
✅ Robot navigation


๐Ÿ“ เคฎเคฐाเค ीเคค เคธเคฎเคœाเคตเคฃी (Marathi Explanation)

๐Ÿ”น เคชเคฐिเคšเคฏ

LDR (Light Dependent Resistor) เคนा เคเค• เคธेเคจ्เคธเคฐ เค†เคนे เคœो เคช्เคฐเค•ाเคถाเคšी เคคीเคต्เคฐเคคा (Light Intensity) เค“เคณเค–เคคो. เคฏाเคšा เคตाเคชเคฐ เค‘เคŸोเคฎॅเคŸिเค• เคฆिเคตे เคšाเคฒू-เคฌंเคฆ เค•เคฐเคฃे, เคธ्เคฎाเคฐ्เคŸ เคนोเคฎ เคธिเคธ्เคŸीเคฎ्เคธ, เค†เคฃि เคฐोเคฌोเคŸिเค•्เคธ เคฎเคง्เคฏे เค•ेเคฒा เคœाเคคो.


๐Ÿ› ️ เค†เคตเคถ्เคฏเค• เค˜เคŸเค•

✔️ เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ เฅฉ
✔️ LDR เคธेเคจ्เคธเคฐ
✔️ 10Kฮฉ เคฐेเคธिเคธ्เคŸเคฐ
✔️ MCP3008 (ADC)
✔️ เคฌ्เคฐेเคกเคฌोเคฐ्เคก เค†เคฃि เคœเคฎ्เคชเคฐ เคตाเคฏเคฐ


๐Ÿ”Œ เคธเคฐ्เค•िเคŸ เค•เคจेเค•्เคถเคจ

เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ เคฎเคง्เคฏे Analog-to-Digital Converter (ADC) เคจाเคนी, เคฎ्เคนเคฃूเคจ MCP3008 ADC เคตाเคชเคฐเคคो.

MCP3008 เค•เคจेเค•्เคถเคจ:

MCP3008 เคชिเคจเคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ เค•เคจेเค•्เคถเคจ
VDD3.3V
VREF3.3V
AGNDGND
CLKGPIO 11
DOUTGPIO 9
DINGPIO 10
CSGPIO 8
DGNDGND

LDR เค•เคจेเค•्เคถเคจ:

LDR เคชिเคจเค•เคจेเค•्เคถเคจ
เคชเคนिเคฒा เคŸเคฐ्เคฎिเคจเคฒ3.3V
เคฆुเคธเคฐा เคŸเคฐ्เคฎिเคจเคฒMCP3008 เคšॅเคจเคฒ 0 (CH0) 10Kฮฉ เคฐेเคธिเคธ्เคŸเคฐ เคธเคน GND เคตเคฐ

๐Ÿ“œ เคชाเคฏเคฅॉเคจ เค•ोเคก

เคนा เค•ोเคก ldr_sensor.py เคจाเคตाเคจे เคธेเคต्เคน เค•เคฐा เค†เคฃि เคšाเคฒเคตा.

python
import spidev import time spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 1350000 def read_adc(channel): adc = spi.xfer2([1, (8 + channel) << 4, 0]) data = ((adc[1] & 3) << 8) + adc[2] return data try: while True: light_level = read_adc(0) print("เคช्เคฐเค•ाเคถाเคšी เคคीเคต्เคฐเคคा:", light_level) time.sleep(1) except KeyboardInterrupt: spi.close() print("\nเคช्เคฐोเค—्เคฐॅเคฎ เคฅांเคฌเคฒा.")

๐Ÿ’ก เคนे เค•เคธे เค•ाเคฐ्เคฏ เค•เคฐเคคे?

  1. MCP3008 ADC LDR เคšा เค…ॅเคจाเคฒॉเค— เคธिเค—्เคจเคฒ เคกिเคœिเคŸเคฒเคฎเคง्เคฏे เค•เคจ्เคต्เคนเคฐ्เคŸ เค•เคฐเคคो.
  2. SPI เค•เคฎ्เคฏुเคจिเค•ेเคถเคจ เคจे เคกेเคŸा เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏเคฒा เคชाเค เคตเคคे.
  3. เค•ोเคก เคช्เคฐเค•ाเคถाเคšी เคคीเคต्เคฐเคคा เคตाเคšเคคो เค†เคฃि เคคी เคธ्เค•्เคฐीเคจเคตเคฐ เคช्เคฐिंเคŸ เค•เคฐเคคो.

๐ŸŽฏ เค‰เคชเคฏोเค—

✅ เค‘เคŸोเคฎॅเคŸिเค• เคฆिเคตे (Automatic Lighting System)
✅ เคธ्เคฎाเคฐ्เคŸ เคนोเคฎ เค‘เคŸोเคฎेเคถเคจ
✅ เคฐोเคฌोเคŸ เคจेเคต्เคนिเค—ेเคถเคจ (Robot Navigation)

Comments

Popular posts from this blog

IOT : GARDEN WATER SPRINKLER SYSTEM

IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using...

POWER BI - THE ARCHITECTURE

Power BI Architecture: A Comprehensive Guide to Building Effective Data Analytics Solutions     Understanding Power BI Architecture: Power BI's architecture comprises four main components, each playing a pivotal role in the data analytics process: Data Sources:   Power BI connects to a wide range of data sources, including databases, cloud services, Excel files, web services, and more. This versatility enables organizations to consolidate their data from various systems into a single dashboard. Data Transformation:   Once the data is sourced, it undergoes transformation and cleaning processes to make it suitable for analysis. Power BI's Power Query Editor provides a user-friendly interface to manipulate, filter, and shape data according to specific requirements. Data Model:   The heart of Power BI's architecture lies in its data model, whic...

TOUCH PLATE BASED DOOR BELL

Title:  Touch plate based door bell  Circuit:  Components: IC 555 Resistors: 1 M, 100k, 330 ohms Transistor: BC547  PN2222A Capacitor: 10n 1 Copper plate : as touch plate. A 6v battery An LED / Ic UM66 Description: This is the simple circuit for touch plate based security system. In this project what basically done is, circuit detects stray voltages produced by mains voltage and electrostatic built  up in the room.If sufficient static voltage is detected by the plate then chip will charge up. Transistor BC 547 or PN2222A is used basically to increase the sensitivity.In place of led just connect IC um 66(melody IC). Applications: In homes, of course. This can be specially used in places like hospitals, when patients need to call doctor by himself.