General

How to make an air quality monitor?

userHead Account cancelled 2017-08-01 15:50:37 11547 Views0 Replies
In recent years, the atmospheric pollution becomes severe. It’s time for an ingenious maker to make an air quality monitor. A simply air quality monitor can be constructed soon using an air quality monitoring sensor matched up with Arduino controller and expansion board. You can also scientifically and objectively know the quality of air that you breathe constantly even without those specialized monitoring devices and experts’ reports.

See the photos below. It is urgent to make a PM 2.5 monitor!
Image

Image

Image

Component:
Sharp GP2Y1010AU0F Compact optical Dust Sensor *1
DFRduino UNO R3 (same as Arduino UNO R3) *1
Gravity: IO Expansion Shield for Arduino V7.1 *1
Dust Sensor Adapter *1
USB Cable A-B for Arduino Uno/Mega *1

Hardware connection:
1.Insert the I/O expansion board on arduino UNO
2. Connect the dust sensor with the adapter plate through the Dupont line.
3. Mark two interfaces on the adapter plate with D and A
D --> digital interface 2
A --> analog interface 0
As photo:
Image

Simply plug in several lines to complete the connection.
Firstly, we shall generally know the dust sensor based on the codes!
The figure below shows the internal structure diagram and hardware description of dust sensor:

Image
Internal Structure Diagram of Dust Sensor
At the transmitting terminal, we need to drive an infrared LED, i.e., pin 3 above, corresponding to the ledPower defined in the program. We can also see the output corresponding to the pin 5 above. The analog quantity is outputted, corresponding to measurePin in the program.
So, how can we get the desired value?
The following screenshot is from datasheet. You may see the output voltage of dust sensor is nearly linear. dustDensity = 0.17 * calcVoltage -0.1; this formula is approximately transformed from the curve (from ChrisNafis). The dustDensity here refers to the dust density value in unit of mg/m3. calcVoltage refers to the output voltage value.
Image

We all know that, for the output voltage of 0- 5V, the corresponding UNO analog interface reads 0~1023. calcVoltage= voMeasured * (5.0 / 1024.0); this formula means the voltage value converted by analog value. voMeasured refers to the output quantity of analog interface.
The calculation is based on time
According to the datasheet, i.e., the second figure below, we need to start the internal LED and wait for 280 µs before reading the output value. The first figure shows the whole pulse duration is 320 us. Therefore, we need to wait for another 40 µs before switching off the LED.
Image

Image

The program and working principle of dust sensor are briefly introduced above.
In case of no adapter plate, see the figure below.
Image

We need to externally connect a 150 Ohm resistor and connect a 220uF capacitor in parallel at pin 1. That’s why we use adapter plate. The line connection becomes easy and stability is also increased.
The pin position is as shown below. If you need connect a resistor and a capacitor externally, please check following contents.
Image
Corresponding Arduino pin of dust sensor:
(8.71 KiB) Downloaded 5010 times
Image

Image

Connect the lines as shown in the figure. After connection, download the sample codes above.
CODE:
Code: Select all
int measurePin = 0;  // 连接模拟口0
int ledPower = 2;    // 连接数字口2
  
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
  
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
  
void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}
  
void loop(){
  digitalWrite(ledPower,LOW);       //开启内部LED
  delayMicroseconds(samplingTime);  // 开启LED后的280us的等待时间
  
  voMeasured = analogRead(measurePin);   // 读取模拟值
  
  delayMicroseconds(deltaTime);        //  40us等待时间
  digitalWrite(ledPower,HIGH);         // 关闭LED
  delayMicroseconds(sleepTime);
  
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);   //将模拟值转换为电压值
  
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
dustDensity = 0.17 * calcVoltage - 0.1;
  
  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);
  
  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);
  
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity); // unit: mg/m3
  
  delay(1000);
}
icon 111.png Download(0)