考完试来搞事情啦~~
搜了一次论坛,只有一个关于闹钟的项目好像,于是......就有了这个..
上视频!
首先,这个项目是由浩克闹钟和反浩克贴纸构成
反浩克贴纸用于关闭闹钟,所以关闹钟首先要找到这个贴纸...(划重点),这个只有霍尔传感器方案可以实现哦
材料
浩克闹钟:
Arduino Nano DFR0010
mp3播放模块
TF内存卡
3W小喇叭
DS3231时钟模块
SS49线性霍尔传感器
小磁铁
(视频中也使用了红外避障模块,和霍尔传感器两个方案任选)
反浩克贴纸:一张纸
一个小磁铁
万能的热熔胶
制作过程

准备材料


截取浩克的声音

连接MP3模块

完成其他的硬件接线

拆面具


引出LED电源线

测试

整体图

安装面具

调整红外模块的灵敏度(调至最低,防止误触发)

用热熔胶固定

正面安装磁铁,用于吸合反浩克贴纸
(磁铁很小,可能看不到,在人中偏下的位置)

背面图

反浩克贴纸hhhh

上面也有一个小磁铁哦,这个很重要
代码部分
需要安装Ds3231和MP3的库文件
DFRobotDFPlayerMini-1.0.1.zip
ds3231-master.zip
(MP3是使用DF的库文件)
DS3231一般买回来的时候是时间不准的,需要用代码调整,但是这个改时间的代码只要运行一次哦(程序中我就先注释掉了)
这一段:
-
- //Reset time of the DS3231,Use only once when the time is not accurate
- struct ts settime;
- settime.sec = 00;
- settime.min = 24;
- settime.hour = 16;
- settime.mday = 4;
- settime.mon = 5;
- settime.year = 2017;
-
- DS3231_set(settime);
复制代码
设置闹钟的代码- // time when to wake up
- uint8_t wake_HOUR = 18;
- uint8_t wake_MINUTE = 54;
- uint8_t wake_SECOND = 20;
复制代码
这里设置的就是18'54"20,每天一次
完全体的代码
- #include "Arduino.h"
- #include "SoftwareSerial.h"
- #include "DFRobotDFPlayerMini.h"
- #include <Wire.h>
- #include "ds3231.h"
-
- #define BUFF_MAX 256
- SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
- DFRobotDFPlayerMini myDFPlayer;
- void printDetail(uint8_t type, int value);
-
- // time when to wake up
- uint8_t wake_HOUR = 18;
- uint8_t wake_MINUTE = 54;
- uint8_t wake_SECOND = 20;
-
- int playingFlag = 0;
-
- // how often to refresh the info on stdout (ms)
- unsigned long prev = 1000, interval = 1000;
-
- void set_alarm(void)
- {
- // flags define what calendar component to be checked against the current time in order
- // to trigger the alarm - see datasheet
- // A1M1 (seconds) (0 to enable, 1 to disable)
- // A1M2 (minutes) (0 to enable, 1 to disable)
- // A1M3 (hour) (0 to enable, 1 to disable)
- // A1M4 (day) (0 to enable, 1 to disable)
- // DY/DT (dayofweek == 1/dayofmonth == 0)
- uint8_t flags[5] = { 0, 0, 0, 1, 1 };
-
- // set Alarm1
- DS3231_set_a1(wake_SECOND, wake_MINUTE, wake_HOUR, 0, flags);
-
- // activate Alarm1
- DS3231_set_creg(DS3231_INTCN | DS3231_A1IE);
- }
-
- void setup()
- {
- pinMode(4,OUTPUT);//led pin
- pinMode(3,INPUT);//ir sensor pin
- Wire.begin();
- DS3231_init(DS3231_INTCN);
- DS3231_clear_a1f();
- set_alarm();
- mySoftwareSerial.begin(9600);
- Serial.begin(115200);
- Serial.println();
- Serial.println(F("DFRobot DFPlayer Mini Demo"));
- Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
- if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
- Serial.println(F("Unable to begin:"));
- Serial.println(F("1.Please recheck the connection!"));
- Serial.println(F("2.Please insert the SD card!"));
- while (true);
- }
- Serial.println(F("DFPlayer Mini online."));
- myDFPlayer.volume(22); //Set volume value. From 0 to 30
- //myDFPlayer.play(1); //Play the first mp3
- //myDFPlayer.pause();
- /*
- //Reset time of the DS3231,Use only once when the time is not accurate
- struct ts settime;
- settime.sec = 00;
- settime.min = 24;
- settime.hour = 16;
- settime.mday = 4;
- settime.mon = 5;
- settime.year = 2017;
-
- DS3231_set(settime);
- */
-
- }
-
- void loop()
- {
- char buff[BUFF_MAX];
- unsigned long now = millis();
- struct ts t;
- // once a while show what is going on
- if ((now - prev > interval) && (Serial.available() <= 0)) {
- DS3231_get(&t);
- // display current time
- snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year,
- t.mon, t.mday, t.hour, t.min, t.sec);
- Serial.println(buff);
- // display a1 debug info
- DS3231_get_a1(&buff[0], 59);
- Serial.println(buff);
- if (DS3231_triggered_a1()) {
- // INT has been pulled low
- Serial.println(" -> alarm1 has been triggered");
- myDFPlayer.enableLoopAll(); //play the first wav
- digitalWrite(4,HIGH);//open led
- playingFlag = 1;//set the playing flag
- // clear a1 alarm flag and let INT go into hi-z
- DS3231_clear_a1f();
- }
- prev = now;
- }
- if (!digitalRead(3) && playingFlag == 1)
- {
- myDFPlayer.pause();
- digitalWrite(4,LOW);//close led
- playingFlag = 0;
- }
- }
复制代码
传一下代码文件和音频
HK_clock_1.zip
浩克声音.zip
|