To interface a dust sensor with an ESP32, you must first choose between analog infrared sensors (like the Sharp GP2Y1014AU, requiring pulsed GPIOs and ADC math) or digital laser scattering sensors (like the Plantower PMS5003, outputting UART PM2.5 data directly). The analog route demands precise timing and empirical voltage-to-density formulas, while the digital route requires 5V-to-3.3V logic level shifting to protect the ESP32's GPIO pins. This guide provides the exact wiring, raw-to-unit conversion math, and bench-tested interference mitigations for both architectures.
The Physics of Light Scattering
Dust sensors operate on the principle of Mie scattering, where a focused light beam intersects an airflow chamber. When airborne particulates pass through the beam, they scatter photons at specific angles toward a photodetector. The intensity of the scattered light is directly proportional to the mass concentration of the particles in the air, allowing the sensor's internal or external circuitry to translate optical flashes into electrical signals representing particulate matter (PM) density.
The primary divergence in modern modules is the light source. Infrared LED sensors (analog) use a broad, low-coherence beam that detects general dust density but struggles to differentiate particle sizes, requiring external microcontrollers to pulse the LED and sample the analog voltage. Laser scattering sensors (digital) use a focused, high-coherence laser diode and an integrated microcontroller to count individual particle scatter events, categorizing them into PM1.0, PM2.5, and PM10 bins before transmitting the data via a digital serial stream.
Hardware Selection: Analog vs. Laser Scattering Modules
Choosing the right module depends on your required resolution, budget, and microcontroller overhead. Below is a data-dense comparison of the most common bench and commercial modules available for embedded air quality projects.
| Module | Principle | Output Type | Min Particle Size | Typical Price (2026) | Best Use Case |
|---|---|---|---|---|---|
| Sharp GP2Y1014AU | IR LED Scattering | Analog Voltage | ~1.0 µm | $6 - $9 | Basic dust presence / HVAC triggers |
| Plantower PMS5003 | Laser Scattering | UART (9600 baud) | 0.3 µm | $12 - $16 | DIY Air Quality Monitors (PM2.5) |
| Sensirion SPS30 | Laser Scattering | UART / I2C | 0.3 µm | $25 - $30 | High-accuracy indoor climate nodes |
| Honeywell HPMA115S0 | Laser Scattering | UART (Modbus-like) | 0.3 µm | $40 - $50 | Industrial / Medical-grade prototyping |
For hobbyist air quality monitors tracking EPA PM2.5 standards, the Plantower PMS5003 is the undisputed workhorse. However, if you are building a simple filter-clog detector or a high-dust industrial trigger where exact PM2.5 mass isn't required, the Sharp analog sensor is significantly cheaper and easier to source.
Wiring, Pinouts, and Power Requirements
Power and logic levels are where most ESP32 builders fry their boards or get erratic readings. The ESP32 operates at 3.3V logic, while most high-quality dust sensors require a 5V supply and output 5V logic.
| Sensor Pin | Function | ESP32 Connection (PMS5003 Digital) | ESP32 Connection (Sharp Analog) |
|---|---|---|---|
| VCC / V_IN | Power Supply (4.8V - 5.2V) | 5V (USB or Buck Converter) | 5V (Pin 1 & 4) |
| GND | Ground | GND | GND (Pin 2 & 6) |
| TX / V_OUT | Data Output | Voltage Divider -> GPIO 16 (RX2) | Direct to GPIO 34 (ADC1_CH6) |
| RX / LED_CTRL | Control Input | GPIO 17 (TX2) via Level Shifter | 2N3904 NPN Base -> GPIO 25 |
Supply Range Note: Both the PMS5003 and the Sharp GP2Y1014AU require a stable 5V rail capable of delivering at least 150mA. The PMS5003 draws ~100mA when the internal fan spins up. If your ESP32 dev board's onboard 3.3V regulator is back-feeding the 5V rail from a weak USB hub, the sensor's fan will brownout, stalling the airflow and causing PM readings to drop to zero.
Output Signal Math: Converting Raw ADC to µg/m³
The output of a digital sensor like the PMS5003 is a 32-byte UART packet containing pre-calculated PM1.0, PM2.5, and PM10 values in µg/m³. You simply parse the hex bytes (specifically bytes 10-13 for PM2.5 standard particles). However, the analog Sharp GP2Y1014AU outputs a raw voltage that requires strict timing and mathematical scaling.
The Sharp GP2Y1014AU Analog Math
The Sharp sensor does not output a continuous voltage. You must pulse the internal IR LED, wait exactly 0.28 milliseconds for the photodiode to stabilize, read the ADC, and then turn the LED off to prevent thermal drift. According to the Sharp GP2Y1014AU Application Note, the transfer function is roughly linear between 0.1 mg/m³ and 1.0 mg/m³.
The raw-to-unit conversion requires three steps:
- Raw ADC to Voltage: The ESP32's 12-bit ADC (0-4095) is notoriously non-linear. Do not use
analogRead() * 3.3 / 4095. Instead, use the ESP32 Arduino Core v3.x calibrated functionanalogReadMilliVolts()to get a true millivolt reading, as detailed in the Espressif ADC Oneshot Driver documentation. - Voltage to mg/m³: The empirical formula for the 1014AU series is
DustDensity (mg/m³) = (Voltage_V * 0.17) - 0.1. - mg/m³ to µg/m³: Multiply by 1000 to match standard AQI reporting units.
// ESP32 Sharp GP2Y1014AU Timing and Math
const int LED_PIN = 25;
const int ADC_PIN = 34;
float readDustDensity_ug() {
digitalWrite(LED_PIN, HIGH); // Turn on IR LED via transistor
delayMicroseconds(280); // Wait exactly 0.28ms for photodiode response
int raw_mv = analogReadMilliVolts(ADC_PIN); // Use calibrated ESP32 ADC
float voltage_V = raw_mv / 1000.0;
digitalWrite(LED_PIN, LOW); // Turn off LED to prevent heating
delayMicroseconds(40); // Total pulse width ~0.32ms per datasheet
// Apply transfer function and convert to µg/m³
float dustDensity_mg = (0.17 * voltage_V) - 0.1;
if (dustDensity_mg < 0) dustDensity_mg = 0; // Clamp negative noise
return dustDensity_mg * 1000.0;
}
Real-World Interference and Calibration Pitfalls
Dust sensors are highly susceptible to environmental noise. If your PMS5003 or analog sensor is reporting massive PM spikes when the room is clean, you are likely hitting one of three interference vectors.
1. Humidity and Water Droplets (The False PM2.5 Spike)
Optical sensors cannot differentiate between solid dust and liquid water droplets. If relative humidity exceeds 70-80%, condensation or fine mist will scatter the laser/IR beam, causing the sensor to report PM2.5 levels in the 'Hazardous' range (300+ µg/m³). Fix: Integrate a BME280 or SHT30 temperature/humidity sensor into your build. Write a software compensation curve that ignores or caps PM readings when RH > 75%, or physically mount a Nafion drying tube at the sensor's air intake for high-humidity environments.
2. Ambient IR Bleed (Analog Sensors Only)
The Sharp GP2Y1014AU's plastic housing is not perfectly opaque to external infrared light. If the sensor is mounted near a window with direct sunlight, or near an incandescent bulb, ambient IR will hit the photodiode, artificially inflating the baseline voltage. Fix: Wrap the sensor body in copper foil tape (grounded to the ESP32 GND) or heat-shrink it in opaque black tubing, leaving only the bottom intake vents exposed.
3. ESP32 ADC Noise and Ground Loops
The ESP32's WiFi/Bluetooth radio draws massive transient current spikes (up to 250mA), which causes ground bounce on the 3.3V and 5V rails. If your analog dust sensor shares a long, thin ground wire with the ESP32, this ground bounce will couple into the ADC reading, creating a 50-100mV ripple that translates to a 15-20 µg/m³ jitter in your dust data. Fix: Use a star-ground topology. Run a dedicated, thick ground wire from the sensor's GND pin directly to the main power supply ground, bypassing the ESP32 dev board's header pins entirely. Add a 100nF ceramic capacitor and a 10µF electrolytic capacitor directly across the sensor's VCC and GND pins at the socket.






