欢迎光临
我们一直在努力

Arduino温湿度开空调提醒实验(MP3模块版本)

2018012609571611_thumb[3]

==概述==

最近天气寒冷,办公室温度降到只有几度,办公室一整天开空调,按照BOSS的要求,严格把控温度,随意用现有的传感器和模块做了个开空调提醒的桌面温度监测装置。

本次是以小实验的方式写的,对于模块不了解的,可以先看一下我们的模块教程,了解掌握模块使用方法后,再尝试本小实验。

对于非本店模块不提供技术支持!如果无法做通,可能是不兼容导致,请自行尝试)。

 


所需材料:


UNO R3主控版一个:
点我购买


面包板一块:
点我购买


杜邦线若干(公对母):
点我购买


面包线若干:
点我购买


DHT11温湿度模块一个:点我购买


MP3播放器模块一个:
点我购买


SD卡(TF内存卡一张),建议去在线商城购买


小喇叭一个:点我购买


1K电阻两个:
点我购买


I2C1602显示屏:
点我购买 

模块教程:

MP3模块教程:http://arduino365.com/2016/09/01/mp3%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8%E6%A8%A1%E5%9D%97/

I2C1602显示屏:http://arduino365.com/2016/09/01/i2c-1602%E8%BD%AC%E6%8E%A5%E6%9D%BF/

DHT11:http://arduino365.com/2016/08/31/%E6%B8%A9%E6%B9%BF%E5%BA%A6%E4%BC%A0%E6%84%9F%E5%99%A8dht11/

==接线图==


zhuomianwendu0002_2222_thumb[2]

==接线方式==

Arduino            DHT11

5V                      VCC

GND                  GND

D2                      DATA

—————————————–

Arduino              mp3

5V                       VCC

GND                   GND

TX         1K电阻              RX

RX         1K电阻              TX

———————————————

MP3                      小喇叭

SPK_1                     +

SPK_2                     –

——————————————–

Arduino                 I2C1602显示屏

5V                             VCC

GND                          GND

A4                              SDA

A5                              SCL

——————————————————————————————

==例子程序==

//**************************库文件部分**************************
#include <LiquidCrystal_I2C.h>//I2C1602显示屏头文件
#include <Wire.h>//I2C头文件
LiquidCrystal_I2C lcd(0x3B,16,2);//I2C1602显示屏地址、坐标
#include <SoftwareSerial.h>//Arduino软串口头文件
#include <DFPlayer_Mini_Mp3.h>//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.h>//引用头文件
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分钟后,重新开始播报。



  

==相关下载==

库文件:https://pan.baidu.com/s/1qZEWFc4

所需要的语音文件(整个MP3文件夹扔进SD卡里):https://pan.baidu.com/s/1jJ5F3d8

免费及超级好用的文字转MP3软件:http://www.gateface.com/

(下载并安装后,内网登录—-打开浏览器,界面上有个语音朗读)


20180126103435_thumb[2]

未经允许不得转载:Arduino-Maker » Arduino温湿度开空调提醒实验(MP3模块版本)

支付宝扫码打赏 微信打赏

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

分享到:更多 ()

评论 抢沙发

评论前必须登录!

 

线上商城

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