Calculate the Air Quality Index (IAQ, IQA) with a DSM501 on Arduino or ESP8266


The Air Quality Index (IAQ) is fairly easy to determine using an Arduino (or ESP8266) and a DSM501 sensor. The DSM501A is a detector capable of measuring the presence of fine particles in suspension in the atmosphere according to PM2.5 and PM10 standards. The DSM501A is a very economical sensor (about € 4.80) which can be used as a base to build an air quality measurement station connected with an ESP8266. The DSM501A is able to carry out measurements to the PM2.5 and PM10 standards. That is, it is capable of detecting particles whose diameter is less than 2.5 μm for PM2.5 and less than 1 μm for PM1.0.

Principle of the sensor

The DSM501 is a Led optical detector that is more economical to manufacture than Laser models. The operating principle is similar to the smoke detectors used in fire detectors. The led illuminates the particles in a dark room. A photo-detector collects light. The measured signal is then proportional to the size and the quantity of particles in suspension.

Attention. Do not use this sensor to detect fumes from a fire.

source :

The DSM501 is capable of classifying and measuring airborne particles less than 1 micron (PM1.0) and 2.5 micrometres (PM2.5) in size.

Note. There are two models (A and B at the end of the designation). The two models are perfectly identical. It is the pitch of the connector that changes. 2mm for model A and 2.5mm for B.

Principle of communication with the Arduino / ESP8266

The DSM501 does not send its measurement directly. It uses the PWM system. It will therefore be necessary to measure the ratio between the time spent in the high state (+ 4.5V) and the time spent in the low state (0V). Then, thanks to this curve, it is possible to determine the quantity of particles in the air.

source :

Can I use the DSM501 on an ESP8266?

Some of you will certainly yell at the 4.5V outputs of the sensors plugged into the ESP8266. Theoretically, the inputs of the ESP8266 must not exceed 3.3V. This is perfectly correct, but the ESP8266 seems to tolerate a voltage overrun if the intensity remains low according to this study published by Digital Me. One risks especially to deteriorate its ESP by directly plug the + 5V on terminal 3, 3V or a GPIO output by mistake.

Determination of particle concentration

Fortunately, Makers have done the job for us! Here is the function that retrieves the PWM signal and determine the ratio. Knowing the ratio, it is possible to deduce the concentration of particles in suspension in the air in mg/m3.

Sources :

Calculate the Air Quality Index (AQI)

The French Air Quality Index (AQI) or Air Quality Index (AIQ) in English is an indicator for determining an air quality level. Several pollutants are taken into account. (NO2), oxides of nitrogen (NOx), sulfur dioxide (SO2), lead (Pb), fine particles less than 10μm (PM10), less than 2.5μm Carbon (CO), Benzene (C6H6) and ozone (O3).

The big problem is that there is no international standard. In France, for example, the ATMO. The air quality is determined by an index ranging from 1 (very good) to 10 (dangerous). The ATMO is derived from the European system. In Europe, the Common Air Quality Index (CAQI) ranges from 0 to 100 (5 levels). In the USA and China, the AQI index has 6 levels ranging from 0 to 500 (or more).

To find the thresholds that correspond to your country, go to this Wikipedia page.

How to calculate the French ATMO index

In France, two indices have been developed to make air quality more visible. Everything is explained in detail on this page Wikipedia:

  • The ATMO index for agglomerations with populations exceeding 100,000. It is the maximum threshold of four pollutants. The index varies from 1 to 10.
  • The IQA index for agglomerations of less than 100,000 inhabitants. It is a simplified index, which can be based on the measurement of a smaller number of pollutants (from 1 to 3). According to Article 4 of the French decree JORF No 274 of 25 November 2004, the simplified air quality index (IQA / AQI) is equal to the largest of the sub-indices of the polluting substances actually measured in the Geographical area. The index includes 6 levels (very good, good, average, mediocre, bad, dangerous).

To determine the AQI, we need only have at least one measure. If we have several sensors at our disposal, it will be the worst sub-index that will be used as an IQA index. The thresholds are imposed by Directive 2008/50/EC of 21 May 2008.

This summary table (taken from the Wikipedia article) makes it possible to determine the ATMO index. In the absence of thresholds for PM2.5, I used those of England, very close to European levels.

For example, if a PM10 = 15.5 is found, the simplified ATMO (AQI) will be 3. If there are several measures, the worst index (the highest score) becomes the ATMO.

ATMO index O3

Hourly av.


Hourly av.


Hourly av.


Daily av.


Daily av.

1 0 –  29 0 –  39 0 à  29  0 à 11 0 à 6 Très bon
2 30 –  54 40 – 79 30 à 54 12 à 23 7 à 13 Très bon
3 55 –  79 80 – 119 55 à 84 24 à 35 14 à 20 Bon
4 80 – 104 120 – 159 85 à 109 36 à 41 21 à 27 Bon
5 105 – 129 160 – 199 110 à 134 42 à 47 28 à 34 Moyen
6 130 – 149 200 à 249 135 à 164 48 à 53 35 à 41 Médiocre
7 150 – 179 250 à 299 165 à 199 54 à 58 42 à 49 Médiocre
8 180 – 209 300 à 399 200 à 274 59 à 64 50 à 64 Mauvais
9 210 – 239 400 à 499 275 à 399 65 à 69 65 à 79 Mauvais
10 ≥ 240 ≥ 500 ≥ 400 > 70 ≥ 80 Très mauvais

How to determine the European CAQI index (also called Citeair)

The calculation is similar to the French ATMO. It is obtained using the following grid published on the website At a minimum, the measurement should last 1 hour (PM10 or PM2.5).

caqi europe common air quality index grid

Source :

How to calculate AQI in China and the USA

China and the US have the same calculation system. The level of air quality has 6 levels (good, moderate, mediocre, bad for health, very bad for health, dangerous). The threshold therefore ranges from 0 to 500 (or more) instead of going from 1 to 10 in Europe (ATMO). It is very often the method of calculation that one finds in the examples of codes Arduino. There is also an online calculator here.

Air Quality Index (AQI) Values Levels of Health Concern Colors
0 to 50 Good Green
51 to 100 Moderate Yellow
101 to 150 Unhealthy for Sensitive Groups Orange
151 to 200 Unhealthy Red
201 to 300 Very Unhealthy Purple
301 to 500 Hazardous Maroon

To calculate the threshold, use this formula.

O3 (ppb) O3 (ppb) PM2.5 (µg/m3) PM10 (µg/m3) CO (ppm) SO2 (ppb) NO2 (ppb) AQI AQI
ClowChigh (avg) ClowChigh (avg) ClowChigh (avg) ClowChigh (avg) ClowChigh (avg) ClowChigh (avg) ClowChigh (avg) IlowIhigh Categorie
0-54 (8-hr) 0.0-12.0 (24-hr) 0-54 (24-hr) 0.0-4.4 (8-hr) 0-35 (1-hr) 0-53 (1-hr) 0-50 Good
55-70 (8-hr) 12.1-35.4 (24-hr) 55-154 (24-hr) 4.5-9.4 (8-hr) 36-75 (1-hr) 54-100 (1-hr) 51-100 Moderate
71-85 (8-hr) 125-164 (1-hr) 35.5-55.4 (24-hr) 155-254 (24-hr) 9.5-12.4 (8-hr) 76-185 (1-hr) 101-360 (1-hr) 101-150 Unhealthy for Sensitive Groups
86-105 (8-hr) 165-204 (1-hr) 55.5-150.4 (24-hr) 255-354 (24-hr) 12.5-15.4 (8-hr) 186-304 (1-hr) 361-649 (1-hr) 151-200 Unhealthy
106-200 (8-hr) 205-404 (1-hr) 150.5-250.4 (24-hr) 355-424 (24-hr) 15.5-30.4 (8-hr) 305-604 (24-hr) 650-1249 (1-hr) 201-300 Very Unhealthy
405-504 (1-hr) 250.5-350.4 (24-hr) 425-504 (24-hr) 30.5-40.4 (8-hr) 605-804 (24-hr) 1250-1649 (1-hr) 301-400 Hazardous
505-604 (1-hr) 350.5-500.4 (24-hr) 505-604 (24-hr) 40.5-50.4 (8-hr) 805-1004 (24-hr) 1650-2049 (1-hr) 401-500


Connect the DSM501 to an Arduino or ESP8266 using the following marking

DSM501 Pin Coolor Signification
2 Yellow Vout2 (PM1.0)
3 White Vcc (+5V Arduino or ESP8266)
4 Red Vout1 (MP2.5)
5 Black GND


Source :

Arduino Code / ESP8266 for the DSM501

It is therefore impossible to propose a method of universal calculation. You will need to adapt the Arduino code to your country. Here is a work base that already calculates the French ATMO, the CAQI European and the American and Chinese AQI. The source code will be published on GitHub to allow each one to propose the calculation method corresponding to its country sound.

Note. The sensor requires a pre-heating of 60 seconds before the first measurement can be performed.

It is therefore necessary to carry out a measure long enough to be able to estimate correctly the AQI. You can change the measurement time using the variable sampletime_ms (in milliseconds). The measurement is then extrapolated to 24 hours. The longer the measurement time, the better the estimate of the AQI index. You will need to be patient at startup.

You can now track the level of fine particulate pollution at your home. We will see in the next tutorials how to add other sensors to constitute a true monitoring station of air quality 100% DIY!

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

  • Tomasz Wostal

    Good job mate 🙂 Thanks!

    • Thank you very much Tomasz. I hope the code has been useful for your project. Do not hesitate to share your experience with us. See you soon

  • Ibnu Adi Perdana

    firstly, i want say thank you very much cause i’ve tired to search reference this sensor. 😀
    result data from this system already compared with the standard tool for measurement pm10/2.5?

    i hope you can reply this soon 😀

    • Hello Ibnu and thank you very much. I’m sorry but I do not have any lab equipment that allows me to check the validity of the measurements. See you soon.

      • Ibnu Adi Perdana

        me too, I don’t have any lab equipment. But, base on the calculation in the program, how much error do you think if compare with lab equipment? Is it close to real value?

        • I can only refer to the technical documentation to give you an answer. Yes it is a good sensor. I think we should rather consider the value as an indicator of air quality (very bad, bad, average, good, very good). I have a doubt about the PM1 value that varies a lot too much. For the measurement to be correct, it is necessary to mix the air with a small fan for example. Do not measure during air renewal. See you soon.

          • Ibnu Adi Perdana

            long time no see 😀
            how do you test this tool to detect pm10?

          • I’m sorry but I did not understand your problem. You can tell me a little more. thank you very much

          • Ibnu Adi Perdana

            /sorry about my bad english , have no WA ?

            i mean, how to use this sensor? if lm 35 temperature sensor, we use to detect the temperatur in the somewhere

  • Ang Xian Jia

    Why am i getting strange output? I just copy the code into Arduino and change the pin to 9 and 10.

  • Ang Xian Jia

    1) How can i shorten the measurement total time? I want to get a quick result of AQI.
    2) Will the AQI result print on the serial monitor of Arduino IDE?

  • earlthesquirrel

    Question — For US/China (Lines 86 and 87) you call getAQI both times with a sensor value of 0. I think on 87 you meant for the value to be 1. Correct?

  • Sergey S

    First of all, thanks for great article and sample of code. If I understand correctly, DSM501A can detect dust particles of PM 1.0 (1 μm) and PM 2.5 (2.5 μm), it can’t detect PM 10 (10 μm). But you use sensor results for PM 1.0 in air quality calculations for PM 10. Is it correct or wrong?

DIY Projects