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

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.

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️

Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ Interfacing Load Cell with Raspberry Pi 3 (via HX711) ⚖️ A load cell is a transducer that converts force (weight) into an electrical signal. The HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weigh scales. Today we’ll connect a load cell to Raspberry Pi 3 using the HX711 module. ๐Ÿงช ๐Ÿ”ง Components Required Component Quantity Raspberry Pi 3 1 Load Cell 1 HX711 Module 1 Jumper Wires 6 Breadboard (optional) 1 ๐Ÿ”Œ Pin Connections HX711 Pin Raspberry Pi Pin Pin Number VCC 5V Pin 2 GND Ground Pin 6 DT GPIO 5 Pin 29 SCK GPIO 6 Pin 31 Figure: Load Cell connected to Raspberry Pi 3 via HX711 ๐Ÿ’ป Python Code from hx711 import HX711 import RPi.GPIO as GPIO import time hx = HX711(dout_pin=5, pd_sck_pin=6) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(1) hx.reset()...

Interfacing Sound Sensor with Raspberry Pi 3

๐Ÿ”น Overview The KY-037 is a high-sensitivity sound detection sensor that can detect noise levels in the environment. It provides both analog and digital outputs. In this tutorial, we’ll interface the digital output of KY-037 with Raspberry Pi 3 Model B+ (without using an ADC like MCP3008) and detect sound events.