查看夏普 GP2Y1010AU0F 灰尘传感器的源代码
←
夏普 GP2Y1010AU0F 灰尘传感器
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== 程序== <source lang=cpp> /* Interface to Sharp GP2Y1010AU0F Particle Sensor Program by Christopher Nafis Written April 2012 http://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf http://sensorapp.net/?p=479 Sharp pin 1 (V-LED) => 5V (connected to 150ohm resister) Sharp pin 2 (LED-GND) => Arduino GND pin Sharp pin 3 (LED) => Arduino pin 4 Sharp pin 4 (S-GND) => Arduino GND pin Sharp pin 5 (Vo) => Arduino A4 pin Sharp pin 6 (Vcc) => 5V */ #include <stdlib.h> long lastConnectionTime = 0; // last time you update to the server, in milliseconds const int postingInterval = 10000; // delay between two updates int dustPin = 4; int ledPower = 4; int delayTime = 280; int delayTime2 = 40; float offTime = 9680; int dustVal = 0; int i = 0; float ppm = 0; char s[32]; float voltage = 0; float dustdensity = 0; float ppmpercf = 0; void setup(){ Serial.begin(9600); pinMode(ledPower,OUTPUT); delay(1000); i = 0; ppm =0; } void loop(){ i = i + 1; digitalWrite(ledPower,LOW); // power on the LED delayMicroseconds(delayTime); dustVal = analogRead(dustPin); // read the dust value ppm = ppm + dustVal; delayMicroseconds(delayTime2); digitalWrite(ledPower,HIGH); // turn the LED off delayMicroseconds(offTime); if((millis() - lastConnectionTime > postingInterval)) { voltage = ppm/i*0.0049; dustdensity = 0.17*voltage-0.1; ppmpercf = (voltage-0.0256)*120000; if (ppmpercf < 0) ppmpercf = 0; if (dustdensity < 0 ) dustdensity = 0; if (dustdensity > 0.5) dustdensity = 0.5; String dataString = ""; dataString += dtostrf(voltage, 9, 4, s); dataString += ","; dataString += dtostrf(dustdensity, 5, 2, s); dataString += ","; dataString += dtostrf(ppmpercf, 8, 0, s); i=0; ppm=0; Serial.println(dataString); lastConnectionTime = millis(); } delay(3000); } </source> <br><br>
返回到
夏普 GP2Y1010AU0F 灰尘传感器
。
个人工具
3.142.95.121
该IP地址的讨论
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面