Read an Optical Dust Sensor Properly: LED Timing, Baselines and Useful Trend Data
An analogue dust sensor can make a good electronics and measurement project. It can also produce a convincing graph with the wrong units, an incorrect baseline or measurements taken at the wrong instant. Before converting a voltage into a dust concentration, establish that the electronics and sampling method match the sensor.
The Sharp GP2Y1010AU0F optical dust sensor is one example in PMD Way's air-quality and dust sensor collection. It uses a pulsed optical measurement and an analogue output. This guide focuses on building a trustworthy trend logger, rather than treating the component as a ready-calibrated air-quality instrument.
Understand the optical measurement
The detector responds to light scattered by particles in its sensing region. It does not weigh collected dust or identify a particle's chemical composition. Its output also includes a background contribution, so a non-zero voltage is not automatically evidence of a particular dust concentration.
Particle size, composition and environmental conditions can change the relationship between optical response and mass concentration. The US EPA air sensor guidebook explains these limitations and the need to understand sensor performance. A generic sensitivity equation should not be presented as a universal PM2.5 conversion.
Choose a modest initial question: does the signal remain stable in one location, and does it show repeatable changes during ordinary room activity? Keep the result labelled as sensor voltage or relative response until a suitable comparison supports stronger units and claims.
Use operating limits, not absolute maximum ratings
Sharp's dust-sensor specifications list a 4.5–5.5 V operating supply for this model. Use a suitable regulated nominal 5 V supply. The 7 V figure in the GP2Y1010AU0F datasheet is an absolute maximum, not a recommended operating voltage.
Before connecting the included cable, identify the connector orientation and pin numbering from the drawing. Wire colours alone are not sufficient evidence. The sensor has separate LED and signal-related connections, and the LED drive needs the specified circuit rather than a guessed connection to a GPIO supply pin.
Sharp's application note specifies a 150 Ω resistor and 220 µF capacitor for the LED pulse-drive arrangement. Follow that complete circuit, including capacitor polarity and the required drive behaviour. Check whether an interface board already contains these parts before adding duplicates.
The analogue output must also fit the host ADC input range. A 3.3 V microcontroller should not receive an unchecked signal from a 5 V sensor. Design a suitable interface from the documented maximum output, ADC limits and loading requirements; then verify its scale with known voltages.
Sample at the specified point in the LED pulse
The application note uses a 10 ms pulse cycle and 0.32 ms LED-on interval, with the output sampled 0.28 ms after the LED turns on. These timings define the measurement conditions. Reading the output whenever the main loop happens to reach it is a different experiment.
Consider the ADC's actual acquisition instant, not only the moment a software function is called. Library overhead, conversion duration and interrupt activity can shift the measurement. Check the waveform and sampling timing with suitable equipment, particularly when moving code to another microcontroller.
Keep network transfers, display drawing and storage writes outside the critical sampling sequence. Save the sample quickly, finish the LED cycle and process the result afterwards. A logger that works until Wi-Fi connects may have a scheduling problem rather than a dusty room.
Record missed timing deadlines as invalid samples. Substituting zero creates artificial dips; repeating the previous value hides missing information. A validity flag makes the later graph easier to interpret.
Build the logger in layers
- Verify the supply and interface with the sensor connected.
- Confirm LED timing and output sampling with a minimal program.
- Log ADC counts, converted voltage, timestamp and validity status.
- Add a documented averaging interval.
- Add baseline subtraction and any later concentration estimate separately.
Check the ADC reference voltage rather than assuming it is exactly the board's nominal supply. For a hypothetical ideal 12-bit ADC with a 3.3 V full-scale reference, one code step is approximately 3.3/4096 V, or 0.806 mV. If an input divider is fitted, include its measured ratio in the voltage reconstruction. This calculation describes digitisation, not dust-measurement accuracy.
Retain the unfiltered readings during development. A smooth display can conceal clipped values, periodic electrical interference and timing errors. Compare averages with the raw trace before choosing a filter that merely makes the plot attractive.
Treat the baseline as a measurement condition
The Sharp application note distinguishes the background output from the dust-related increment. Establish a baseline under a documented condition and keep it with the data. Ordinary indoor air is not a certified zero-dust reference.
If you subtract a baseline, show the raw voltage too. An apparent negative increment may indicate noise, a changed baseline or a changed installation. Silently clamping every negative value to zero removes evidence that would help diagnose the problem.
A continuously adapting baseline can also absorb a sustained rise into the new normal. That may suit some appliance-control strategies, but it changes what a trend logger means. Record the baseline algorithm and avoid comparing traces generated with different rules as though they were equivalent.
Evaluate the finished enclosure
The sensor must encounter representative air while remaining protected from inappropriate contamination. Follow the manufacturer's mounting guidance and leave the intended air path unobstructed. Test the finished enclosure because its openings and placement influence what reaches the sensing region.
The EPA siting and installation guide discusses location effects, including rapidly changing conditions near doors, windows and ventilation outlets. Record placement and nearby activities with the log. Do not deliberately generate smoke or hazardous dust merely to make the graph move.
For a quantitative project, compare the logger alongside a suitable reference instrument over a meaningful range of ordinary conditions. The EPA collocation guidance explains why side-by-side evaluation is valuable. Align timestamps and averaging periods before comparing results.
Finish with repeat tests after power cycling and after installing the final cable and enclosure. Keep firmware settings, timing evidence, baseline history and comparison data together. The outcome is a useful measurement experiment with clearly stated limits, rather than an unverified substitute for a certified smoke alarm or health-protection monitor.