If you are wiring an analog dust detection sensor like the Sharp GP2Y1014AU0F to a 3.3V microcontroller like the ESP32, the direct answer is that you must use a voltage divider to protect the ADC, pulse the internal IR LED, and sample the ADC exactly 280µs later. The sensor outputs an analog voltage (typically 0.9V to 4.0V) proportional to particulate matter. Digital variants like the Plantower PMS5003 output pre-calculated UART serial packets, while older models like the Shinyei PPD42NS output a digital PWM pulse width. To get physical units (µg/m³) from the analog Sharp sensor, you must apply a linear transfer function to the scaled voltage reading.
How Optical Dust Detection Sensors Actually Work
Optical particulate sensors rely on the physics of Mie scattering. Inside the sensor chamber, an infrared LED emits a focused beam of light. A photodiode is positioned at a specific angle (usually between 45 and 60 degrees) relative to the LED. When airborne particles pass through the light beam, they scatter the photons; the photodiode detects this scattered light and generates a current proportional to the volume of scattered light, which the internal op-amp converts to a voltage. This principle allows the sensor to estimate the mass concentration of particulate matter (PM) in the air, a critical metric for monitoring indoor air quality and tracking EPA-defined PM2.5 and PM10 thresholds.
Because these sensors require particles to physically enter the optical chamber, airflow management is critical. Budget analog sensors use passive thermal convection—an internal heating resistor warms the air, creating an updraft that pulls ambient air through the bottom vents. Higher-end digital sensors (like the Sensirion SPS30 or Plantower PMS5003) use integrated micro-fans to force a consistent, metered volume of air across the laser or LED beam, drastically improving response time and accuracy at the cost of higher power draw and mechanical noise.
Hardware Specifications and Wiring Pinouts
Before wiring anything, you need to select the right sensor for your application's required resolution and interface. Below is a data-dense comparison of the most common dust detection sensors on the maker market in 2026.
| Model | Interface / Output | Supply Range | Min Detectable Size | Typical Price | Best Use Case |
|---|---|---|---|---|---|
| Sharp GP2Y1014AU0F | Analog Voltage (Pulsed) | 4.5V - 5.5V | ~1.0 µm | $12 - $18 | Basic smoke/dust alarms, HVAC triggers |
| Plantower PMS5003 | Digital UART (3.3V) | 5.0V (via USB/JST) | 0.3 µm | $25 - $35 | DIY air quality monitors, Home Assistant |
| Sensirion SPS30 | Digital I2C / UART | 4.5V - 5.5V | 0.3 µm | $45 - $60 | Medical-grade IAQ, certified lab logging |
| Shinyei PPD42NS | Digital PWM (Pulse Width) | 4.5V - 5.5V | 1.0 µm | $20 - $30 | Legacy Arduino projects, coarse dust |
Sharp GP2Y1014AU0F Wiring to ESP32
The Sharp sensor uses a 6-pin JST connector. Because the sensor requires a 5V supply but the ESP32's ADC pins will be damaged by voltages exceeding 3.3V (and realistically become non-linear above 3.1V), you must use a voltage divider on the analog output pin. A simple 10kΩ / 10kΩ resistor divider will safely halve the output voltage.
| Sensor Pin | Function | ESP32 Connection | Notes / Components |
|---|---|---|---|
| 1 (V-LED) | IR LED Anode | ESP32 GPIO 25 | Drive via NPN transistor (e.g., 2N2222) to handle 150mA pulse current. |
| 2 (LED-GND) | IR LED Cathode | System GND | Connect to common ground. |
| 3 (V-CC) | Sensor Logic Power | 5V Source | Do NOT power from ESP32 3V3 pin. Use external 5V or USB VBUS. |
| 4 (Vout) | Analog Output | ESP32 GPIO 34 (ADC) | Route through 10kΩ/10kΩ voltage divider first! |
| 5 (GND) | System Ground | System GND | Connect to common ground. |
| 6 (Vref) | Op-Amp Reference | Not Connected (NC) | Internally tied for standard calibration. Leave floating. |
Converting Raw ADC Readings to µg/m³ (The Math)
The analog output of the Sharp sensor is not a steady DC voltage; it is a pulsed signal synchronized to the internal IR LED. To get a valid reading, you must pulse the LED, wait for the photodiode to stabilize, read the ADC, and then turn the LED off. The total cycle time is 10ms, and the ADC must be sampled exactly 280µs after the LED turns on.
Step 1: Reverse the Voltage Divider
Because we halved the voltage using a 10kΩ/10kΩ divider, the ESP32 reads half the actual sensor output. First, reconstruct the true sensor voltage:
V_sensor = V_adc * 2.0
Step 2: Map ADC Bits to Voltage
The ESP32's 12-bit ADC returns a raw integer between 0 and 4095, mapping to 0.0V - 3.3V. (Note: For production firmware, use analogReadMilliVolts() and ESP32 ADC calibration eFuses to correct for the chip's notorious non-linearity, but the standard float mapping is sufficient for bench prototyping).
V_adc = (raw_adc / 4095.0) * 3.3
Step 3: Apply the Sharp Transfer Function
According to the manufacturer's application note, the sensor outputs roughly 0.9V in perfectly clean air, and the voltage scales linearly at a sensitivity of 0.005V per µg/m³. The raw-to-unit math is:
Dust_Density (µg/m³) = (V_sensor - 0.9) / 0.005
0.9 in the formula with your measured baseline to eliminate zero-point drift.
Complete ESP32 Arduino C++ Implementation
// Pin Definitions
const int LED_PIN = 25; // GPIO driving the NPN transistor base
const int ADC_PIN = 34; // ADC1 channel for reading (GPIO 34)
// Timing Constants (microseconds)
const int DELAY_BEFORE_READ = 280;
const int DELAY_AFTER_READ = 40; // 280 + 40 = 320us LED on-time
const int TOTAL_CYCLE_MS = 10;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // LED off initially
analogReadResolution(12); // Ensure 12-bit resolution
}
void loop() {
digitalWrite(LED_PIN, HIGH); // Turn on IR LED
delayMicroseconds(DELAY_BEFORE_READ);// Wait for photodiode response
int raw_adc = analogRead(ADC_PIN); // Sample ADC
delayMicroseconds(DELAY_AFTER_READ); // Complete LED pulse width
digitalWrite(LED_PIN, LOW); // Turn off IR LED
// Math: Raw to Voltage (ESP32 3.3V reference)
float v_adc = (raw_adc / 4095.0) * 3.3;
// Math: Reverse 10k/10k voltage divider
float v_sensor = v_adc * 2.0;
// Math: Voltage to Dust Density (ug/m3)
float baseline_v = 0.90; // REPLACE with your clean-air calibration value
float dust_density = (v_sensor - baseline_v) / 0.005;
// Prevent negative values from noise floor
if (dust_density < 0) dust_density = 0.0;
Serial.print("Raw ADC: "); Serial.print(raw_adc);
Serial.print(" | V_sensor: "); Serial.print(v_sensor, 3);
Serial.print("V | Dust: "); Serial.print(dust_density, 2);
Serial.println(" ug/m3");
// Wait remainder of 10ms cycle
delay(TOTAL_CYCLE_MS - 1);
}
Interference, Humidity, and Real-World Calibration
Optical dust sensors are notoriously susceptible to environmental false positives. If your data logs show massive spikes in particulate matter that don't match reality, you are likely falling victim to one of three common interference sources.
1. The Humidity Problem (Water Droplet Scattering)
This is the number one failure mode for DIY air quality stations. Water droplets in high-humidity air scatter IR light just like solid dust particles. When relative humidity (RH) exceeds 70%, the Sharp sensor will report artificially high PM levels. If a foggy morning triggers a 'hazardous smoke' alert on your dashboard, humidity is the culprit.
- The Fix: You cannot fix this in the optical chamber. You must pair the dust sensor with a digital humidity sensor (like an SHT40 or BME280) and apply a software compensation curve in your backend (e.g., Home Assistant or Node-RED) that dampens or ignores dust readings when RH > 75%.
2. Ambient Infrared Light Swamping
The photodiode inside the sensor is sensitive to the IR spectrum. If direct sunlight or a halogen desk lamp shines into the sensor's ventilation slots, the ambient IR will swamp the photodiode, pinning the output voltage high and maxing out your calculated µg/m³.
- The Fix: Never mount an exposed optical sensor near a window. If the sensor must be in a sunlit room, design a 3D-printed enclosure with a baffled, serpentine air intake path that allows air to flow in but blocks direct line-of-sight light from reaching the internal chamber.
3. Physical Orientation and Convection Stall
Because the GP2Y1014AU0F relies on a thermal updraft generated by its internal heating resistor to pull air through the chamber, it must be mounted vertically with the ventilation holes facing up and down. If you mount it horizontally on a breadboard or flat against a ceiling, the convection current stalls, air stops moving through the optical path, and the sensor will read zero dust regardless of the actual air quality.
- The Fix: Always mount the sensor PCB perpendicular to the ground. If your enclosure design requires a horizontal layout, you must abandon the passive Sharp sensor and upgrade to an active-fan model like the Sensirion SPS30 or Plantower PMS5003, which force air through the chamber regardless of gravity.






