Skip to content
Home > Components > Sensors > Photoresistor (LDR)

Photoresistor (LDR)

A classic Light Dependent Resistor whose resistance decreases when exposed to light.

Component Preview

PhotoresistorLDR

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.

SensorsLightPassive

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

PinTypeDescription
Pin 1passiveLeg 1. Connects to the voltage divider.
Pin 2passiveLeg 2. Connects to the voltage divider.

Configurable Attributes

AttributeTypeDefaultDescription
luxnumber500The 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Ω).

  1. Connect Pin 1 of the LDR to Arduino 5V.
  2. Connect Pin 2 of the LDR to Arduino A0.
  3. Connect a 10kΩ resistor from A0 to Arduino GND.

Wiring Diagram

Example Arduino Code

cpp
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 lux attribute.
  • As the simulated lux level increases, a subtle visual glow will appear behind the LDR head to represent the ambient light source.

Released under the MIT License.