[尼克的robot]实做arduino pm2.5感测器 GP2Y1010AU0F 侦测空气悬浮微粒污染

20190101_194814.jpg

GP2Y1010AU0F的原理是用LED光源去侦测空气中悬浮微粒
算是个粗略估计的方法,不会非常精准精确
不过优点就是成本相对雷射式感应器的便宜很多
但尼克用起来数值的相对变化正确性还是有的
 
 
底下就是今天所需的材料 : 
面包版 一块
UNO版 一块
pm2.5感测器 一颗
电容及电阻基本上你买的时候他就会附给你
如果没有的话需要自己准备
一颗 150欧姆的电阻
一颗 220uF的电容
 
接线的部分 :
感应器总共有六条线
由左至右分别是 白,蓝,绿,黄,黑,红
白的部分为方便观看尼克暂时用浅蓝代替
 
1321.png
 
这颗感应器比较要注意的地方是他的线比较多也比较细,所以剥皮的时候,尼克建议剥两倍的长度,然后再对折转一转,当然这样会变的很麻烦,不过不这样的话线很容易从面包板松脱
另外一种方法是剥皮完后直接用銲锡沾一沾

底下是程式的部分

/*

尼克的robot网址 :

https://kenny2019.pixnet.net/blog

*/

//测试得到的资料和空气品质对照:
//3000 + =很差
//1050-3000 =差
//300-1050 =一般
//150-300 =好
//75-150 =很好
//0-75 =非常好

int measurePin = 0; //右边第二条线的接脚
int ledPower = 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); // power on the LED
  delayMicroseconds(samplingTime);
  
  voMeasured = analogRead(measurePin); // read the dust value
  
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  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("原始信号值 (0-1023): ");
  Serial.print(voMeasured);
  
  Serial.print(" - 电压: ");
  Serial.print(calcVoltage);
  
  Serial.print(" - 灰尘密度: ");
  Serial.print(dustDensity * 1000); // 这里将数值呈现改成较常用的单位( ug/m3 )
  Serial.println(" ug/m3 ");
  delay(10000);
}


程式上传后就可以开启序列埠观看数值啰

另外尼克也有遇到很多的问题

像是有时候感应器测值会变负的

在没有接任何其他的模组情况下

这可能是接线的问题

尼克直接把线焊死后就没这个问题了

另外如果有接其他的模组

就很容易发发冲突的问题

尼克还没有时间找出问题所在

因此之后有其他的发现会再写一篇文章跟大家说
 
 
 
 
 
相关文章