Photoresistor (LDR)
A classic Light Dependent Resistor whose resistance decreases when exposed to light.
Component Preview
A Photoresistor (also known as a Light Dependent Resistor or LDR) is a passive electronic component that is sensitive to light. When placed in a voltage divider circuit with a fixed resistor, it allows a microcontroller to easily read the ambient light level as an analog voltage.
Overview
LDRs are commonly used in night-lights, outdoor street lamps, and simple alarm systems to detect the presence or absence of ambient light. The most common type is made of Cadmium Sulfide (CdS), which creates the characteristic orange zigzag track visible on the sensor face. Because they are resistors, they do not have polarity (anode/cathode) and can be connected in either direction.
Pin Reference
| Pin | Type | Description |
|---|---|---|
| Pin 1 | passive | Leg 1. Connects to the voltage divider. |
| Pin 2 | passive | Leg 2. Connects to the voltage divider. |
Configurable Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| lux | number | 500 | The simulated ambient light level in Lux (0-1000). |
Wiring Diagram (Voltage Divider)
To measure light, wire the LDR in a voltage divider with a fixed resistor (e.g., 10kΩ).
- Connect Pin 1 of the LDR to Arduino 5V.
- Connect Pin 2 of the LDR to Arduino A0.
- Connect a 10kΩ resistor from A0 to Arduino GND.

Example Arduino Code
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightLevel = analogRead(ldrPin);
Serial.print("Ambient Light (0-1023): ");
Serial.println(lightLevel);
if (lightLevel < 300) {
Serial.println(" --> It's getting dark!");
}
delay(250);
}Simulation Notes
- In the simulator, right-click the photoresistor to open its context menu and adjust the
luxattribute. - As the simulated lux level increases, a subtle visual glow will appear behind the LDR head to represent the ambient light source.
