๐น 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 Pin | Connection |
---|---|
VDD | 3.3V (Raspberry Pi) |
VREF | 3.3V |
AGND | GND |
CLK | GPIO 11 (SPI_CLK) |
DOUT | GPIO 9 (SPI_MISO) |
DIN | GPIO 10 (SPI_MOSI) |
CS | GPIO 8 (SPI_CE0) |
DGND | GND |
๐ LDR Connections
LDR Pin | Connection |
---|---|
One leg | 3.3V |
Second leg | MCP3008 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.
pythonimport 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
- The MCP3008 ADC converts the analog LDR signal to a digital value.
- The SPI communication sends data to Raspberry Pi.
- 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 เคชिเคจ | เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ เคเคจेเค्เคถเคจ |
---|---|
VDD | 3.3V |
VREF | 3.3V |
AGND | GND |
CLK | GPIO 11 |
DOUT | GPIO 9 |
DIN | GPIO 10 |
CS | GPIO 8 |
DGND | GND |
LDR เคเคจेเค्เคถเคจ:
LDR เคชिเคจ | เคเคจेเค्เคถเคจ |
---|---|
เคชเคนिเคฒा เคเคฐ्เคฎिเคจเคฒ | 3.3V |
เคฆुเคธเคฐा เคเคฐ्เคฎिเคจเคฒ | MCP3008 เคॅเคจเคฒ 0 (CH0) 10Kฮฉ เคฐेเคธिเคธ्เคเคฐ เคธเคน GND เคตเคฐ |
๐ เคชाเคฏเคฅॉเคจ เคोเคก
เคนा เคोเคก ldr_sensor.py
เคจाเคตाเคจे เคธेเคต्เคน เคเคฐा เคเคฃि เคाเคฒเคตा.
pythonimport 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เคช्เคฐोเค्เคฐॅเคฎ เคฅांเคฌเคฒा.")
๐ก เคนे เคเคธे เคाเคฐ्เคฏ เคเคฐเคคे?
- MCP3008 ADC LDR เคा เค ॅเคจाเคฒॉเค เคธिเค्เคจเคฒ เคกिเคिเคเคฒเคฎเคง्เคฏे เคเคจ्เคต्เคนเคฐ्เค เคเคฐเคคो.
- SPI เคเคฎ्เคฏुเคจिเคेเคถเคจ เคจे เคกेเคा เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏเคฒा เคชाเค เคตเคคे.
- เคोเคก เคช्เคฐเคाเคถाเคी เคคीเคต्เคฐเคคा เคตाเคเคคो เคเคฃि เคคी เคธ्เค्เคฐीเคจเคตเคฐ เคช्เคฐिंเค เคเคฐเคคो.
๐ฏ เคเคชเคฏोเค
✅ เคเคोเคฎॅเคिเค เคฆिเคตे (Automatic Lighting System)
✅ เคธ्เคฎाเคฐ्เค เคนोเคฎ เคเคोเคฎेเคถเคจ
✅ เคฐोเคฌोเค เคจेเคต्เคนिเคेเคถเคจ (Robot Navigation)
- Get link
- X
- Other Apps
Comments