大连林海 发表于 2016-3-4 21:00:36

液晶温湿度计兼时钟-DHT11,ds1307,5110液晶

本项目目标:DHT11,ds1307,5110液晶综合运用来做一个带温度,湿度的时钟,使用9V供电


本项目使用到的模块:
Arduino uno主控*1(包括USB线)
Nokia 5110 LCD液晶模组*1
DHT11温度传感器*1
DS1307时钟RTC模块*1
杜邦线*大量
木板雕刻件(参考附件图纸)
螺丝M3*10及螺母*30组(容易掉多备点)
9V电池及接插件

本项目使用到的工具:
万用表(有了比较方便)
螺丝刀适合M3螺丝的就行
热熔胶枪(也可以用胶水之类的,主要用来固定线缆保证可靠性)


本项目使用到的软件及库文件:
Arduino IDE1.05R2
用到的库DHT11,DS1307
机械方面需要用到Solidworks,autocad
库文件   DHT11及RTClib

http://image.geek-workshop.com/forum/201602/29/132317uoni110woa99h0o0.jpg
http://image.geek-workshop.com/forum/201602/29/132342neqzge4xkokxoghs.jpg
http://image.geek-workshop.com/forum/201602/29/132409ed55d8fjcccjn5cd.jpg
http://image.geek-workshop.com/forum/201602/29/132411c575gce35xmevdq5.jpg




/*
Author:simon
Date:2016Feb28
IDE Version:1.0.5R2
Mission:液晶温湿度计兼时钟-DHT11,ds1307,5110液晶综合运用
*/

#include <dht11.h>
#include <string.h>
#include <stdio.h>
#include <Wire.h>
#include <RTClib.h>

void printDateTime(DateTime dateTime);

//创建实例
RTC_DS1307 RTC;
//RTC时钟DS1307模块====SCL连主控板A5
//RTC时钟DS1307模块====SDA连主控板A4
//RTC时钟DS1307模块====GND连主控板GND
//RTC时钟DS1307模块====VCC连主控板5V


/* 日期变量缓存 */
char buf;
char day;
/* 串口数据缓存 */
String comdata = "";
int numdata ={0}, j = 0, mark = 0;

dht11 DHT11;

#define DHT11PIN A0 ///温度传感器连接到A0
//端口定义

///液晶模块 VCC连到5V
///液晶模块 GND连到GND
///液晶模块 BLK连到5V背光LED
int LCD_CE=3;   //液晶模块 CE连到3
int LCD_RST=2;//液晶模块 RST连到2
int SCLK=7;//液晶模块 CLK连到7
int SDIN=6;//液晶模块 Din连到6
int LCD_DC=5;//液晶模块 DC连到5

double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} //摄氏温度度转化为华氏温度

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-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * 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/100);
double Td = (b * temp) / (a - temp);
return Td;
}

//****************************定义ASCII字符**********************//

/**********************************
6 x 8 font
1 pixel space at left and bottom
index = ASCII - 32
***********************************/
const unsigned char font6x8[] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
};






/************************LCD初始化函数********************************/
void LCD_init(void)
{
//先设置为输出
pinMode(SCLK,OUTPUT);
pinMode(SDIN,OUTPUT);
pinMode(LCD_DC,OUTPUT);
pinMode(LCD_CE,OUTPUT);
pinMode(LCD_RST,OUTPUT);

// 产生一个让LCD复位的低电平脉冲
digitalWrite( LCD_RST, LOW);

delayMicroseconds(1);
digitalWrite( LCD_RST, HIGH);

// 关闭LCD
digitalWrite( LCD_CE, LOW);
delayMicroseconds(1);

// 使能LCD
digitalWrite( LCD_CE, HIGH); //LCD_CE = 1;
delayMicroseconds(1);
LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式
LCD_write_byte(0xb8, 0); // 设置偏置电压
LCD_write_byte(0x06, 0); // 温度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示

// 关闭LCD
digitalWrite( LCD_CE, LOW); //LCD_CE = 0;
}
/************************LCD清屏函数*************Robocat.com.cn******************/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
{
LCD_write_byte(0, 1);
}
}
/*************************设置字符位置函数**************************/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
/*************************ASCII字符显示函数*************************/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
{
LCD_write_byte(font6x8, 1);
}
}
/*******************************************************************/
/*-------------------------------------------------
LCD_write_english_String : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,x 0-83 ,y 0-5
--------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/******************************************************************/
/*---------------------------------------------
LCD_write_byte : 写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
---------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
digitalWrite( LCD_CE, LOW); // 使能LCD_CE = 0
if (command == 0)
{
digitalWrite( LCD_DC, LOW);// 传送命令 LCD_DC = 0;
}
else
{
digitalWrite( LCD_DC, HIGH);// 传送数据LCD_DC = 1;
}

for(i=0;i<8;i++)
{
if(dat&0x80)
{
digitalWrite( SDIN, HIGH);//SDIN = 1;
}
else
{
digitalWrite( SDIN, LOW);//SDIN = 0;
}
digitalWrite( SCLK, LOW);//SCLK = 0;
dat = dat << 1;
digitalWrite( SCLK, HIGH);//SCLK = 1;
}
digitalWrite( LCD_CE, HIGH);//LCD_CE = 1;

}
/******************************************************************/



void setup()
{
delay(10);
Serial.begin(9600);
LCD_init();//初始化液晶
LCD_clear();
delay(10) ;
//初始化总线
Wire.begin();
//初始化实时时钟
RTC.begin();


}
void loop()
{
DateTime now = RTC.now();

char str1="",str2;

String str=String(DHT11.temperature);
str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;
//strcpy(str1,str2);
LCD_write_english_string(0,0,"Temp(oC): ") ;
int chk = DHT11.read(DHT11PIN);
LCD_write_english_string(72,0,str1) ;


str=String(DHT11.humidity);
str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;
//strcpy(str1,str2);
LCD_write_english_string(0,2,"Humid ity:") ;
chk = DHT11.read(DHT11PIN);
LCD_write_english_string(72,2,str1) ;
LCD_write_english_string(0,3,"Robocat") ;

//rtc

LCD_write_english_string(0,4,"T:") ;
String str_second="";
if (now.second()<10)
{
str_second="0";
}

String str_minute="";
if (now.minute()<10)
{
str_minute="0";
}

String str_hour="";
if (now.hour()<10)
{
str_hour="0";
}




str=str_hour+String(now.hour()) +":"+str_hour+String(now.minute())+":"+str_second+String(now.second());
str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;
LCD_write_english_string(20,4,str1) ;
LCD_write_english_string(0,5,"D:") ;



str=String(now.year()) +"-"+String(now.month())+"-"+String(now.day());
str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;str1=str;
str=String(" ");
LCD_write_english_string(18,5,str1) ;
LCD_write_english_string(18,5,str1) ;




//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;
}

Serial.print("Hour;");
Serial.println(now.hour());





delay(200) ;
}





iooops 发表于 2016-3-4 21:28:40

啊好像很复杂的样子…………

大连林海 发表于 2016-3-4 21:30:41

iooops 发表于 2016-3-4 21:28
啊好像很复杂的样子…………

一个朋友做的 很牛的

iooops 发表于 2016-3-4 22:59:39

大连林海 发表于 2016-3-4 21:30
一个朋友做的 很牛的

{:5_172:}

dsweiliang 发表于 2016-3-5 14:01:53

你朋友做的,算不算是原创贴?

virtualwiz 发表于 2016-3-5 19:42:04

有激光机真好呀,分分钟做外壳:lol

大连林海 发表于 2016-3-6 07:13:39

dsweiliang 发表于 2016-3-5 14:01
你朋友做的,算不算是原创贴?

朋友的原创 不过他发在其他的论坛了 我觉得很好 就发过来 让大家看看

大连林海 发表于 2016-3-6 07:13:51

virtualwiz 发表于 2016-3-5 19:42
有激光机真好呀,分分钟做外壳

可惜 我没有 领导不给买

maomaopcy 发表于 2018-3-16 20:06:20

dht11这个库如何安装呢

kimi423520 发表于 2018-6-24 14:37:41

温湿度计用DHT-22 是不是会更好,

Johnnie168 发表于 2018-11-18 14:28:10

感谢分享!

jfMTScEaoh0s 发表于 2022-3-5 20:22:42

啊,不用U8GLIB吗?直接通信很烦
页: [1]
查看完整版本: 液晶温湿度计兼时钟-DHT11,ds1307,5110液晶