硬件清单

Arduino NANO
1602LCD + PCF8574T模块
YL-47 DHT11模块

连线

1. 连接LCD: PCF8574T模块4pin(Gnd, Vcc, SDA i2c数据, SCL i2c时钟) 连接至Arduino接口 Gnd -> Gnd, Vcc -> Vcc, SDA -> A4, SDL -> A5
2. 连接YL-47 DHT11: Gnd -> Gnd, Vcc -> Vcc, Data-> D4

Library

除了1602需要的库以外, 需要安装两个自带的库:  DHT Sensor Library by Adafruit, Adafruit Unified Sensor

测试代码

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>#define DHTPIN 4
#define DHTTYPE DHT11// I2C地址, 一般为0x3F, 0x20或0x27
LiquidCrystal_I2C lcd(0x27,16,2);
// 初始化DHT
DHT dht(DHTPIN, DHTTYPE);void setup() {lcd.init();lcd.backlight(); // 打开背光Serial.begin(9600);dht.begin();lcd.setCursor(0,0); // line 0, pos 0lcd.print("Good Day!");lcd.setCursor(0,1); // line 1, pos 0lcd.print("H:     % T:");delay(1000);
}void loop() {// Reading temperature or humidity takes about 250 milliseconds!// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)float h = dht.readHumidity();// Read temperature as Celsius (the default)float t = dht.readTemperature();// Read temperature as Fahrenheit (isFahrenheit = true)float f = dht.readTemperature(true);// Check if any reads failed and exit early (to try again).if (isnan(h) || isnan(t) || isnan(f)) {Serial.println("Failed to read from DHT sensor!");return;}// Compute heat index in Fahrenheit (the default)float hif = dht.computeHeatIndex(f, h);// Compute heat index in Celsius (isFahreheit = false)float hic = dht.computeHeatIndex(t, h, false);Serial.print("Humidity: ");Serial.print(h);Serial.print(" %\t");Serial.print("Temperature: ");Serial.print(t);Serial.print(" *C ");Serial.print(f);Serial.print(" *F\t");Serial.print("Heat index: ");Serial.print(hic);Serial.print(" *C ");Serial.print(hif);Serial.println(" *F");lcd.setCursor(2,1); // line 1, pos 0
  lcd.print(h);lcd.setCursor(11,1); // line 1, pos 0
  lcd.print(t);delay(1000);
}

代码说明

1. DHT11启动到读取数据需要等待1~2秒
2. 温湿度的精度都为1, 没有小数部分
3. DHT库里面带了计算热指数的方法 computeHeatIndex(), 用于生成综合温湿度计算得到的热指数值

改进拼接字符串

改进后的代码, 注意: arduino里的sprintf只能格式化整数, 不能格式化浮点

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <DS3231.h>#define DHTPIN 4
#define DHTTYPE DHT11// I2C地址, 一般为0x3F, 0x20或0x27
LiquidCrystal_I2C lcd(0x27,16,2);
DHT dht(DHTPIN, DHTTYPE);
DS3231 Clock;
bool century=false;
bool h12;
bool PM;void setup() {lcd.init();//lcd.backlight(); // 打开背光Serial.begin(9600);dht.begin();lcd.setCursor(0,0); // line 0, pos 0lcd.print("Good Day Jessie~~");lcd.setCursor(0,1); // line 1, pos 0lcd.print("H:  % T:   T:");delay(1000);
}void loop() {char str[17];sprintf(str,"%02d-%02d %02d:%02d:%02d  ",Clock.getMonth(century),Clock.getDate(),Clock.getHour(h12, PM),Clock.getMinute(),Clock.getSecond());lcd.setCursor(0,0); // line 0, pos 0
  lcd.print(str);// Reading temperature or humidity takes about 250 milliseconds!// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)float h = dht.readHumidity();// Read temperature as Celsius (the default)float t = dht.readTemperature();// Read temperature as Fahrenheit (isFahrenheit = true)float f = dht.readTemperature(true);// Check if any reads failed and exit early (to try again).if (isnan(h) || isnan(t) || isnan(f)) {Serial.println("Failed to read from DHT sensor!");return;}// Compute heat index in Fahrenheit (the default)float hif = dht.computeHeatIndex(f, h);// Compute heat index in Celsius (isFahreheit = false)float hic = dht.computeHeatIndex(t, h, false);Serial.print("Humidity: ");Serial.print(h);Serial.print(" %\t");Serial.print("Temperature: ");Serial.print(t);Serial.print(" *C ");Serial.print(f);Serial.print(" *F\t");Serial.print("Heat index: ");Serial.print(hic);Serial.print(" *C ");Serial.print(hif);Serial.println(" *F");lcd.setCursor(2,1); // line 1, pos 0lcd.print((int)h);lcd.setCursor(8,1); // line 1, pos 0lcd.print((int)t);lcd.setCursor(13,1);lcd.print((int)(Clock.getTemperature()*10));delay(1000);
}

Arduino从DHT11读取温湿度数据并显示在1602LCD相关推荐

  1. 树莓派3B Qt+dht11读取温湿度并写入数据库202005(8)

    内容 本文介绍:使用树莓派3B Qt+dht11读取温湿度,以一定时间间隔更新数据,显示于界面,并写入数据库 硬件:树莓派3B,温湿度传感器dht11,杜邦线 1.建工程 建立工程后点击mainwin ...

  2. dht11 java_树莓派从DHT11读取温湿度

    树莓派之DHT11传感器 硬件DHT11 主要看其原理,具体的详细原理大家就搜索引擎都能搜到. 也是为了好奇心,入手一台便宜的示波器,看看具体波形,下面是我所测: 这张显示首次触发,主机至少下拉18m ...

  3. qt读取摄像头数据并显示

    Qt 框架可以使用 Qt Multimedia 模块读取摄像头数据并显示.下面是一个简单的例子: 创建一个 Qt Widgets 项目 在窗口上放置一个 QCameraViewfinder 创建一个 ...

  4. 泰克示波器控制scpi,程序读取波形数据并显示

    泰克示波器控制scpi,程序读取波形数据并显示,py程序 """ tektronix MDO3000 series oscilloscope test "&qu ...

  5. Esp32读取温湿度数据通过mqtt上传阿里云平台

    目录 前言 一.esp32刷MicroPython固件库 二.创建阿里云产品 1.注册阿里云账号并登录控制台 2.找到物联网平台中的公共实例进入 3.创建产品及设备 4.编辑物模型并发布 5.最后找到 ...

  6. 基于cc2530获取DHT11的温湿度数据

    1.概述: DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性和卓越的长期稳定性.传感器包括一个电阻式感湿 ...

  7. 通过时序图编程操作DHT11读取温湿度

    目录 一.DHT11模块 二.时序图分析 总的时序: 开始信号与响应信号: 读取数据: 停止信号: 三.程序部分 一.DHT11模块 Dht11温湿度检测模块,模块引出引脚有VCC.GND和DATA, ...

  8. MATLAB读取nc数据并显示

    本篇博客主要介绍采用MATLAB读取nc数据并进行显示. 首先是显示经纬度: 示例代码: lon = ncread('met_em.d02.2018-09-12_00_00_00.nc', 'XLON ...

  9. 读取MNIST数据集并显示数据集图片 完全解析

    # coding: utf-8 import sys, os sys.path.append(os.pardir) # 为了导入父目录的文件而进行的设定 import numpy as np from ...

最新文章

  1. Julia程序设计3 数组1 创建、初始化、属性与访问
  2. 【Paper】2018_多无人机协同编队控制算法研究_林倩玉
  3. Java 中Comparator 的使用,实现集合排序
  4. Atcoder ARC062F - AtCoDeerくんとグラフ色塗り / Painting Graphs with AtCoDeer
  5. jtabel 遍历_使用抽象表模型获取JTable中选定的行
  6. 比特币钱包私钥_如何通过私钥创建比特币钱包地址
  7. SQL Server 2012入门T-SQL基础篇:(10)UPDATE语句
  8. 递归算法计算八皇后问题(Eight Queen Problem with Recursive Algorithm)
  9. 隐式差分matlab程序,油藏数值模拟隐式差分MATLAB源程序
  10. 中文核心期刊是什么?
  11. 10K 3435热敏电阻阻值表
  12. 利用Github快速搭建个人博客总结(亲测)
  13. 第2章——R的数据组织
  14. nu.xom.IllegalNameException: 0x20 is not a legal NCName character
  15. 递推练习之费解的开关
  16. 三相异步电机基于模型的效率估计算法
  17. 用JS做一个简易的时间显示动态效果
  18. selenium打开浏览器后闪退解决
  19. python去除Excel重复项
  20. CHAP协议认证模式

热门文章

  1. 每天九点十分开始每半小时一次执行一个cron_每天通勤4小时!西咸双城生活的上班族,不简单...
  2. mysql ehcache_MyBatis使用Ehcache作为二级缓存
  3. mysql主从配置常见问题_mysql 主从复制配置,以及常见问题解决!
  4. Unity项目代码书写规范
  5. 机器学习之 weka学习(四)
  6. iOS下载大文件原理解析一
  7. vue中通过第三方代理解决跨域问题
  8. Flask中路由系统以及蓝图的使用
  9. C#循环给多个控件赋值
  10. R-CNN , Fast R-CNN , Faster R-CNN原理及区别