The Physics of Photon Detection

Light sensors convert electromagnetic radiation in the visible, infrared, or ultraviolet spectrums into measurable electrical signals. At the semiconductor level, this relies on the internal photoelectric effect: when a photon with sufficient energy strikes the depletion region of a PN junction (or a photoconductive material like cadmium sulfide), it excites an electron into the conduction band. This creates an electron-hole pair, temporarily lowering the material's resistance or generating a small photocurrent proportional to the incident light intensity.

The physical package and integrated filters dictate the sensor's spectral response. Human eyes peak in sensitivity around 555 nm (green-yellow), but bare silicon photodiodes peak near 800-900 nm (near-infrared). High-quality ambient light sensors integrate optical filters (like the IR-cut filter on the BH1750FVI) to mimic the human luminosity function. This ensures the raw electrical output accurately correlates with perceived brightness rather than invisible heat radiation from incandescent bulbs or sunlight.

Analog vs. Digital: Choosing Your Sensor

Bench Tip: Never conflate analog voltage dividers with digital I2C light sensors. An LDR outputs a variable resistance requiring a bias circuit to produce a voltage, while a digital IC outputs a pre-calibrated 16-bit integer over an I2C bus. Treating them interchangeably in firmware will result in garbage data.
Table 1: Common Light Sensor Specifications (2026 Market Data)
Part Number Type Output Signal Supply Range Spectral Peak Approx. Cost
GL5528 CdS Photoresistor (LDR) Variable Resistance N/A (Passive) 540 nm (Green) $0.10
TEMT6000X01 NPN Phototransistor Current (Analog) 2.5V - 6.0V 570 nm (Yellow) $0.85
BH1750FVI Digital Ambient IC I2C (16-bit Digital) 2.4V - 3.6V 550 nm (Human Eye) $2.50

Interfacing and Wiring to Microcontrollers

When wiring light sensors to a 3.3V logic microcontroller like the ESP32 or Raspberry Pi Pico, you must respect the supply range and logic levels. Supplying a 3.3V I2C sensor with 5V will permanently damage the internal ADC and I2C transceivers.

Wiring Pinout Table (ESP32 DevKit V1)

Sensor Pin ESP32 Pin Notes
VCC / VIN 3V3 Do not use 5V for BH1750 or TEMT6000 on 3.3V boards
GND GND Common ground required for I2C and ADC references
SCL (BH1750) GPIO 22 Default I2C SCL; requires 4.7kΩ pull-up to 3.3V
SDA (BH1750) GPIO 21 Default I2C SDA; requires 4.7kΩ pull-up to 3.3V
OUT (TEMT6000) GPIO 34 ADC1_CH6; input only, no internal pull-up needed

Numbered Wiring Steps

  1. De-energize the breadboard: Disconnect the USB cable or power supply before routing jumper wires to prevent shorting the I2C bus.
  2. Route Power: Connect the sensor VCC to the ESP32 3.3V pin. Verify with a multimeter that the rail reads between 3.25V and 3.35V.
  3. Wire the Signal: For I2C (BH1750), connect SDA and SCL. If your breakout board lacks onboard pull-up resistors, solder 4.7kΩ resistors between the SDA/SCL lines and the 3.3V rail.
  4. Verify Connections: Set your multimeter to continuity mode. Check for shorts between VCC and GND before applying power.

Converting Raw Data to Physical Units (Lux Math)

A raw ADC reading or I2C register value is useless without conversion to a physical unit. The standard metric for illuminance is the lux (lumens per square meter). Here is the exact math for both digital and analog outputs.

Digital Output Math (BH1750FVI)

The BH1750 handles the analog-to-digital conversion and spectral scaling internally. It outputs a raw 16-bit integer via I2C. According to the Rohm BH1750FVI datasheet, the resolution in standard continuous mode is 1.2 lux per LSB.

Formula:
Lux = Raw_16bit_Value / 1.2
If the sensor returns a raw hex value of 0x00D5 (213 in decimal), the illuminance is 213 / 1.2 = 177.5 lux.

Analog Output Math (TEMT6000 Phototransistor)

Analog sensors require external biasing. The TEMT6000 acts as a current source. According to the Vishay TEMT6000 datasheet, the typical photocurrent is 2.0 µA at 1000 lux. This means I (Amps) = Lux × 2e-9.

Bench Reality Check: Most cheap breakout boards use a 10kΩ pull-down resistor. At 1000 lux, 2 µA across 10kΩ yields only 0.02V—far too low for a 12-bit ADC to read accurately. To fix this, swap the resistor for a 100kΩ pull-down.

Formula with 100kΩ resistor and ESP32 12-bit ADC (3.3V reference):
V_out = (Lux × 2e-9) × 100,000 = Lux × 0.0002
Lux = V_out / 0.0002 = V_out × 5000
Since V_out = (ADC_Raw × 3.3) / 4095, we substitute:
Lux = ((ADC_Raw × 3.3) / 4095) × 5000
Lux = ADC_Raw × 4.029

Calibration, Scaling, and Interference Sources

Even with perfect math, real-world environments introduce noise that ruins sensor accuracy. You must account for these three common interference sources:

  • Mains Flicker (50/60Hz): AC-powered lighting (especially fluorescent and cheap LED drivers) pulses at 100Hz or 120Hz. If your sensor's integration time is too short, you will sample the peaks and troughs of the AC wave, causing wild lux swings. Fix: Set the BH1750 to "Continuous High-Resolution Mode 2" (120ms integration time) to average out the ripple, or implement a 50-sample moving average filter in firmware for analog sensors.
  • ESP32 ADC Non-Linearity: The Espressif ESP32 ADC documentation explicitly warns that the SAR ADC is non-linear, especially below 0.15V and above 3.1V. Fix: Keep your analog sensor's voltage output strictly between 0.5V and 2.5V by tuning your pull-down resistor value, or use an external I2C ADC like the ADS1115.
  • IR Contamination: Sunlight contains massive amounts of near-infrared radiation. Bare photodiodes will read direct sunlight as blindingly bright, even if the visible light is moderate. Fix: Only use sensors with integrated IR-cut optical filters (like the BH1750 or TSL2591) for applications requiring human-perceived brightness tracking.

Frequently Asked Questions

What are light sensors used for in home automation?

In home automation, light sensors are primarily used for closed-loop lighting control and energy savings. By monitoring ambient lux levels near windows, a microcontroller can dim or turn off artificial LED fixtures when natural daylight exceeds 300 lux (standard office desk lighting). They are also used to trigger circadian lighting routines, shifting smart bulbs to warmer 2700K color temperatures as evening ambient light drops below 50 lux.

What are light sensors called when they only detect infrared?

Sensors optimized exclusively for the infrared spectrum (typically 850 nm to 940 nm) are usually called photodiodes or IR receivers. When packaged with a demodulator circuit to filter out ambient visible light and only listen for a specific carrier frequency (like 38 kHz), they are known as IR receiver modules (e.g., the TSOP38238), which are standard in remote control applications rather than ambient light measurement.

What are light sensors' typical lux ranges for indoor vs outdoor?

Understanding the logarithmic scale of light is critical for selecting the right sensor range. A dark bedroom at night measures 0.1 to 1 lux. A well-lit office desk sits around 300 to 500 lux. Direct indoor sunlight hitting a floor can reach 10,000 lux. Outdoors, an overcast day measures 10,000 to 25,000 lux, while direct midday summer sunlight can exceed 100,000 lux. Ensure your chosen sensor does not saturate (clip at its maximum register value) when exposed to your target environment's peak brightness.