LDR¶
| Component | Light Dependent Resistor (LDR) |
| Type | Input |
| Function | Measure light intensity |
Introduction¶
A Light Dependent Resistor (LDR) is a type of resistor that changes its resistance based on the amount of light it is exposed to. The resistance of an LDR decreases as the intensity of light increases. This makes it a useful component for light sensing applications.
Pin Description¶
The LDR has two pins. The resistance across these pins changes based on the amount of light it is exposed to. You can connect the LDR to an analog pin on a microcontroller to measure the resistance and determine the light intensity. You use a voltage divider circuit to measure the resistance across the LDR.
Code Example¶
The following code example demonstrates how to read the resistance across the LDR using an analog pin on an Arduino board.
#define LDR_PIN A0 // define the LDR pin
void setup() {
Serial.begin(9600); // start serial communication at 9600 bps
}
void loop() {
int ldrValue = analogRead(LDR_PIN); // read the value from the LDR
Serial.println(ldrValue); // print the value to the serial port
delay(100); // wait for 100ms
}
(This example uses the Serial library to print the resistance value to the serial port. You can view the output using the Serial Monitor in the Arduino IDE.