[尼克的robot]实做arduino pm2.5感测器GP2Y1010AU0F 侦测空气悬浮微粒污染 伫立的一棵树
[尼克的robot]实做arduino pm2.5感测器 GP2Y1010AU0F 侦测空气悬浮微粒污染
底下是程式的部分
/*
尼克的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);
}
程式上传后就可以开启序列埠观看数值啰
另外尼克也有遇到很多的问题
像是有时候感应器测值会变负的
在没有接任何其他的模组情况下
这可能是接线的问题
尼克直接把线焊死后就没这个问题了
另外如果有接其他的模组
就很容易发发冲突的问题
尼克还没有时间找出问题所在