欢迎光临
我们一直在努力

基于Arduino的开空调提醒实验(MP3模块、温湿度模块、1602显示屏)

1、概述

对于模块不了解的,可以先看一下我们的模块教程[传送门],了解掌握模块使用方法后,再尝试本小实验。因为综合实验一般涉及多个模块,我们仅对全部使用我司产品的客户做技术支持,若只是部分使用我司产品的,我们只对我司产品部分是否有故障进行排查。

2、所需材料

1、UNO主控板:官方板 或者 国产板
2、辅助配件:面包板杜邦线
3、传感器和模块:DHT11温湿度传感器MP3音乐播放器模块1602显示屏(IIC版)

3、接线图

Arduino DHT11
5V VCC
GND GND
D2 DATA
Arduino I2C1602显示屏
5V VCC
GND GND
A4 SDA
A5 SCL
Arduino mp3模块
5V VCC
GND GND
TX–1K电阻 RX
RX–1K电阻 TX
喇叭 mp3模块
+ SPK_1
SPK_2

4、程序代码

//**************************库文件部分**************************
#include //I2C1602显示屏头文件
#include //I2C头文件
LiquidCrystal_I2C lcd(0x3B,16,2);//I2C1602显示屏地址、坐标
#include //Arduino软串口头文件
#include //MP3模块头文件
//**************************温湿度计算部分**************************
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;
}
  //**************************温度传感器文件部分**************************
  #include //引用头文件
dht11 DHT11;//申明函数名称
#define DHT11PIN 2//定义DHT11引脚
void setup() {
  //**************************初始值设定部分**************************
Serial.begin (9600);
mp3_set_serial (Serial); //设置MP3串口为Arduino串口
mp3_set_volume (1000);//MP3音量,由于使用8欧0.5瓦喇叭,音量尽可能大一点。 Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();//显示名称字符
}
void loop()
  {
  //**************************温度传感器输出部分**************************
Serial.println("\n");
  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;
}//读取模块状态
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
  Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
  Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);
  Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);
  Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
  Serial.print("DewPointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));//串口输出函数
//**************************I2C1602显示屏温度显示部分**************************
lcd.init();
lcd.backlight();
lcd.print("wendu:");
  lcd.print((float)DHT11.temperature,2);
lcd.println("C    ");
//温度的单位参数
lcd.setCursor(0,1);
lcd.print("shidu:");
lcd.print((float)DHT11.humidity,2);
lcd.println("%RH  ");//%RH湿度的单位参数
//**************************MP3模块输出部分**************************
if(DHT11.temperature==0)
{mp3_play (1);
delay(3000);}
else if(DHT11.temperature==1)
{mp3_play (2);
delay(3000);}
else if(DHT11.temperature==2)
{mp3_play (3);
  delay(3000);}
else if(DHT11.temperature==3)
  {mp3_play (4);
  delay(3000);}
else if(DHT11.temperature==4)
{mp3_play (5);
delay(3000);}
else if(DHT11.temperature==5)
  {mp3_play (6);
delay(3000);}
else if(DHT11.temperature==6)
  {mp3_play (7);
delay(3000);}
else if(DHT11.temperature==7)
{mp3_play (8);
delay(3000);}
else if(DHT11.temperature==8)
  {mp3_play (9);
delay(3000);}
else if(DHT11.temperature==9)
{mp3_play (10);
delay(3000);}
else if(DHT11.temperature==10)
{mp3_play (11);
  delay(3000);}
else if(DHT11.temperature==11)
{mp3_play (12);
delay(3000);}
else if(DHT11.temperature==12)
{mp3_play (13);
delay(3000);}
else if(DHT11.temperature==13)
{mp3_play (14);
delay(3000);}
else if(DHT11.temperature==14)
{mp3_play (15);
delay(3000);}
else if(DHT11.temperature==15)
  {mp3_play (16);
  delay(3000);}
  else if(DHT11.temperature==16)
{mp3_play (17);
delay(3000);}
else if(DHT11.temperature==17)
{mp3_play (18);
delay(3000);}
else if(DHT11.temperature==18)
{mp3_play (19);
  delay(3000);}
else if(DHT11.temperature==19)
{mp3_play (20);
delay(3000);}
else if(DHT11.temperature==20)
{mp3_play (21);
delay(3000);}
else if(DHT11.temperature==21)
{mp3_play (22);
delay(3000);}
else if(DHT11.temperature==22)
{mp3_play (23);
delay(3000);}
else if(DHT11.temperature==23)
  {mp3_play (24);
delay(3000);}
else if(DHT11.temperature==24)
  {mp3_play (25);
delay(3000);}
else if(DHT11.temperature==25)
{mp3_play (26); delay(3000);}
else if(DHT11.temperature==26)
{mp3_play (27);
delay(3000);}
else if(DHT11.temperature==27)
{mp3_play (28);
delay(3000);}
else if(DHT11.temperature==28)
{mp3_play (29);
delay(3000);}
else if(DHT11.temperature==29)
{mp3_play (30);
delay(3000);}
else if(DHT11.temperature==30)
{mp3_play (31);
delay(3000);}
else if(DHT11.temperature==31)
{mp3_play (32);
delay(3000);}
else if(DHT11.temperature==32)
  {mp3_play (33);
delay(3000);}
else if(DHT11.temperature==33)
{mp3_play (34);
delay(3000);}
else if(DHT11.temperature==34)
  {mp3_play (35);
delay(3000);}
else if(DHT11.temperature==35)
{mp3_play (36);
delay(3000);}
else if(DHT11.temperature==36)
  {mp3_play (37);
  delay(3000);}
else if(DHT11.temperature==37)
{mp3_play (38);
  delay(3000);}
else if(DHT11.temperature==38)
  {mp3_play (39);
delay(3000);}
else if(DHT11.temperature==39)
{mp3_play (40);
delay(3000);}
else if(DHT11.temperature==40)
  {mp3_play (41);
delay(3000);}
else if(DHT11.temperature==41)
{mp3_play (42);
  delay(3000);}
else if(DHT11.temperature==42)
  {mp3_play (43);
  delay(3000);}
else if(DHT11.temperature==43)
{mp3_play (44);
delay(3000);}
else if(DHT11.temperature==44)
  {mp3_play (45);
delay(3000);}
else if(DHT11.temperature==45)
{mp3_play (46);
delay(3000);}
else if(DHT11.temperature==46)
  {mp3_play (47);
delay(3000);}
else if(DHT11.temperature==47)
{mp3_play (48);
delay(3000);}
else if(DHT11.temperature==48)
{mp3_play (49);
delay(3000);}
else if(DHT11.temperature==49)
  {mp3_play (50);
delay(3000);}
else if(DHT11.temperature==50)
{mp3_play (51);
delay(3000);}//温度语音部分
if(DHT11.temperature<=15)
{mp3_play(52);
  delay(6000);}
  else if(DHT11.temperature>=30)
  {mp3_play(53);
delay(6000);}
  else if((DHT11.temperature<=29)||(DHT11.temperature>=16))
  {mp3_play(54);
  delay(6000);}//播报语音部分
//**************************屏幕保护部分**************************
lcd.clear();
lcd.print("arduino365.com");
lcd.setCursor(0,1);//屏幕保护显示内容及位置
lcd.print("Arduino-maker");
delay(300000);//屏幕保护延时
lcd.clear(); }

当模块刚上电后,会对温度进行检测,随后提示当前温度,并提醒您是否需要开空调或者温度是否适宜。每隔300秒即5分钟左右自动检测并播报一次,可自行调整。当播报和温度显示结束后,显示屏进入屏幕保护状态。等待10分钟后,重新开始播报。

5、相关下载

1、库文件
2、所需要的语音文件(整个MP3文件夹扔进SD卡里)
3、免费及超级好用的文字转MP3软件
(下载并安装后,内网登录—-打开浏览器,界面上有个语音朗读)

未经允许不得转载:Arduino-Maker » 基于Arduino的开空调提醒实验(MP3模块、温湿度模块、1602显示屏)

支付宝扫码打赏 微信打赏

原创文章,若帮到您,欢迎打赏

分享到:更多 ()

评论 抢沙发

评论前必须登录!

 

线上商城

中贝斯特创客空间蘑菇云创客教育