
What is an LDR (Light Dependent Resistor)?
An LDR (Light Dependent Resistor), also known as a photoresistor, is a variable resistor whose resistance decreases with increasing light intensity. It's commonly used in light-sensing circuits, such as automatic streetlights, alarm systems, and light meters.
In the context of an Arduino project, an LDR module senses light intensity and provides an analog voltage corresponding to the light level. By reading this analog voltage, the Arduino can determine the brightness of the environment.
Components:
- Arduino (any model, like Uno)
- LDR Module or LDR with a resistor (typically 10kΩ)
- Jumper wires
- Breadboard (optional)
LDR Module Pin Description (for modules with 3 pins):
1. VCC → 5V power supply
2. GND → Ground
3. OUT → Analog Output (connected to an Arduino analog pin)
If you are using just an LDR and a resistor, set up a voltage divider circuit where one end of the LDR is connected to 5V, the other end to GND through a resistor, and the junction of the LDR and resistor is connected to an analog pin on the Arduino.
Wiring the LDR to Arduino:
1. VCC → 5V pin on Arduino
2. GND → GND pin on Arduino
3. OUT (from LDR module) → Analog Pin (e.g., A0) on Arduino
Code Example:
int ldrPin = A0; // Pin where the LDR is connected
int ldrValue = 0; // Variable to store the light level
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
ldrValue = analogRead(ldrPin); // Read the analog value from the LDR
Serial.print("Light Intensity: ");
Serial.println(ldrValue); // Print the light intensity to the Serial Monitor
delay(500); // Delay for stability
}
How the Code Works:
analogRead(ldrPin): Reads the analog value from the LDR pin, which is proportional to the light intensity. The value will be between 0 and 1023, where 0 represents complete darkness, and 1023 represents maximum brightness.
Serial.print: Displays the light intensity in the Serial Monitor.
Testing:
1. Upload the code to the Arduino using the Arduino IDE.
2. Open the Serial Monitor to observe the light intensity values as you expose the sensor to different lighting conditions (covering or shining light on the LDR).
This simple setup allows the Arduino to sense the ambient light level, enabling projects like light-activated devices or automatic brightness control.
Comments