شحن مجاني للأوردرات فوق
1000 ج
رمضان كريم
Ambient Light Detection for Arduino and DIY Electronics
The 4-Pin LDR Module is a light-sensitive sensor that detects ambient light intensity using a photoresistor. This module provides both digital and analog outputs, making it ideal for automatic lighting systems, weather stations, and smart home applications.

Detects visible light spectrum (400-700nm)
Digital (TTL) and Analog signals
Sensitivity potentiometer
4-pin connection (VCC, GND, DO, AO)
| Operating Voltage | 3.3V – 5V DC |
|---|---|
| Resistance Range | 200Ω (light) – 20MΩ (dark) |
| Response Time | ≈20ms (rise), ≈30ms (fall) |
| Spectral Peak | 540nm (green light) |
| Output Signals | Digital (TTL) + Analog |
| Dimensions | 32mm × 14mm |

| Pin | Label | Description | Arduino Connection |
|---|---|---|---|
| 1 | VCC | Power (3.3V-5V) | 5V |
| 2 | GND | Ground | GND |
| 3 | DO | Digital Output | Digital Pin |
| 4 | AO | Analog Output | Analog Pin |
// Basic Connections: // VCC → 5V // GND → GND // DO → D2 (Digital Input) // AO → A0 (Analog Input) // For best results, position sensor away from direct light sources
// Digital Output Example
const int ldrDigital = 2;
void setup() {
pinMode(ldrDigital, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(ldrDigital) == LOW) {
Serial.println("Bright light detected!");
// Add your response code here
}
delay(100);
}
// Analog Output Example
const int ldrAnalog = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightValue = analogRead(ldrAnalog);
Serial.print("Light level: ");
Serial.println(lightValue);
if (lightValue < 300) { // Adjust threshold as needed
Serial.println("Dark environment detected");
}
delay(200);
}
// Automatic baseline calibration
int baseline = 0;
void calibrate() {
for(int i=0; i<10; i++) {
baseline += analogRead(A0);
delay(100);
}
baseline /= 10;
Serial.print("Calibrated baseline: ");
Serial.println(baseline);
}
// Approximate lux calculation
float calculateLux(int rawValue) {
// Calibration values needed for accuracy
float voltage = rawValue * (5.0 / 1023.0);
return pow(10, (voltage - 1.0) / 0.5); // Example conversion
}
// Automatic light control
void controlLED(int lightLevel) {
if(lightLevel < 300) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
// Light level monitoring
void logLightLevel() {
int light = analogRead(A0);
Serial.print(millis()/1000);
Serial.print(",");
Serial.println(light);
delay(60000); // Log every minute
}
No account yet?
Create an Account
Recent Comments