论坛» 综合技术» 测试测量

【DIY】ESP8266 arduino开发的一款150元内激光PM2.5检测仪(带WIFI功能)【附源码】

菜鸟
2015-09-15 12:55 1楼

DIY激光PM2.5检测仪

ESP8266 arduino开发的一款激光PM2.5检测仪

看到网上做的pm2.5检测仪最多的是使用夏普的传感器的,但是夏普传感器的稳定性低,目前最准确的还是激光的传感器,所以做这个试试;

现在已经可以通过手机wifi连接并显示pm2.5的值(根据数值分rgb三种颜色显示);

此产品软硬件完全开源,并且后续会持续更新,争取做一个完善的空气质量检测仪;

菜鸟
2015-09-15 14:42 2楼

元件:
ESP8266 01 模块,批量<10元
SDS011/SDS018/SDS021 激光PM2.5传感器 批量<100元
USB转TTL模块3-10元
导线若干
方便刷机用的开关一个(可不用)

菜鸟
2015-09-15 14:43 3楼
连线: USB2TTLESP8266之间

ESP8266

USB2TTL

备注

VCC

3.3V

GND

GND

CH_PD

3.3V

连线之间添加20-100欧的电阻,以免电压不匹配

GPIO0

GND

连线之间添加开关,用于刷机和运行固件状态切换。

GPIO0GND为刷机状态;

GPIO0悬空为正常运行状态;

RX

TX

TX

RX

ESP8266SDS011/SDS018/SDS021之间

ESP8266

SDS011/SDS018/SDS021

备注

RXD

TXD

连线之间添加20-100欧的电阻,以免电压不匹配

GND

GND

USB2TTL SDS011/SDS018/SDS021之间

SDS011/SDS018/SDS021

USB2TTL

备注

5V

5V

GND

GND

菜鸟
2015-09-15 14:44 4楼
软件开发环境 下载

简单方式:

http://share.weiyun.com/dfd9763e10370ec584b635e1f06e3bbf

下载文件Arduino_ESP8266_IDE_1.0(内置编译器及烧写功能).rar

复杂方式:

安装arduino

下载Arduino 1.6.5

https://www.arduino.cc/en/main/software

打开文件-首选项窗口

Additional Board Manager URLs里输入 :

http://arduino.esp8266.com/stable/package_esp8266com_index.json

可以通过输入逗号 输入多个网址;

从工具-板子-板子管理:选择ESP8266板并安装;

配置

如果wifi模块是01~12的应选择NodeMCU 0.9,如下图所示:

然后,设置CPU Frequency80MHzUpload Speed115200,端口选择wifi模块与电脑连接分配的端口(如COM1),编程器不用选择,IDE已经默认设置好的,这个比较适合懒人,呵呵!

菜鸟
2015-09-15 14:45 5楼
代码
/* Create a WiFi access point and provide a web server for pm2.5 on it. */ #include  #include  #include  /* Set these to your desired credentials. */ const char *ssid = "AirMonitor"; const char *password = "inovafitness"; ESP8266WebServer server(80); // this is a demo for Arduino PM2.5 sensor test // PM2.5 sensor is from www.inovafitness.com SDS011 unsigned int Pm25 = 0;//used for result pm2.5 unsigned int Pm10 = 0;//used for result pm10 unsigned char Pm25IsNew = 0;//show if pm25 is refreshed void ProcessSerialData() { uint8_t mData = 0; uint8_t i = 0; uint8_t mPkt[10] = {0}; uint8_t mCheck = 0; while (Serial.available() > 0) { // from www.inovafitness.com // packet format: AA C0 PM25_Low PM25_High PM10_Low PM10_High 0 0 CRC AB mData = Serial.read(); delay(2); if(mData == 0xAA)//head1 ok { delay(400);//wait until packet is received mPkt[0] = mData; mData = Serial.read(); if(mData == 0xc0)//head2 ok { mPkt[1] = mData; mCheck = 0; for(i=0;i < 6;i++)//data recv and crc calc { mPkt[i+2] = Serial.read(); delay(2); mCheck += mPkt[i+2]; } mPkt[8] = Serial.read(); delay(1); mPkt[9] = Serial.read(); if(mCheck == mPkt[8])//crc ok { Serial.flush(); //Serial.write(mPkt,10); Pm25 = (uint16_t)mPkt[2] | (uint16_t)(mPkt[3]<<8); Pm10 = (uint16_t)mPkt[4] | (uint16_t)(mPkt[5]<<8); if(Pm25 > 9999) Pm25 = 9999; if(Pm10 > 9999) Pm10 = 9999; //get one good packet Pm25IsNew = 1; return; } } } } } /* Just a little test message. Go to http://192.168.4.1 in a web browser * connected to this access point to see it. */ void handleRoot() { char pm25_str[100]; char *pm25_format_red = "

Pm2.5=%d.%d

"; char *pm25_format_green = "

Pm2.5=%d.%d

"; char *pm25_format_blue = "

Pm2.5=%d.%d

"; if (Pm25<150)//15.0 sprintf(pm25_str,pm25_format_green, Pm25/10,Pm25%10); else if (Pm25<500)//pm2.5<50.0 sprintf(pm25_str,pm25_format_blue, Pm25/10,Pm25%10); else sprintf(pm25_str,pm25_format_red, Pm25/10,Pm25%10); server.send(200, "text/html", pm25_str); } void setup() { delay(1000); Serial.begin(9600); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); delay(500); delay(500); //while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("done"); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); ProcessSerialData(); }

菜鸟
2015-09-15 14:46 6楼
固件刷机
菜鸟
2015-09-15 14:47 7楼
成品图
菜鸟
2015-09-15 14:47 8楼
运行

使用手机或笔记本等有wifi的设备,连接WIFI AP名称:AirMonitor,密码:inovafitness

连接后,访问192.168.4.1,如下:

菜鸟
2016-02-04 04:12 9楼
学习了!非常感谢啊!
共9条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]