TA的每日心情 | 奋斗 2019-10-1 12:54 |
---|
签到天数: 313 天 连续签到: 1 天 [LV.8]以坛为家I
|
下面介绍使用Arduino UNO、LCD1602、DS1307、DHT11制作带星期温湿度的数字日历时钟的方法
硬件连接:
DS1307模块的SDA SCL连接Arduino UNO数字输入输出上面一排的SDA SCL,DS1307的VCC GND连接Arduino UNO的ICSP的VCC GND
ICSP排针排列如下
LCD1602的VCC GND SDA SCL连接到Arduino UNO的5V GND A4 A5
DHT11温湿度传感器的VCC GND DATA连接到Arduino UNO的3.3V GND 数字输入输出7
连接好之后上电,打开Arduino IDE,打开项目--加载库--管理库,搜索安装rtllib库
如果之前没有安装过LiquidCrystal_I2C库还需要安装这个,接着搜索安装DHT Sensor Library by Adafruit库,建议安装低于1.2.2版本,如果安装1.3.0版本会报错缺少Adafruit_Sensor.h,安装1.3.0版本DHT库的用户还需要安装Adafruit Unified Sensor库才能解决编译报错
安装完库之后新建sketch输入下面代码
#include <Wire.h>#include <RTClib.h>#include "DHT.h"#include <LiquidCrystal_I2C.h>#define DHTPIN 7#define DHTTYPE DHT11DHT dht(DHTPIN, DHTTYPE);float hum;float temp;LiquidCrystal_I2C lcd(0x3F,16,2);RTC_DS1307 RTC;char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};void setup () { Serial.begin(9600); lcd.init(); lcd.backlight(); dht.begin(); Wire.begin(); RTC.begin(); RTC.adjust(DateTime(__DATE__, __TIME__)); }void loop () { int h = dht.readHumidity(); int t = dht.readTemperature(); DateTime now = RTC.now(); Serial.print(now.year(), DEC); Serial.print('-'); Serial.print(now.month(), DEC); Serial.print('-'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.print(' '); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.println(); lcd.setCursor(0,0); lcd.print(now.year(), DEC); lcd.print('-'); lcd.print(now.month(), DEC); lcd.print('-'); lcd.print(now.day(), DEC); lcd.print(' '); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); delay(1000); lcd.setCursor(0,1); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.print(':'); lcd.print(now.second(), DEC); lcd.print(' '); lcd.setCursor(9,1); lcd.print(t); lcd.print("C"); lcd.print(" "); lcd.print(h); lcd.print("%");}上传后运行效果如下
|
|