LDR Sensor Module Documentation
The LDR (Light Dependent Resistor) Sensor Module is a low-cost, easy-to-use module designed to detect changes in ambient light levels. This module consists of a light-dependent resistor (LDR) connected to a voltage regulator and an output pin. The output voltage of the module varies in response to changes in light intensity, making it an ideal component for applications such as lighting control, security systems, and robotics.
Operating Voltage: 3.3V to 5V
Output Voltage: 0V to VCC
Sensitivity: 1-100 lux
Response Time: 10-50 ms
Package: 25 pieces per pack
VCC: Power supply pin (3.3V to 5V)
GND: Ground pin
OUT: Output pin (analog signal)
Arduino Example: Automatic LED Lighting Control
In this example, we will use the LDR Sensor Module to control an LED light based on the ambient light level.
LDR Sensor Module
Arduino Board (e.g., Arduino Uno)
LED Light
Breadboard and Jumper Wires
Code:
```c
const int ledPin = 13; // LED connected to digital pin 13
const int ldrPin = A0; // LDR sensor output connected to analog pin A0
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int ldrValue = analogRead(ldrPin);
int lightLevel = map(ldrValue, 0, 1023, 0, 100); // Convert analog value to light level (0-100)
if (lightLevel < 50) { // If light level is low
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(50);
}
```
Raspberry Pi Example: Day/Night Detection
In this example, we will use the LDR Sensor Module to detect the day/night cycle and print a message to the console accordingly.
LDR Sensor Module
Raspberry Pi (e.g., Raspberry Pi 4)
Breadboard and Jumper Wires
Code (Python):
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
ldr_pin = 17 # LDR sensor output connected to GPIO 17
GPIO.setup(ldr_pin, GPIO.IN)
while True:
ldr_value = GPIO.input(ldr_pin)
if ldr_value < 500: # If light level is low
print("Night time!")
else:
print("Day time!")
time.sleep(1)
```
Note: In this example, we are using the RPi.GPIO library to read the analog value from the LDR sensor. You may need to adjust the threshold value (500) based on your specific setup.
To improve the accuracy of the readings, consider adding a capacitor (e.g., 10uF) between the OUT pin and GND to filter out noise.
Use the LDR Sensor Module in conjunction with other sensors (e.g., temperature, humidity) to create a more comprehensive environmental monitoring system.
Experiment with different threshold values and control scenarios to tailor the module's behavior to your specific application.