The Sharp GP2Y1014AU0F is a staple for DIY air quality monitoring, outputting an analog voltage pulse proportional to particulate matter (PM) concentration. To interface this sensor with an ESP32, you must drive its internal IR LED with a precise 0.32ms pulse and sample the ESP32’s ADC at exactly 280µs to capture the peak scattering voltage. This guide covers the exact wiring, the raw-to-µg/m³ conversion math, and the environmental interference factors that ruin readings.

Sensing Principle: Optical Scattering

The Sharp GP2Y1014AU0F uses optical scattering to detect airborne particulate matter. Inside the molded housing, an infrared emitting diode (IRED) fires across a dark chamber toward a phototransistor positioned at an oblique angle. When dust particles pass through the IR beam, they scatter light onto the phototransistor, generating a proportional analog voltage. The sensor relies on passive convection—air flows through the chamber naturally due to heat generated by the internal components—rather than a mechanical fan.

Unlike laser-based PM2.5 sensors (such as the Plantower PMS5003) that force air through a laser beam and output digital UART packets, this optical sensor requires strict microsecond-level timing from your microcontroller. The IRED must be pulsed to prevent overheating, and the phototransistor's analog output must be sampled at the exact moment the light scattering peaks, making the raw-to-unit conversion highly dependent on precise code execution.

Wiring and Pinout for ESP32 Integration

Callout: ESP32 ADC Voltage Limits
The GP2Y1014AU0F can output up to 4.0V in heavy dust. The ESP32's ADC saturates at ~3.1V to 3.3V and is notoriously non-linear near the rails. You must use a voltage divider on the analog output pin, or you will clip your readings during high-PM events.
Sensor Pin Function ESP32 Connection Notes / Supply Range
1 (V-LED) LED Power 5V via 150Ω Resistor Limits IRED current to ~20mA. (Skip if using a breakout board with built-in resistor).
2 (LED-GND) LED Ground GND Common ground with ESP32.
3 (LED) LED Control GPIO 25 (Output) Active LOW. Pull HIGH to turn off, LOW to turn on.
4 (S-GND) Sensor Ground GND Must share ground with LED-GND.
5 (Vo) Analog Output GPIO 34 via Divider Use 10kΩ/10kΩ divider to scale 4V down to 2V for ESP32 ADC.
6 (Vcc) Sensor Power 5V Supply range: 4.5V to 5.5V. Do not power from ESP32 3.3V pin.

Output Signal Math: Raw ADC to µg/m³

What the output actually is: The sensor outputs an analog voltage pulse. It is not a steady DC voltage; it is a transient spike that occurs only while the IR LED is pulsed. You must trigger the ADC conversion at exactly 280µs after the LED turns on to catch the peak scattering amplitude.

The Conversion Math:
According to the Sharp Optoelectronics datasheet, the relationship between output voltage and dust density is linear. The standard equation for the raw sensor (without a voltage divider) is:
Dust Density (mg/m³) = 0.17 × Voltage - 0.1
To get micrograms per cubic meter (µg/m³), which is the standard unit used by the EPA for PM air quality indexes, you multiply by 1000.

Because we are using a 10kΩ/10kΩ voltage divider (ratio = 2.0) to protect the ESP32, we must multiply the read voltage by 2 before applying the Sharp formula. Furthermore, modern ESP32 Arduino cores (v3.x) include analogReadMilliVolts(), which uses the chip's internal eFuse calibration data to bypass the ESP32's notorious ADC non-linearity. Always use this function instead of raw analogRead().


#include <Arduino.h>

const int LED_PIN = 25;
const int ADC_PIN = 34;
const float DIVIDER_RATIO = 2.0; // 10k/10k voltage divider

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH); // LED OFF (Active LOW)
  analogSetAttenuation(ADC_11db); // Set full 3.3V range
}

void loop() {
  // 1. Pulse the IR LED ON
  digitalWrite(LED_PIN, LOW); 
  
  // 2. Wait exactly 280 microseconds for scattering to peak
  delayMicroseconds(280); 
  
  // 3. Sample the ADC (returns calibrated millivolts)
  int adc_mv = analogReadMilliVolts(ADC_PIN); 
  
  // 4. Turn LED OFF (Total pulse width ~0.32ms)
  delayMicroseconds(40); 
  digitalWrite(LED_PIN, HIGH); 
  
  // 5. Math: mV to V, apply divider, then Sharp formula
  float voltage_raw = adc_mv / 1000.0;
  float voltage_actual = voltage_raw * DIVIDER_RATIO;
  
  // Sharp formula: mg/m3 = 0.17 * V - 0.1
  float dust_mg_m3 = (0.17 * voltage_actual) - 0.1;
  
  // Convert to µg/m³ and clamp negative values (clean air offset)
  float dust_ug_m3 = dust_mg_m3 * 1000.0;
  if (dust_ug_m3 < 0) dust_ug_m3 = 0; 
  
  Serial.printf("PM Density: %.2f µg/m³\n", dust_ug_m3);
  
  // Wait for next cycle (Datasheet recommends 100ms+ interval)
  delay(1000); 
}

Calibration, Scaling, and Interference Sources

Calibration and Scaling: The - 0.1 in the math equation represents the sensor's 'clean air' zero-offset voltage (typically around 0.6V to 0.9V at the sensor pin). However, manufacturing tolerances mean your specific unit might output slightly higher or lower in perfectly clean air. To calibrate, power the sensor in a known clean environment (or cover it completely to block dust while allowing air), record the baseline voltage, and replace the 0.1 constant with your measured baseline offset.

Common Interference Sources:

  • High Humidity: Water droplets scatter IR light exactly like dust particles. If relative humidity exceeds 70%, the sensor will report massive false spikes. You must pair this sensor with a BME280 humidity sensor and apply a software compensation curve to subtract humidity-induced scattering.
  • Ambient IR Light: Direct sunlight contains heavy infrared radiation. If the sun hits the sensor's optical chamber, the phototransistor will saturate. Always mount the sensor in a shaded, 3D-printed enclosure with a labyrinth air-intake to block direct light paths.
  • Mounting Orientation: Because this sensor relies on thermal convection to draw air through the chamber, it must be mounted vertically with the intake holes facing downward. Mounting it horizontally stalls airflow and results in zero-readings.

FAQ: Common Questions on Sensors and Detectors

Why do optical dust sensors and detectors give false highs in high humidity?

Optical particulate sensors and detectors operate by measuring light scattering. Water vapor, when it condenses into microscopic droplets in high-humidity environments (above 70% RH), refracts and scatters the sensor's internal IR beam just like solid dust does. The phototransistor cannot distinguish between a solid PM2.5 particle and a liquid water droplet. To fix this, professional setups use a heating resistor at the air inlet to evaporate moisture before it enters the chamber, or apply a algorithmic discount factor based on a co-located capacitive humidity sensor.

How do analog air quality sensors and detectors differ from digital UART models?

Analog air quality sensors and detectors, like the GP2Y1014AU0F, output a raw voltage that requires the microcontroller to handle precise timing, ADC sampling, and mathematical conversion. They are cheaper ($10-$15) but demand more CPU overhead and calibration. Digital UART models (like the PMS5003 or SPS30) contain an internal microcontroller and a laser diode. They actively pull air in with a fan, count individual particles using laser diffraction, and output pre-calculated digital packets via serial. Digital models are more accurate for specific PM1.0/PM2.5/PM10 bins but cost significantly more ($25-$60) and draw higher continuous current.

What is the typical lifespan of IR-based particulate sensors and detectors?

The lifespan of IR-based particulate sensors and detectors is primarily limited by the degradation of the internal infrared emitting diode (IRED). The Sharp GP2Y1014AU0F datasheet rates the IRED for roughly 5 years of continuous operation if pulsed correctly. If you leave the IR LED on continuously (DC instead of pulsing) or fail to use the current-limiting 150Ω resistor, the IRED will overheat and burn out in a matter of weeks. Additionally, in highly polluted or industrial environments, the optical chamber can physically accumulate grime on the lens, requiring compressed air cleaning every 6 to 12 months to maintain calibration accuracy.