
GP2Y1010AU0F子產品
本教程使用的是GP2Y1010AU0F子產品,某寶上定價38軟妹币。
該子產品具有非常低的電流消耗(最大20mA,11毫安典型值),最高7VDC供電。傳感器的輸出是一個模拟電壓成正比的測量粉塵密度,具有0.5V/0.1mg/m3的靈敏度。
準備材料
- Arduino UNO *1
- GP2Y1010AU0F子產品 *1
- 150歐電阻 *1
- 220uF電解電容 *1
- 面包闆 *1
- 跳線 若幹
接線
GP2Y1010AU0F | Arduino | |
---|---|---|
1 | 150歐電阻 | 5V |
220uF電解電容 | GND | |
2 | -> | |
3 | ||
4 | ||
5 | A0 | |
6 |
示例程式
int dustPin=0;
float dustVal=0;
int ledPower=2;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
pinMode(dustPin, INPUT);
}
void loop(){
// ledPower is any digital pin on the arduino connected to Pin 3 on the sensor
digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
delay(1000);
if (dustVal>36.455)
Serial.println((float(dustVal/1024)-0.0356)*120000*0.035);
}
附:測試得到的資料和空氣品質對照:
3000 + = 很差
1050-3000 = 差
300-1050 = 一般
150-300 = 好
75-150 = 很好
0-75 = 非常好