Skip to content
Home > Components > Sensors > LDR Sensor Module (4-pin)

LDR Sensor Module (4-pin)

A photoresistor module with an onboard LM393 comparator, providing both an analog brightness reading and a digital threshold trigger.

Component Preview

LDR Sensor ModuleLDR Module

This module uses a Light Dependent Resistor (LDR). Its resistance decreases as light intensity increases. The onboard LM393 comparator compares the analog voltage against a potentiometer-set threshold, driving the Digital Output (DO) HIGH when it gets dark.

SensorsLightAnalog/Digital

Overview

Unlike a bare photoresistor, this 4-pin module provides dual outputs. The Analog Output (AO) gives you a varying voltage that represents ambient light intensity, while the Digital Output (DO) acts as a simple day/night switch.

Pin Reference

PinTypeDescription
AOanalogAnalog Output. Outputs a voltage proportional to light intensity. Connect to A0.
DOdigitalDigital Output. Goes HIGH when light falls below the threshold. Connect to D4.
GNDpowerGround. Connect to Arduino GND.
VCCpowerPower Supply. Connect to Arduino 5V.

Configurable Attributes

This component has no standard configurable attributes.

Working Principle

  1. Analog: A voltage divider is formed by the LDR and a fixed resistor. As light increases, LDR resistance drops, and AO voltage increases.
  2. Digital: The LM393 chip compares AO with a reference voltage. When AO drops below the reference (indicating it is dark), the comparator flips DO to a HIGH state.

Wiring Diagram

  1. Connect VCC to 5V.
  2. Connect GND to GND.
  3. Connect AO to Arduino A0.
  4. Connect DO to Arduino D4.

Wiring Diagram

Example Arduino Code

This code reads both the analog light level and the digital threshold trigger simultaneously.

cpp
const int ldrDigitalPin = 4;
const int ldrAnalogPin = A0;

void setup() {
  Serial.begin(9600);
  pinMode(ldrDigitalPin, INPUT);
  Serial.println("LDR Sensor Ready");
}

void loop() {
  // Read both pins
  int analogVal = analogRead(ldrAnalogPin);
  int digitalVal = digitalRead(ldrDigitalPin);
  
  // Calculate a rough lux approximation (for simulation/demo purposes)
  float lux = (1023.0 - analogVal) / 1023.0 * 1000.0;
  
  Serial.print("Analog (0-1023): ");
  Serial.print(analogVal);
  Serial.print(" | Lux (Approx): ");
  Serial.print(lux, 0);
  
  // DO is HIGH when it is dark
  if (digitalVal == HIGH) {
    Serial.println(" | Status: DARK");
  } else {
    Serial.println(" | Status: LIGHT");
  }
  
  delay(500);
}

Simulation Notes

  • In the simulator, clicking on the LDR module brings up an interactive "Lux" slider to simulate ambient light changing.
  • Sliding it to the far left (0 Lux) will trigger the DO pin to go HIGH.

Released under the MIT License.