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 = 非常好
排线位置:
不接电容电阻接线示意图:
注意:添加一个150ohm的电阻和一个220uF的电容,接线如下图: Sensor Pin Arduino Pin
1 Vled –> 5V (150ohm resistor)
2 LED-GND –> GND
3 LED –> Digital pin 2
4 S-GND –> GND
5 Vo –> Analog pin 0
6 Vcc –> 5V
LED引脚必须调节成1ms的周期。
LED似乎使用的是PNP晶体管来通电,LED引脚必须接收一个较低的电压。