Introduction: Making an Alarm Clock That Asks Questions Randomly

About: Empowering Creation for Future Innovators; Our mission is to form a community with easy access to whether hardware, software and ideas that allow makers and younger generation to achieve their goals and realiz…

Do you usually have trouble getting up? Set more than a dozen alarm clocks in the morning, but still can't wake up and turn them off in a daze. When you waking up and find out that you are late, and then you blame the alarm clock for not making any noise. In order to help me better complete my 996 workdays, a simple small alarm clock is specially made - an alarm clock that will randomly ask questions. Its unpleasant cry makes you sleepless; in addition, during the answering process, you must concentrate on listening to the question, otherwise, you will not be able to judge whether it is asking “how many is one plus one” or “How many words in the question of ‘how many is one plus one’” It is a home essential product, the initiator who forced you to the peak of life.


Step 1: Design Idea

I got two very interesting small modules from DFRobot, one is the speech synthesis module and the other is the speech recognition module.

So I thought about making an alarm clock. I felt that it was really difficult for everyone to get up in the morning, and ordinary alarm clocks were full of cannon fodder. Then the idea of making a "real" alarm clock emerged. In fact, I found that when people wake up and after their mind become clear, they don't want to sleep anymore. So whether it is an alarm clock with wheels running around or an alarm clock that slaps people, it is all about making people have a clear conscience. I will make a slightly gentler one here. An alarm clock with random questions. It will stop making noise if the answer is correct; if the answer is incorrect, it will keep annoying you.

Step 2: Start Making the Cover

Find a suitable carton, I don't have a suitable one here. So I use two small one and glued them together to make a big one.

Step 3: Connect Each Module As Follows

Clock Module → uno IIC

Clock Module INT Pin → uno D2

Speaker Red Wire → uno D3

Speaker Black Wire → uno GND

IIC Expansion Board → uno IIC

White Button → uno D4

Speech recognition, synthesis, LED segment code → IIC Expansion Board

Step 4: Refit the Cover and Assembly

1. Make a hole for the LED segment screen, and the holes for the speaker and battery on the back of the box.

2. Use hot melt adhesives to glue all the modules on, and finally, put all the devices into the box.

Step 5: Programming

Install the library functions of each module, adjust the questions you want to ask and the time of the alarm setting, then burn the program into it.

* @file setAlarmInterrupt.ino
* @brief Set alarm, and use interrput pin to trigger it
* @n Experiment phenomenon: set the alarm clock to trigger at a specified time
* @n connect SQW pin with DIGITALPIN2
* @n print information on serial port after the alarm clock is triggered.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (
* @licence The MIT License (MIT)
* @author [LuoYufeng](
* @version V0.1
* @date 2019-08-19
* @url
#include "DFRobot_DS3231M.h"
#include "DFRobot_SpeechSynthesis.h"
#include "DFRobot_ASR.h"
# include "DFRobot_LedDisplayModule.h"

DFRobot_LedDisplayModule LED(Wire, 0xE0);
DFRobot_SpeechSynthesis_I2C ss;
DFRobot_ASR asr;
volatile int8_t alarmFlag = 0;
unsigned long timeout = 3000;
unsigned long timelast = 0;
unsigned long timenow = 0;
unsigned char hourval =0;
unsigned char hourhigh = 0;
unsigned char hourlow = 0;
unsigned char minuteval = 0;
unsigned char minutehigh = 0;
unsigned char minutelow = 0;
unsigned char secondval = 0;
unsigned char secondhigh = 0;
unsigned char secondlow = 0;
char str1[2];
char str2[2];
char str3[2];
char str4[2];
char str5[2];
char str6[2];
char str7[2];
char str8[2];
DFRobot_DS3231M rtc;

void setup(void)
while(LED.begin8() != 0)
Serial.println("Initialization of the chip failed, please confirm that the chip connection is correct!");

/*Wait for the chip to be initialized completely, and then exit*/
while(rtc.begin() != true){
Serial.println("failed to init chip, please check if the chip connection is correct. ");
*@brief Set the value of pin sqw
*@param mode eDS3231M_OFF = 0x01 // Not output square wave, enter interrupt mode
*@n eDS3231M_SquareWave_1Hz = 0x00 // 1Hz square wave
*@n eDS3231M_SquareWave_1kHz = 0x08 // 1kHz square wave
*@n eDS3231M_SquareWave_4kHz = 0x10 // 4kHz square wave
*@n eDS3231M_SquareWave_8kHz = 0x18 // 8kHz square wave

*@brief enable Alarm1 interrupt

*@brief disable Alarm1 interrupt

*@brief enable Alarm2 interrupt

*@brief disable Alarm2 interrupt
rtc.setAlarm(eMinutesHoursDayMatch,/*date,0-30*/30,/*hour,1-12 in 12hours,0-23 in 24hours*/15,e24hours,
/*minute,0-59*/13,/*second,0-59, this argument doesn't work in Alarm2*/42);
//rtc.setAlarm(eMinutesHoursDayMatch,/*date,0-30*/30,/*hour,1-12 in 12hours,0-23 in 24hours*/15,e24hours,
// /*minute,0-59*/13,/*second,0-59, this argument doesn't work in Alarm2*/42);
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
rtc.setYear(21);//Set year, default in the 21st century.
attachInterrupt(0, interrupt, FALLING);


void loop() {
*@brief Judge if the alarm clock is triggered
*@return true, triggered; false, not triggered
Serial.print(rtc.year(), DEC);
Serial.print(rtc.month(), DEC);
Serial.print(, DEC);
Serial.print(" (");
Serial.print(") ");
Serial.print(rtc.hour(), DEC);
Serial.print(rtc.minute(), DEC);
Serial.print(rtc.second(), DEC);
Serial.print(' ');
/*if rtc works in 24hours mode,this function doesn't print anything*/
hourval = rtc.hour();
hourhigh = hourval/10;
hourlow = hourval%10;
minuteval = rtc.minute();
minutehigh = minuteval/10;
minutelow = minuteval%10;
secondval = rtc.second();
secondhigh = secondval/10;
secondlow = secondval%10;
sprintf(str1, "%d", hourhigh);
sprintf(str2, "%d", hourlow);
sprintf(str4, "%d", minutehigh);
sprintf(str5, "%d", minutelow);
sprintf(str7, "%d", secondhigh);
sprintf(str8, "%d", secondlow);
if(alarmFlag == 1){

Serial.println("Alarm clock is triggered.");
ss.speak("how many is one plus one");
timelast = millis();
if( == 3){
Serial.println("received'san',command flag'0'");
alarmFlag = 0;
timenow = millis();
if((timenow - timelast) >= timeout){
Serial.println("received'x',command flag'x'");

if (rtc.lostPower()) {
Serial.println("RTC lost power, please reset the time!");

void interrupt(){
alarmFlag = 1;

Step 6: And Then, It's Done

Thanks for reading! Welcome any opinions about this project.