找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 12060|回复: 7
打印 上一主题 下一主题
收起左侧

arduino+DS1302+dht11

[复制链接]
跳转到指定楼层
楼主
最近发现自己没有个小钟表起床看时间不方便于是就做了一个
成品!

材料arduino
      ds1302
      1602  (有条件的可以使I2c)
      dht11
     电线若干

接线顺序
1602---12 ,11 ,7  ,6  ,5  ,4
ds1302    ce--2
               Io--3
               sclk--9dht11----8

使用3个库LiquidCrystal.h  DS1302.h dht11.h  
直接上原码,没有按键调时,和串口功能,以后改进

  1. #include <LiquidCrystal.h>
  2. #include <DS1302.h>
  3. #include <dht11.h>      // DHT11 传感器程序库

  4. // Init the DS1302
  5. DS1302 rtc(2, 3, 9);
  6. // Init the LCD
  7. LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
  8. void setup()
  9. {
  10.   // Set the clock to run-mode, and disable the write protection
  11.   rtc.halt(false);
  12.   rtc.writeProtect(false);

  13.   // Setup LCD to 16x2 characters
  14.   lcd.begin(16, 2);

  15.   // The following lines can be commented out to use the values already stored in the DS1302
  16.   rtc.setDOW(TUESDAY);        // Set Day-of-Week to FRIDAY
  17.   rtc.setTime(22,05, 0);     // Set the time to 12:00:00 (24hr format)
  18.   rtc.setDate(24,10,2017);   // Set the date to August 6th, 2010
  19. }

  20. void loop(){
  21.         // Display time centered on the upper line
  22.   lcd.setCursor(1, 0);
  23.   lcd.print(rtc.getTimeStr());

  24.   // Display abbreviated Day-of-Week in the lower left corner
  25.   lcd.setCursor(12, 0);
  26.   lcd.print(rtc.getDOWStr(FORMAT_SHORT));

  27.   // Display date in the lower right corner
  28.   lcd.setCursor(6, 1);
  29.   lcd.print(rtc.getDateStr());

  30.   // Wait one second before repeating :)
  31.   delay (1000);

  32. dht11 DHT11;     // 温湿度传感器程序对象
  33. const byte dataPin = 8;
  34.   int chk = DHT11.read(dataPin);
  35.   if (chk == 0)
  36.     lcd.setCursor(0, 1);   // 显示温度
  37.     lcd.print((float)DHT11.temperature, 1);
  38.     lcd.print((char) 0xDF);


  39. }
复制代码

全部资料51hei下载地址:
数字钟.zip (94.95 KB, 下载次数: 105)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:157550 发表于 2018-12-14 01:51 | 只看该作者
不错不错,学习了
回复

使用道具 举报

板凳
ID:463470 发表于 2019-1-7 09:39 | 只看该作者
谢谢楼主分享。。。。。。。
回复

使用道具 举报

地板
ID:794756 发表于 2020-7-1 18:33 | 只看该作者
在吗, 索取arduino+DS1302+dht11 整套资料
回复

使用道具 举报

5#
ID:471632 发表于 2022-3-9 10:39 | 只看该作者
好东西,能加上wifi自动校时更好了。
回复

使用道具 举报

6#
ID:138707 发表于 2023-7-29 18:44 | 只看该作者
好东西,能加上wifi自动校时更好了。
回复

使用道具 举报

7#
ID:1075678 发表于 2023-10-14 18:53 | 只看该作者
ziba108 发表于 2023-7-29 18:44
好东西,能加上wifi自动校时更好了。

想请问一下,怎么添加呢?发现库里面没有找到关于WiFi的库文件,所以就不知道怎么继续做了。
回复

使用道具 举报

8#
ID:1075678 发表于 2023-10-14 19:09 | 只看该作者
想问一下这里使用的IIC功能吗?为什么我在自己软件上面验证时,出现说void halt出现问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表