The Practical Light Sensor Definition for Embedded Systems
At the silicon level, a light sensor operates on the internal photoelectric effect. When photons with sufficient energy strike a semiconductor junction, they excite electrons from the valence band into the conduction band, generating electron-hole pairs. In photoconductive devices like Light Dependent Resistors (LDRs), this lowers the bulk resistance of the material (typically cadmium sulfide). In photodiodes and phototransistors, the junction is reverse-biased or left floating, and the generated carriers create a measurable photocurrent proportional to the incident irradiance.
In embedded systems, the practical light sensor definition extends beyond the physics to the actual electrical output. Analog sensors (LDRs, phototransistors) output a variable resistance or raw current, which you must convert to a voltage using a pull-down or pull-up resistor and read via a microcontroller's Analog-to-Digital Converter (ADC). Digital sensors (like the BH1750 or TSL2591) contain an internal integrating ADC and an I2C interface. They output a pre-calculated 16-bit integer representing Lux directly, bypassing the microcontroller's ADC entirely and shifting the burden of calibration to the silicon manufacturer.
Component Selection Matrix: LDR vs. Phototransistor vs. Digital IC
Choosing the right sensor depends entirely on your required lux range, environmental conditions, and whether you can spare an ADC pin. Below is a data-dense comparison of the four most common light sensors used in maker and IoT projects today.
| Component | Type | Output Signal | Lux Range | Supply Range | Typical Price (2026) |
|---|---|---|---|---|---|
| GL5528 | LDR (CdS) | Analog (Resistance) | 5 - 500 Lux | N/A (Passive) | $0.05 |
| TEMT6000 | Phototransistor | Analog (Current) | 1 - 1,000 Lux | 3.3V - 5.0V | $0.45 |
| BH1750FVI | Digital IC | Digital (I2C) | 1 - 65,535 Lux | 3.0V - 5.0V | $1.20 |
| TSL2591 | Digital IC | Digital (I2C) | 0.000188 - 88,000 Lux | 2.7V - 3.6V | $3.50 |
Wiring and Pin Mapping for ESP32 and Arduino
Below is the standard wiring configuration for interfacing both an analog phototransistor (TEMT6000) and a digital I2C sensor (BH1750) to an ESP32 DevKit V1. The same logic applies to the Arduino Uno, substituting GPIO 34 for A0, and GPIO 21/22 for A4/A5.
| Sensor Pin | TEMT6000 (Analog) | BH1750 (Digital I2C) | ESP32 DevKit V1 Pin |
|---|---|---|---|
| VCC | 3.3V | 3.3V | 3V3 |
| GND | GND | GND | GND |
| Signal / SDA | OUT (via 10kΩ pull-down) | SDA | GPIO 34 (ADC) / GPIO 21 (SDA) |
| N/A / SCL | N/A | SCL | GPIO 22 (SCL) |
Numbered Steps for Analog Wiring (TEMT6000)
- De-energize the breadboard: Ensure your ESP32 is unplugged from USB before wiring analog components to prevent accidental short circuits on the ADC pins.
- Place the 10kΩ pull-down resistor: Connect a 10kΩ 1% metal film resistor between the TEMT6000 OUT pin and GND. This converts the sensor's variable current output into a measurable voltage ($V = I \times R$).
- Wire the signal line: Connect the junction of the OUT pin and the 10kΩ resistor directly to ESP32 GPIO 34. Do not route this through long jumper wires; analog signals are highly susceptible to 60Hz mains noise.
- Power the sensor: Connect VCC to the ESP32's 3.3V pin. Never power the TEMT6000 with 5V if you are feeding the signal directly into a 3.3V microcontroller ADC, as the output voltage will exceed the pin's absolute maximum rating and destroy the GPIO.
Output Signal Math: Converting Raw ADC to Lux
The most common mistake makers make is treating raw ADC counts as linear physical units. They are not. Here is the exact math to convert raw readings into Lux for both analog and digital paradigms.
Analog Math (TEMT6000 on ESP32)
The ESP32 features a 12-bit ADC (0-4095). Assuming a 3.3V reference and a 10kΩ pull-down resistor, the conversion path is:
- Calculate Voltage: $V_{out} = ADC_{raw} \times (3.3 / 4095)$
- Calculate Current: The TEMT6000 datasheet specifies a collector current ($I_c$) based on the voltage across the 10kΩ resistor. $I_c (\text{in Amps}) = V_{out} / 10,000$.
- Scale to Lux: According to the Vishay TEMT6000 datasheet, the sensor yields approximately 2 µA of current per 1 Lux of illuminance. Therefore, $Lux = (I_c \text{ in } \mu A) \times 2$.
Combined Formula:
Lux = ((ADC_raw * (3.3 / 4095)) / 10000) * 1000000 * 2
Lux = ADC_raw * 0.1611 (at 12-bit resolution, 3.3V reference, 10kΩ resistor).
Digital Math (BH1750)
Digital sensors handle the integration and scaling internally. When you read the BH1750 via I2C, it returns a 16-bit unsigned integer. The scaling is hardcoded by Rohm Semiconductor: Lux = Raw_I2C_Value / 1.2. If you set the sensor to "Continuous High Resolution Mode 2", the measurement time is 120ms, and the raw value directly maps to 0.5 Lux steps. No ADC math required.
Calibration, Scaling, and Interference Sources
Even with perfect math, real-world environments introduce interference that will corrupt your light sensor data if left unaddressed.
1. Infrared (IR) Bleed and Spectral Response
Silicon-based phototransistors (like the TEMT6000) and photodiodes naturally respond to wavelengths between 400nm and 1100nm, peaking in the near-infrared (IR) spectrum around 850nm. Human eyes only see 400nm-700nm. If you place an analog silicon sensor near an incandescent bulb or in direct sunlight, the massive IR output will skew your Lux reading artificially high compared to what a human perceives. The Fix: For analog sensors, you must place a physical IR-cut filter (hot mirror) over the lens, or use a digital sensor like the TSL2591, which features dual photodiodes (one broadband, one IR-only) and subtracts the IR component in silicon.
2. 50Hz / 60Hz AC Mains Flicker
Artificial lighting powered by AC mains does not emit constant light; it pulses at 100Hz or 120Hz (twice the line frequency). If your microcontroller samples the ADC in a tight loop (e.g., taking 100 samples per second), your Lux readings will swing wildly. The Fix: Never use instantaneous single-shot readings for indoor light sensing. Implement a moving average over a minimum 20ms window (one full AC cycle at 50Hz) to integrate the flicker out of the signal. Digital sensors like the BH1750 handle this automatically via their internal integration time settings.
3. Cosine Correction and Field of View
Lux is defined as lumens per square meter incident on a flat surface. If light strikes your sensor at a 60-degree angle, the physical illuminance drops by 50% (Lambert's Cosine Law). Bare phototransistors have a narrow acceptance angle (often ±60°) and suffer from severe cosine error at the edges. If you are building a weather station or a smart-home wall switch, you must mount the sensor under a diffusing PTFE (Teflon) dome or a frosted polycarbonate cap to scatter the light and approximate a true 180-degree hemispherical response.






