5分钟搭建室内颗粒物测试系统-乐联网应用
本帖最后由 laoliu1982 于 2012-11-18 12:27 编辑前言:
参考内容是:
http://www.howmuchsnow.com/arduino/airquality/(感谢@友善的蜜蜂)
http://www.geek-workshop.com/thread-297-1-1.html
硬件:
1 Arduino UNO(必须)约50RMB
2 W5100(可选) 约85RMB
3 PPD42NS(必须) 约70RMB
现在市面上有三种廉价颗粒传感器:
GP2Y1010AU0F(约40RMB),DSM501A(约30RMB),PPD42NS(约70RMB)
为什么选择PPD42NS?上面第一个连接用的是PPD42NS,第二个连接用的是DSM501A。DSM501A与PPD42NS原理完全一致,连引脚顺序也一致(模块引脚间距不一样而已)。但是实际我们用DSM501A测试,效果不是很好。用PPD测试,感觉和标定用的dolos设备一致性比较好。sharp的GP2Y1010AU0F 由于需要外接电阻电容,就没进行测试。
DYLOS 与 PPD42NS的数据对比 http://open.lewei50.com/home/gatewaystatus/69选择“最近一周”看的比较明显。
平台:乐联网平台open.lewei50.com
arduino:连线
PPD42NS Pin 1 => Arduino GND
PPD42NS Pin 3 => Arduino 5VDC
PPD42NS Pin 4 => Arduino Digital Pin 8
程序1 :通过W5100 上传
/*
open.lewei50.comsensorclinet
*/
#include <SPI.h>
#include <Ethernet.h>
#define USERKEY "xxxxxx8845829a4f348acb720ed3" // replace your key here
// assign a MAC address for the ethernet controller.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
// initialize the library instance:
EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(216,52,233,121); // numeric IP for api.cosm.com
char server[] = "open.lewei50.com"; // name address for cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 30*1000; //delay between updates to cosm.com
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup() {
// start serial port:
Serial.begin(9600);
pinMode(8,INPUT);
starttime = millis();
// start the Ethernet connection with DHCP:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
for(;;)
;
}
else {
Serial.println("Ethernet configuration OK");
}
starttime = millis();
}
int x=0; //simulated sensor output
int sampling=1;
int transfering=0;
void loop() {
// read the analog sensor:
//int sensorReading = analogRead(A0);
// if there's incoming data from the net connection.
// send it out the serial port.This is for debugging
// purposes only:
if(1==sampling)
{
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
if ((millis()-starttime) > sampletime_ms)
{
ratio = lowpulseoccupancy/(sampletime_ms*10.0);// Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
//Serial.print(lowpulseoccupancy);
// Serial.print(",");
Serial.print(ratio);
Serial.print(",");
Serial.println(concentration);
lowpulseoccupancy = 0;
//initiate the http post
sampling=0;
transfering=1;
}
}
// http post begin
if(1==transfering)
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
//initiate the PPDS testing
transfering=0;
sampling=1;
starttime=millis();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
Serial.print("http post:");
Serial.println(concentration);
sendData(concentration);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
//Serial.println(lastConnected);
}
}
// this method makes a HTTP connection to the server:
void sendData(int thisData) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.print("POST /api/V1/gateway/Updatesensors/01 "); // 01代表01网关,如果是02网关这里换成02
client.println("HTTP/1.1");
client.print("userkey: ");
client.println(USERKEY);
client.println("Host: open.lewei50.com ");
client.print("Content-Length: ");
// calculate the length of the sensor reading in bytes:
// 8 bytes for "sensor1," + number of digits of the data:
int thisLength = 24 + getLength(thisData);
client.println(thisLength);
// last pieces of the HTTP PUT request:
//client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.println();
// here's the actual content of the PUT request:
// 这里的用p1,是因为用户在系统里面已经添加了一个传感器缩写叫p1的传感器 (在01网关下面)
client.print("[{\"Name\":\"p1\",\"Value\":");
client.print(thisData);
client.println("}]");
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
// This method calculates the number of digits in the
// sensor reading.Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:
int getLength(int someValue) {
// there's at least one byte:
int digits = 1;
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
while (dividend > 0) {
dividend = dividend /10;
digits++;
}
// return the number of digits:
return digits;
}
程序2:通过串口打印到电脑,电脑通过乐联网转发软件 上传。
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup() {
Serial.begin(9600);
pinMode(8,INPUT);
starttime = millis();
}
void loop() {
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
if ((millis()-starttime) > sampletime_ms)
{
ratio = lowpulseoccupancy/(sampletime_ms*10.0);// Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
//Serial.print(lowpulseoccupancy);
// Serial.print(",");
Serial.print(ratio);
Serial.print(",");
Serial.println(concentration);
lowpulseoccupancy = 0;
starttime = millis();
}
}
串口打印的数据通过“乐联网转发软件” 就可以完成数据的上传
乐联网转发软件
乐联网平台使用设置:
乐联网采用
用户-网关(具备地理属性)-传感器三级架构
每个用户可以有多个网关,每个网关可以带多个传感器。可以分别设置网关是否公开,传感器是否公开。首页的地图只显示公开的网关,点进去就可以看到该网关下面公开的传感器。
系统具体使用方法:http://open.lewei50.com/home/news/69
学习学习,交流一下 还有dolos,羡慕~~~~楼主厉害 ewx_boy 发表于 2012-11-18 21:13 static/image/common/back.gif
还有dolos,羡慕~~~~楼主厉害
正经300多刀呢。 颗粒物也来 了
这下高端了 颗粒物也来 了
这下高端了
总的来看PPD与dylos的一致性还是不错的,呆在北京有一个好处就是可以经历大范围的颗粒物浓度变化,完全免费就可以看到粗糙的标定结果。 laoliu1982 发表于 2012-11-19 18:17 static/image/common/back.gif
总的来看PPD与dylos的一致性还是不错的,呆在北京有一个好处就是可以经历大范围的颗粒物浓度变化,完全 ...
看这个精度还不错ing 从我们办公室这一个月测试的结果来看,北京空气质量真不是盖的。下面是一个月内/一周内 我们办公室测得的颗粒物含量。
采用的设备是dylos 设备。蓝色的是dylos测试数据在0-3000的比例(3000的定义是very poor)红色是大于3000的比例。尤其是最近一个星期,只有5%的时间,在very poor以下。
说明:测试数据仅代表我们办公室的情况,不代表室外空气质量。 DSM501A的效果能有多差?PPD的价格确实太贵了 :@鄙视LZ不理不睬不交流的行为,发消息也不回。忍心买了一个DSM501a,等了好几天终于到了,发现它的有效量程是2500到12500pcs之间,PPD42NS有效量程是0到8000pcs,我在北京的宿舍里测到的值在3000--10000pcs之间,用dsm也是可以的,如果室内空气比较干净的话(数浓度经常低于2500pcs),应该用ppd。另外传感器放的位置也是有讲究的,应该把有加热电阻的一段放在下方,出气孔朝上,不然侧得的数据不准,传感器周围的空气应该没有明显的流动 我用的是LZ的程度,但是我感觉这个程序有问题,测量时间没有精确控制到30000毫秒,因为要等最后一个低电平结束。这样测量值应该是偏大的,而且有可能误差很多,下个月有钱了再试一下ppd 低电平占空比会误差百分之零点几,修改的程序如下:int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long endtime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup() {
Serial.begin(9600);
pinMode(8,INPUT);
starttime = millis();
}
void loop() {
duration = pulseIn(pin, LOW);
lowpulseoccupancy += duration;
endtime = millis();
if ((endtime-starttime) > sampletime_ms)
{
ratio = (lowpulseoccupancy-endtime+starttime + sampletime_ms)/(sampletime_ms*10.0);// Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
//Serial.print(lowpulseoccupancy);
// Serial.print(",");
Serial.print(ratio);
Serial.print(",");
Serial.println(concentration);
Serial.println(endtime-starttime);
lowpulseoccupancy = 0;
starttime = millis();
}
} 蓝色星空 发表于 2013-2-23 22:50 static/image/common/back.gif
低电平占空比会误差百分之零点几,修改的程序如下:
貌似网站消息多了,没有提醒,刚发现有几条消息没看
给你提个意见,最好别问问题不回就抱怨,谁都没有义务必须要回复谁的问题。
程序是老外写的,我就是改了一下发到乐联网的平台上了。同样方式比较DSM和PPD,发现PPD多次平均以后还可以,DSM跳动太大没找到规律,也没仔细研究过。如果修改程序可以降低百分之零点几的跳动也挺好的。
ppd长时间测试的结果:我晚上给你发一个子账户,你可以登上去看,有大概春节一周的数据。比较两个ppd的传感器,竖着放的。
laoliu1982 发表于 2013-2-24 10:51 static/image/common/back.gif
貌似网站消息多了,没有提醒,刚发现有几条消息没看
给你提个意见,最好别问问题不回就抱怨,谁都没有 ...
抱歉,之前在考虑买哪一个传感器,但是找不到对比资料,你这里一句话带过但是没给出对比的数据,所以比较急。DSM确实会有较大跳动,但看到你帖子里的ppd的跳动也比较大。没有用过ppd,所以也不知道ppd能好多少。我用dsm 10次测量取平均跳动也不是很大,上下10%吧。您的数据在哪里?