DIY 激光PM2.5检测仪
ESP8266 arduino开发的一款激光PM2.5检测仪
看到网上做的pm2.5检测仪最多的是使用夏普的传感器的,但是夏普传感器的稳定性低,目前最准确的还是激光的传感器,所以做这个试试;
现在已经可以通过手机wifi连接并显示pm2.5的值(根据数值分rgb三种颜色显示);
此产品软硬件完全开源,并且后续会持续更新,争取做一个完善的空气质量检测仪;
DIY 激光PM2.5检测仪
ESP8266 arduino开发的一款激光PM2.5检测仪
看到网上做的pm2.5检测仪最多的是使用夏普的传感器的,但是夏普传感器的稳定性低,目前最准确的还是激光的传感器,所以做这个试试;
现在已经可以通过手机wifi连接并显示pm2.5的值(根据数值分rgb三种颜色显示);
此产品软硬件完全开源,并且后续会持续更新,争取做一个完善的空气质量检测仪;
元件:
ESP8266 01 模块,批量<10元
SDS011/SDS018/SDS021 激光PM2.5传感器 批量<100元
USB转TTL模块3-10元
导线若干
方便刷机用的开关一个(可不用)
ESP8266 |
USB2TTL |
备注 |
VCC |
3.3V |
|
GND |
GND |
|
CH_PD |
3.3V |
连线之间添加20-100欧的电阻,以免电压不匹配 |
GPIO0 |
GND |
连线之间添加开关,用于刷机和运行固件状态切换。 GPIO0接GND为刷机状态; GPIO0悬空为正常运行状态; |
RX |
TX |
|
TX |
RX |
|
ESP8266和SDS011/SDS018/SDS021之间
ESP8266 |
SDS011/SDS018/SDS021 |
备注 |
RXD |
TXD |
连线之间添加20-100欧的电阻,以免电压不匹配 |
GND |
GND |
|
SDS011/SDS018/SDS021 |
USB2TTL |
备注 |
5V |
5V |
|
GND |
GND |
|
简单方式:
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 Frequency为80MHz,Upload Speed为115200,端口选择wifi模块与电脑连接分配的端口(如COM1),编程器不用选择,IDE已经默认设置好的,这个比较适合懒人,呵呵!
/* Create a WiFi access point and provide a web server for pm2.5 on it. */ #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> /* 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 = "<head><meta http-equiv=\"refresh\" content=\"5\"></head><h1>Pm2.5=<font color=\"red\">%d.%d</font></h1>"; char *pm25_format_green = "<head><meta http-equiv=\"refresh\" content=\"5\"></head><h1>Pm2.5=<font color=\"green\">%d.%d</font></h1>"; char *pm25_format_blue = "<head><meta http-equiv=\"refresh\" content=\"5\"></head><h1>Pm2.5=<font color=\"blue\">%d.%d</font></h1>"; 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(); }
使用手机或笔记本等有wifi的设备,连接WIFI AP 名称:“AirMonitor”,密码:”inovafitness”
连接后,访问192.168.4.1,如下:
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |