Photoresistor Reference
A light-dependent resistor (LDR) module providing both analog and digital light-level outputs.
Pin names
| Name | Description |
|---|---|
| VCC | Power (5V) |
| GND | Ground |
| DO | Digital Out — HIGH/LOW based on a threshold (adjustable via onboard trimmer on real hardware) |
| AO | Analog Out — voltage proportional to light level |
Attributes
This component has no configurable attributes.
Usage
Connect VCC to 5V, GND to GND, and AO to an analog input pin for a continuous light-level reading. Use DO instead for a simple bright/dark digital signal.
const int LDR_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int light = analogRead(LDR_PIN);
Serial.println(light); // higher = brighter
delay(200);
}
Examples
| Description | Attrs |
|---|---|
| Default photoresistor | {} |
See also
- Potentiometer — manually-controlled analog input instead of light-driven
- DHT22 — another common analog/digital environmental sensor