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

代码如下:

double Fahrenheit(double celsius)
{
return 1.8 * celsius + ;
} //摄氏温度度转化为华氏温度 double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度 // 露点(点在此温度时,空气饱和并产生露珠)
// 参考: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(, (11.344*(-/A0)))-) ;
SUM += 8.1328e-3 * (pow(,(-3.49149*(A0-)))-) ;
SUM += log10(1013.246);
double VP = pow(, SUM-) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
} // 快速计算露点,速度是5倍dewPoint()
// 参考: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/);
double Td = (b * temp) / (a - temp);
return Td;
}
static const unsigned char PROGMEM str_1[] =
{
0x00,0x08,0x43,0xFC,0x32,0x08,0x12,0x08,
0x83,0xF8,0x62,0x08,0x22,0x08,0x0B,0xF8,
0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,
0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x20,0x00,
};//温 static const unsigned char PROGMEM str_2[] =
{
0x01,0x00,0x00,0x84,0x3F,0xFE,0x22,0x20,
0x22,0x28,0x3F,0xFC,0x22,0x20,0x23,0xE0,
0x20,0x00,0x2F,0xF0,0x22,0x20,0x21,0x40,
0x20,0x80,0x43,0x60,0x8C,0x1E,0x30,0x04,
}; // 度 static const unsigned char PROGMEM str_3[] =
{
0x00,0x08,0x47,0xFC,0x34,0x08,0x14,0x08,
0x87,0xF8,0x64,0x08,0x24,0x08,0x0F,0xF8,
0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,
0x23,0x30,0x21,0x24,0x3F,0xFE,0x20,0x00,
}; //湿
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht11.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h> dht11 DHT11;
#define DHT11PIN 2
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET); #define LOGO16_GLCD_HEIGHT 16 //定义显示高度
#define LOGO16_GLCD_WIDTH 16 //定义显示宽度 #if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void printDateTime(DateTime dateTime);
//创建实例
RTC_DS1307 RTC; DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
uint8_t bell[] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
char data[];
char Str_year[], Str_month[], Str_date[], Str_DoW[], Str_hour[], Str_minute[], Str_second[];
String recivedStr="";//接收到的字符串
int recivedNum =;//接收到的字符个数
void setup() {
Serial.begin();
Wire.begin();
// 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) //OLED 的I2C位置
// init done display.clearDisplay();
//////////////// // Serial.println("Please enter the time: year[2]month[2]date[2]DoW[2]hour[2]minute[2]second[2]");
// Serial.println("example: 2014-12-3 Wednesday 14:15:15 enter:14120303141515");//1703072154
//英文字符显示
//display.setTextSize(1); //设置字体大小
//display.setTextColor(WHITE); //设置字体颜色白色
//display.setCursor(0,0); //设置字体的起始位置
//display.println(" zhongbest.com");//输出字符并换行
//display.display(); //把缓存的都显示
//初始化实时时钟
RTC.begin();
} void loop() {
int chk = DHT11.read(DHT11PIN); // Serial.print("Read sensor: ");
// switch (chk)
// {
// case DHTLIB_OK:
// Serial.println("OK");
// break;
// case DHTLIB_ERROR_CHECKSUM:
// Serial.println("Checksum error");
// break;
// case DHTLIB_ERROR_TIMEOUT:
// Serial.println("Time out error");
// break;
// default:
// Serial.println("Unknown error");
// break;
// }
display.clearDisplay();
//英文字符显示
display.setTextSize(); //设置字体大小
display.setTextColor(WHITE); //设置字体颜色白色
display.setCursor(,); //设置字体的起始位置 // display.print("Humidity(%):");
// display.println((float)DHT11.humidity, 2); // display.print("Temperature(oC):"); // display.print("Temperature(oF):");
// display.println(Fahrenheit(DHT11.temperature), 2);
//
// display.print("Temperature(K):");
// display.println(Kelvin(DHT11.temperature), 2);
//
// display.print("Dew Point(oC):");
// display.println(dewPoint(DHT11.temperature, DHT11.humidity));
//
// display.print("Dew PointFast(oC):");
// display.println(dewPointFast(DHT11.temperature, DHT11.humidity));
//中文字符显示
display.drawBitmap(, , str_1, , , ); //在坐标X:26 Y:16的位置显示中文字符中
display.drawBitmap(, , str_2, , , ); //在坐标X:42 Y:16的位置显示中文字符贝
display.setCursor(,); //设置字体的起始位置
display.setTextSize(); //设置字体大小
display.print(":");
display.println((float)DHT11.temperature, );
display.drawBitmap(, , str_3, , , ); //在坐标X:26 Y:16的位置显示中文字符中
display.drawBitmap(, , str_2, , , ); //在坐标X:42 Y:16的位置显示中文字符贝
display.setCursor(,); //设置字体的起始位置
display.setTextSize(); //设置字体大小
display.print(":");
display.println((float)DHT11.humidity, );
int val;
val=analogRead();
// Serial.println(val,DEC);
display.setCursor(,); //设置字体的起始位置
display.print("MQ-2: ");
display.println(val,DEC);
// display.setCursor(0,60);
display.print("-------------------");
DateTime now = RTC.now();
//通过串口传送当前的日期和时间
printDateTime(now); /////////////////////////////////////////////////////////// while(Serial.available() > )//读取字符串
{
recivedStr += char(Serial.read());
// delay(2);
recivedNum = recivedNum+;
}
if(recivedNum == )
{ //year[2]month[2]date[2]DoW[2]hour[2]minute[2]second[2]
String strtemp = "";
strtemp = recivedStr.substring(,);
int years = strtemp.toInt();
RTC.set(RTC_YEAR,years);//设置年 strtemp = recivedStr.substring(,);
int months = strtemp.toInt();
RTC.set(RTC_MONTH,months);//设置月 strtemp = recivedStr.substring(,);
int days = strtemp.toInt();
RTC.set(RTC_DAY,days);//设置日 strtemp = recivedStr.substring(,);
int hours = strtemp.toInt();
RTC.set(RTC_HOUR,hours);//设置小时 strtemp = recivedStr.substring(,);
int minutes = strtemp.toInt();
RTC.set(RTC_MINUTE,minutes);//设置分钟 strtemp = recivedStr.substring(,);
int seconds = strtemp.toInt();
RTC.set(RTC_SECOND,seconds);//设置秒
recivedNum = ;
}
display.display(); //把缓存的都显示
delay();
} void printDateTime(DateTime dateTime) {
//传送年份
display.setCursor(,); //设置字体的起始位置
display.print(dateTime.year(), DEC);
display.print('/');
//传送月份
display.print(dateTime.month(), DEC);
display.print('/');
//传送月份中的第几天
display.print(dateTime.day(), DEC);
display.print(' ');
//传送小时
display.print(dateTime.hour(), DEC);
display.print(':');
//传送分钟
display.print(dateTime.minute(), DEC);
display.print(':');
//传送秒
display.print(dateTime.second(), DEC);
display.display(); //把缓存的都显示
}

模块:

OLED12864显示屏:

模块针脚        Arduino针脚

VCC     ---->   3.3V

GND    ---->    GND

SCL     ---->    A5

SDA    ---->    A4

烟雾传感器MQ-2:

VCC     ---->    5V

GND    ---->    GND

A0       ---->    A0

温湿度传感器DHT11:

+       ------>   5V

OUT  ------>    2

-       ------>    GND

时钟模块DS1307:

SCL     ------->   A5

SDA    ------->   A4

VCC    ------->   5V

GND   ------->  GND

arduino使用oled显示时间MQ_2温湿度的更多相关文章

  1. PMS5003ST+Arduino Nano OLED屏显示

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

  2. Arduino——My-Clock项目 发布时间:2018-12-31

    技术:Arduino.光敏传感器.DHT11.DS1302.OLED显示屏   概述 项目My-Clock是一个环境监测时钟,接入光敏传感器和温湿度传感器监测环境信息,加入DS1302模块用于获取时间 ...

  3. ESP8266开发之旅 应用篇② OLED显示天气屏

    1.前言     这一篇,博主将教大家怎么去实现一个简易版本的天气助手.     先来一个博主已经实现功能的图片,如下: 1.1 知识储备     本篇需要用到以下知识点: 运用到ArduinoJso ...

  4. 致敬学长!J20航模遥控器开源项目计划【开局篇】 | 先做一个开机界面 | MATLAB图像二值化 | Img2Lcd图片取模 | OLED显示图片

    我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/C ...

  5. 灵感手环第一步——0.96寸OLED显示实验

    这算是我这个系列的第一篇博客吧.首先要解决的就是屏幕显示问题.我选择了目前新兴起的OLED显示模块. OLED(OrganicLightEmittingDiode),中文译作有机发光二极管,目前被广泛 ...

  6. MicroPython之TPYBoard v102开发板控制OLED显示中文

    转载请以链接形式注明文章来源,公众号:MicroPython玩家汇 0x00前言 之前看到一篇文章是关于TPYBoardv102控制OLED屏显示的,看到之后就想尝试一下使用OLED屏来显示中文.最近 ...

  7. MicroPython实例之TPYBoard开发板控制OLED显示中文

    0x00 前言 之前看到一篇文章是关于TPYBoard v102控制OLED屏显示的,看到之后就想尝试一下使用OLED屏来显示中文.最近利用空余时间搞定了这个实验,特此将实验过程及源码分享出来,方便以 ...

  8. 用STM32玩SR04(测距、串口显示、OLED显示)

    目录 用STM32玩SR04(测距.串口显示.OLED显示) 超声波模块使用 SR04初始化 SR04使用串口打印数据 SR04使用OLED来传输数据,并显示在OLED上 用STM32玩SR04(测距 ...

  9. [转] 使用反射机制控制Toast的显示时间

    大体上说就是利用toast的内部类TN 来控制show和hide ,这是一个反射机制 怎么控制toast的显示时间呢?这个就是通过tn类的show和hide的方法 http://blog.csdn.n ...

随机推荐

  1. Confluence 6 修改空间名字和标识

    希望修改空间名称: 在空间名称的边上,选择  图标. 输入新的空间名称,然后单击 保存(Save). 标识(Logo )- 修改空间的名称和标识. 重新组织(Reorder) - 拖动来从新组织快捷链 ...

  2. Confluence 6 设置其他页面为你空间的主页

    在任何时候,如果你希望某一个页面称为你空间的主页,你可以非常容易的从 编辑空间细节(Edit Space Details)标签页中进行修改. 希望编辑空间的细节: 进入空间后,然后从边栏的底部选择 空 ...

  3. python3 设置滚动条

    #!python3#coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.by import Byimpor ...

  4. python 线程 进程

    1.进程与线程优.缺点的比较总言:使用进程和线程的目的,提高执行效率. 进程: 优点:能利用机器的多核性能,同时进行多个操作. 缺点:需要耗费资源,重新开辟内存空间,耗内存. 线程: 优点:共享内存( ...

  5. Leetcode 124 *

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  6. 70. Climbing Stairs爬楼梯

    网址:https://leetcode.com/problems/climbing-stairs/ 其实就是斐波那契数列,没什么好说的. 注意使用3个变量,而不是数组,可以节约空间. class So ...

  7. centos命令行系列之centos查看磁盘空间大小

    df -h 扩展: 1.查看当前文件夹所有文件大小 du -sh 2.查看指定文件下所有文件大小 du -h /data/ 3.查看指定文件大小 du -h install.log 4.查指定文件夹大 ...

  8. [LeetCode] 104. Maximum Depth of Binary Tree ☆(二叉树的最大深度)

    描述 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l ...

  9. ActiveMQ 消息的重新投递

    正常情况下:consumer 消费完消息后,会发送"标准确认"给 broker,这个确认对象以 MessageAck 类表征: // 省略其他代码.类中定义了各种确认的类型 pub ...

  10. vue element-ui 通过v-for渲染的el-form-item组件,使用自带的表单验证

    HTML: <el-form ref="newTermDetail" :model="newTermDetail" class="auto_fo ...