In this tutorial you will learn how to use the Dust Sensor GP2Y1010AU0F with an Arduino to measure dust density. We will discuss the sensor’s features, how to connect it to an Arduino board, and how to interpret the data it provides.
Measuring dust densities is important for health because high levels of dust in the air can lead to respiratory issues, allergies, and other health problems. Monitoring dust levels allows us to assess indoor and outdoor air quality, identify potential health risks, and take appropriate measures to improve air quality.
Required Parts
I used an Arduino Uno for this project but any other Arduino board, or an ESP8266/ESP32 board will work just as well.
The GP2Y1010AU0F dust sensor comes with a 220µF capacitor and a 150Ω resistor, which are required for wiring the sensor with an Arduino. No need to buy them separately.
Dust Sensor GP2Y1010AU0F
Arduino Uno
Dupont Wire Set
Breadboard
USB Cable for Arduino UNO
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.
Basics of the GP2Y1010AU0F Dust Sensor
The GP2Y1010AU0F is an optical air quality sensor, designed to sense dust particles. It is especially effective in detecting very fine particles like cigarette smoke, and is commonly used in air purifier systems. The following image show the sensor.
Internal Structure
Within the senor an infrared LED and a infrared photoresistor are diagonally arranged. The light of the IR LED is reflected by the dust particles entering the device via a hole (dust path). The amount of reflected IR light is measured by the infrared sensor and converted into an output voltage. The more dust is in the dust path the more light is reflected and the higher is the output voltage. The picture below shows the internal construction of the GP2Y1010AU0F sensor.
The GP2Y1010AU0F has a low current consumption of 20mA max or 11mA typical, and runs on 5V. Its output voltage is proportional to the measured dust density, with a sensitivity of 0.5V/0.1mg/m3. The sensor can detect particles a small as 0.5µm and the maximal dust density it can measure is 580 µg/m3.
Internal Schematics
The following image shows the internal schematics of the GP2Y1010AU0F. You can see the circuit that drives the IR LED (IRED) and the amplifier circuit with the IR photodiode (PD) that creates the output signal Vo at pin 5.
There is also a trimmer (adjustable resistor Rs) to adjust the sensitivity of the sensor but you should not change it. In the image below you can see the location of the trimmer and the amplifier IC.
The GP2Y1010AU0F has a six pin connector. The infrared LED is powered via (1) V-LED and (2) LED-GND and controlled via pin (3) LED. The signal amplifier IC is powered via (6) Vcc and (4) S-GND and the output volage signal Vo is on pin (5).
Datasheets
For more detailed information on the GP2Y1010AU0F have a look at its datasheet and the application notes linked below.
Connecting the GP2Y1010AU0F to Arduino
To connect the GP2Y1010AU0F to Arduino we need to follow the application example provided in in the Application Notes (see below).
You can see that the output signal Vo at pin (5) goes into the analog-digital converted (A/D) of the microcontroller and that the IR LED at pin (3) is controlled via an output pin of the microcontroller.
We won’t need the depicted transistor to drive the IR LED since an Arduino GPIO pin can easily provide the required 20mA for the LED. There is also a little bit of additional circuitry such as a 150Ω current limiting resistor for the IR LED and a 220µF capacitor, but nothing too complicated.
The following pinout shows where the six pins are located on the connector of the actual sensor.
V-LED
powers the LED and needs to be connected to 5V with a 150Ω resistor. LED-GND
is the ground for the IR LED and is connected to the GND
pin of the Arduino. LED
is used to switch the LED and we connect it to pin 7 of the Arduino. Though any other digital output pin will work as well.
S-GND
is the ground for the sensor and should be connected to the GND
pin of the Arduino. Vo
provides the sensor output and will be connect to the analog input A0
of the Arduino. Vcc
is the power for the sensor module and need to be connected to 5V.
The following picture shows the complete wiring on a breadboard, including the 220µF capacitor.
When connecting the capacitor watch out for correct polarity. Its negative pin (usually shorter and marked by a white stripe) must be connected to ground (black wire).
Code for measuring dust density with GP2Y1010AU0F
To measure dust density let’s have a look at the response curve of the GP2Y1010AU0F first. It shows how the output voltage Vo changes with increasing dust density, measured as milligrams per cubic meter (mg/m3).
For dust densities from 0 to 0.5 mg/m3 the graph shows a largely linear relationship between voltage and dust density. Once we get close to the maximum density of 580 µg/m3 (=0.58 mg/m3) the sensor can detect, the curve flattens out and we cannot measure anything useful anymore. The maximum output voltage will be around 3.7V at this point.
Calculating Dust Densities
The linear part of the graph can be described by the following equation:
D[mg/m3] = 0.170 x Vo − 0.1
It allows us to calculate the dust density D in mg/m3 by measuring the output voltage Vo with the Arduino. Since the dust densities in mg/m3 tend to be small numbers, we can also measure the densities in µg/m3, simply by multiplying the dust densities in mg/m3 by 1000.
D[µg/m3] = (0.170 x Vo − 0.1) x 1000
Sampling Protocol
The datasheet for the GP2Y1010AU0F states that we should use the following sampling protocol when measuring dust densities. After switching on the IR LED we should wait for 0.28 milliseconds, then read the output voltage Vo and after that switch of the IR LED.
With the dust density equation above and the sampling protocol we now have all the information to write the code to actually measure dust densities with the GP2Y1010AU0F and an Arduino.
Code for measuring Dust Density
Have a look at the complete code first and then we take it apart and discuss its details.
const int sensorPin = A0; const int ledPin = 7; const int adcMax = 1023; const float Vcc = 5.0; float readDensity() { digitalWrite(ledPin, LOW); delayMicroseconds(280); int adc = analogRead(sensorPin); float v0 = Vcc * adc / adcMax; float density = 0.170 * v0 - 0.1; // mg/m^3 digitalWrite(ledPin, HIGH); return density * 1000; // ug/m^3 } void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); delay(1000); } void loop() { Serial.print("Dust:"); Serial.println(readDensity()); delay(1000); }
Constants
The code starts by defining some constants. sensorPin
is the analog input the Vo
output of the dust sensor is connect to, and ledPin
is the the digital output that controls the IR LED within the dust sensor.
adcMax
is the maximal value the analog-digital-converter (ADC) can produce. In case of the Arduino Uno, which has a 10-bit ADC this value is 1023. If you use a different microcontroller you have to adjust this value. See the analogRead()
function or the datasheet of your microcontroller for more information.
We also specify the voltage of the power supply Vcc
here. In theory the sensor can run on 3.3V as well but then you have to adjust the resistor for the IR LED or keep that voltage a 5V. Also you will have to make sure that the analog input does not exceed the maximal voltage. To keep thing simple, it is easier to stick with 5V.
const int sensorPin = A0; const int ledPin = 7; const int adcMax = 1023; const float Vcc = 5.0;
Reading Dust Density
Next we have the function readDensity()
that reads the dust density measured by the sensor. First the function switches on the IR LED via digitalWrite(ledPin, LOW)
. Note that the logic is inverted (LOW means on).
Then we wait the 0.28ms (=280µs) as advised by the datasheet before reading the Vo
output of the sensor using analogRead()
. However, the ADC of the Arduino does not return the voltage at A0 but a raw adc value (0…1023) that we need to convert to the v0
voltage via v0 = Vcc * adc / adcMax
.
Now we can apply the equation shown above to convert the v0
voltage into a dust density
measure in mg/m^3. After switching of the IR LED we multiply the dust density
by 1000 to return a measurement in µg/m3.
float readDensity() { digitalWrite(ledPin, LOW); delayMicroseconds(280); int adc = analogRead(sensorPin); float v0 = Vcc * adc / adcMax; float density = 0.170 * v0 - 0.1; // mg/m^3 digitalWrite(ledPin, HIGH); return density * 1000; // ug/m^3 }
Setup function
The setup function is simple. We initiate the serial interface, set the mode of the ledPin
to OUTPUT and wait for a second – the datasheets says the sensor needs about 1 second to get ready.
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); delay(1000); }
Loop function
In the loop function, we simply call our readDensity()
function and print the measured dust density to the serial monitor. We repeat the measurement approximately every second (not counting the 0.28ms for the measurement). You can sample faster, down to 100ms works fine. Faster than that and I noticed the that the sensor stopped reacting properly.
void loop() { Serial.print("Dust:"); Serial.println(readDensity()); delay(1000); }
Output Example
If you open the Serial Plotter you should see the normal dust densities fluctuating around 0 µg/m3. I vigorously shook a duster in front of the sensor and you can see the spike in dust density in the graph below.
Then I burnt a match and the sensor again reacted strongly to the smoke produced. Note that the smoke lingered longer than the dust.
Finally, you can also test the function of the sensor and code by blocking the dust path with an object, for instance a small screw driver as shown in the picture below.
The measured dust density should go up close to the maximum value of around 580 µg/m3 that the sensor can measure. I was getting a value of 534 µg/m3.
And there you have it! A nice little dust sensor that will help you to keep your environment healthy.
Conclusions
The GP2Y1010AU0F is an easy to use and a quite sensitive sensor. It reacts nicely to dust, smoke and should be able to detect pollen as well, though I have not yet tested this.
When connecting the sensor to a different microcontroller than the Arduino Uno used here, watch out for different voltages (5V vs 3.3V), and the resolution and input range of the analog-digital-converter (ADC). Many tutorials for the GP2Y1010AU0F get this slightly wrong and the resulting measurements of dust density are incorrect. Also watch out for the mg/m3 to µg/m3 conversion, which is sometimes wrongly implemented.
Finally, if you need a sensor that can measure the concentration of PM.2.5 particles have a look at the DSM501 sensor.
FAQ
What are health and unhealthy levels of dust density when measured in µg/m3?
Healthy levels of dust density are typically below 50 µg/m3, while unhealthy levels are above 150 µg/m3.
What is the relationship between dust density measured in µg/m3 and Particulate matter PM, specifically PM2.5 and PM10?
Dust density measured in µg/m3 is directly related to particulate matter (PM), including PM2.5 and PM10. PM2.5 refers to particles with a diameter of 2.5 µm or smaller, while PM10 refers to particles with a diameter of 10 µm or smaller. Higher dust density indicates higher levels of PM2.5 and PM10 in the air.
Why is PM2.5 pollution bad for your health?
Of all air pollution measures, PM2.5 pollution poses the greatest health threat. Due to its small size, PM2.5 can remain suspended in the air for long periods of time and can be absorbed deep into the bloodstream upon inhalation.
What are the main sources of PM2.5 pollution?
Common sources of PM2.5 pollution are motor and combustion, industrial processes stoves, fireplaces, and home wood burning, smoke from fireworks and wildfires, smoking, dust and pollen particles.
Can a PM2.5 or PM10 sensor measure pollen?
Most pollen particles are larger than PM2.5 and PM10 particles and would be ignored by a PM2.5 or PM10 sensor. However, while Pollen particles are usually over 10 µm they can break into smaller particles in the PM2.5 range, which can be measured.
Can I calibrate the GP2Y1010AU0F sensor to measure PM2.5 or PM25 values?
No, the GP2Y1010AU0F sensor is designed to detect larger particles and cannot be calibrated to measure PM2.5 or PM25 values.
What is the typical size of pollen and can a dust sensor such as the GP2Y1010AU0F measure pollen density?
The typical size of pollen is around 10-100 µm. If you can see the pollen floating in the air, this means the particle is quite big, at least 60 µm in size. The GP2Y1010AU0F dust sensor can measure particles larger than 0.5 µm, so it can detect pollen particles.
What is an unhealth level of pollen density?
An unhealthy level of pollen density would typically be considered high when it exceeds 100 grains per cubic meter, which may trigger allergies in sensitive individuals.
What density in µg/m^3 corresponds to 100 grains per cubic meter?
The conversion from grains to micrograms per cubic meter (µg/m^3) depends on the density of the specific material being measured. For pollen, the conversion factor is approximately 1 grain = 6.48 µg/m^3. Therefore, 100 grains of pollen would be equivalent to 648 µg/m^3.
Stefan is a professional software developer and researcher. He has worked in robotics, bioinformatics, image/audio processing and education at Siemens, IBM and Google. He specializes in AI and machine learning and has a keen interest in DIY projects involving Arduino and 3D printing.