这代码一般都是复制过来,在小改下就行了

代码如下:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET); #define LOGO16_GLCD_HEIGHT 16 //定义显示高度
#define LOGO16_GLCD_WIDTH 16 //定义显示宽度 int measurePin = ; //Connect dust sensor to Arduino A0 pin
int ledPower = ; //Connect 3 led driver pins of dust sensor to Arduino D2
int samplingTime = ;
int deltaTime = ;
int sleepTime = ; int dustVal=;
int i=;
float ppm=;
char s[];
float voltage=;
float dustdensity=;
float ppmpercf=; void setup(){
Serial.begin();
pinMode(ledPower,OUTPUT);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
i=;
ppm=;
display.clearDisplay();
}
void loop(){
i=i+;
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime);
dustVal = analogRead(measurePin); // read the dust value
ppm=ppm+dustVal;
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime); voltage=ppm/i*0.0049;
dustdensity=0.17*voltage-0.1;
ppmpercf=(voltage-0.0256)*;
if(ppmpercf<) ppmpercf=; if(dustdensity<) dustdensity=; if(dustdensity>0.5)
dustdensity=0.5;
String dataString="";
dataString+=dtostrf(voltage,,,s);
dataString+="PM2.5 ---> ";
dustdensity = dustdensity*;
dataString+=dtostrf(dustdensity,,,s);
dataString+=" -----> ";
dataString+=dtostrf(ppmpercf,,,s);
i=;
ppm=;
Serial.println(dustdensity);
Serial.println(dataString);
display.clearDisplay();
display.setCursor(,);
display.setTextSize(); //设置字体大小
display.setTextColor(WHITE); //设置字体白色
display.print("dustDensity:");
display.print(dataString); //输出字符
display.display(); //显示以上 delay();
}

模块:

OLED12864显示屏:

模块针脚        Arduino针脚

VCC     ---->   3.3V

GND    ---->    GND

SCL     ---->    A5

SDA    ---->    A4

夏普灰尘传感器GP2Y10:

Arduino显示PM2.5的更多相关文章

  1. 用Arduino显示颜色序列(u8g2,OLED)

    目录 用Arduino显示颜色序列(u8g2,OLED) 用Arduino显示颜色序列(u8g2,OLED) 提前祝大家新年快乐! 主控:Arduino Mega 2560 硬件:126×64 OLE ...

  2. 吴裕雄--天生自然python学习笔记:python爬虫PM2.5 实时监测显示器

    PM2.5 对人体的健康影响很大,所以空气中的 PM2.5 实时信息受到越来越多的关注. Python 的 Pandas 套件不但可以自动读取网页中的表格 数据 , 还可对数据进行修改.排序等处理,也 ...

  3. 吴裕雄 python 爬虫(2)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com' html = requests.get(url) ...

  4. 吴裕雄 实战PYTHON编程(8)

    import pandas as pd df = pd.DataFrame( {"林大明":[65,92,78,83,70], "陈聪明":[90,72,76, ...

  5. 吴裕雄 实战python编程(3)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp ...

  6. Arduino-串口函数Serial

    串口是Arduino与其它设备进行通信的接口,我们需要很好的掌握它的使用.Arduino串口使用相关的函数共有10个(随着版本的升级,新版本加入了更多,具体请参见官网:http://www.ardui ...

  7. 在web浏览器上显示室内温度(nodeJs+arduino+socket.io)

    上次的nodejs操作arduino入门篇中实现了如何连接arduino.这次我们来实现通过arduino测量室内温度并在浏览器上显示出来. [所需材料] 硬件:LM35温度传感器,arduino u ...

  8. Arduino 开源库 u8glib2 之 图标显示【原创】

    Arduino 开源库 u8glib2 研究之 图标显示                -----------------关于drawXBM drawXBMP函数使用的研究 因为心血来潮,近来想做一个 ...

  9. PMS5003ST+Arduino Nano OLED屏显示

    整合OLED显示和PMS5003报数 #include <Arduino.h> #include <pms.h> /////////////////////////////// ...

随机推荐

  1. Spring Batch 体系结构

    Spring Batch 设计的时候充分考虑了可扩展性和各类终端用户. 下图显示了 Spring Batch 的架构层次示意图,这种架构层次为终端用户开发者提供了很好的扩展性与易用性. 上图显示的是 ...

  2. 电脑用U盘启动

    除了根据提示按DEL或者F2进入到BIOS界面更改设置之外. 还可以在开机时按F8或F12进入到引导界面,可直接选择USB. 当把登录用户登录,其他用户都被禁用时,电脑登不进去.要制作启动U盘,进入到 ...

  3. textarea点击蓝色背景,黄色条,input点击黄色条,如何去掉?

    textarea:focus{ background: #ffff outline:none; } input:focus{ oulilne:none; }

  4. 跨域和jsonp的原理

    什么是跨域? 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对JavaScript施加的安全限制. 所谓同源是指,域名,协议,端口均相同,不明白没关系,举个栗子: h ...

  5. grid 操作实例

    1.下载selenium server 地址http://www.seleniumhq.org/download 2.这里以2.44.0.jar为例+windows 平台+在一台主机上运行 3.cmd ...

  6. Oracle11g温习-第十三章:索引

    2013年4月27日 星期六 10:46 1.索引(Index)的功能:对记录进行排序,加快表的查询速度  2.索引的分类  1)B-tree 索引(默认) a.在一个大表上 b.建立在重复值比较少的 ...

  7. Leetcode 863. 二叉树中所有距离为 K 的结点

    863. 二叉树中所有距离为 K 的结点  显示英文描述 我的提交返回竞赛   用户通过次数39 用户尝试次数59 通过次数39 提交次数174 题目难度Medium 给定一个二叉树(具有根结点 ro ...

  8. [Codeforces Round #340 (Div. 2)]

    [Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...

  9. 用javascript切换bootstrap的tab

    html: <button class="tabContainer" data-toggle="tab" href="#note" i ...

  10. Django之REST framework源码分析

    前言: Django REST framework,是1个基于Django搭建 REST风格API的框架: 1.什么是API呢? API就是访问即可获取数据的url地址,下面是一个最简单的 Djang ...