0

$USD

$USD
PROJECTS Arduino

DIY Simple Math-Solving Alarm Clock Out of Cardboard

DFRobot Dec 19 2019 846

This will prevent you from going back to sleep after snoozing that since now you have to solve a math problem to snooze the alarm.

Things used in this project

Hardware components

Arduino UNO & Genuino UNO ×1 
DFRobot I2C 16x2 Arduino LCD Display Module ×1 
Buzzer ×1 
IR receiver (generic) ×1 
JustBoom IR Remote ×1 
Seeed Pi RTC (DS1307) ×1 
Jumper wires (generic) ×1 
Resistor 10k ohm ×1


Software apps and online services

Arduino IDE


Story

Alert

This clock only works for the Elegoo remote as shown below:

Story

Have you ever fallen right back to sleep after snoozing your alarm clock? That's because you're still bran-dead when you hit that snooze button. A simple way to prevent this is to wake your brain up with a simple math problem.

Earlier this year, I bought the Elegoo Starter Kit UNO R3 Project with the hope of being able to make some cool stuff that I once saw like robot or toy car. This is one of my very first project using Arduino Uno R3 and since I've just started it, the clock itself looks like crap. But it's still better than nothing, right? Link to the kit is here.


Libraries

For this little project, there's a few libraries you need to download and format as you can see below:

*For the IRremote library, you'll have to go to boarddefs.h, find the following segment of code:

// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc // ATmega48, ATmega88, ATmega168, ATmega328 //#define IR_USE_TIMER1 // tx = pin 9 #define IR_USE_TIMER2 // tx = pin 3 and change it to: // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc // ATmega48, ATmega88, ATmega168, ATmega328 #define IR_USE_TIMER1 // tx = pin 9 //#define IR_USE_TIMER2 // tx = pin 3 https://github.com/arduino-libraries/LiquidCrystal https://github.com/adafruit/RTClib
 

https://github.com/arduino-libraries/LiquidCrystal

https://github.com/adafruit/RTClib

 

The cardboard box

Choose and cut whatever cardboard that fits your circuit best. For me, I just cut a random amazon delivery box, and it works great!

The circuit

Assemble your circuit according to the following image



To save some place because my goal is making an as small and compact an alarm clock as possible, I use the Arduino Prototype Shield v.5 that comes with the kit I bought. You can choose to use or not to use the board.

Fits perfectly! :)

Tips

- When compiling the code, don't hit verify (the check icon) but hit upload (the arrow icon) instead.

- When you upload, if you want the clock to have the right time on it, then don't unplug it from the computer or unplug after connect it to external battery.

- If you unplug it and then connect it to the power source, the time shows is the time when you last upload it.



Remote Controller

+ ST/REPT: Hit it if you want to set Alarm. If you've entered "Set hour," hit it again to set minute and again to set second. Hit it one last time to finish setting up alarm

+ The red power button: This button is programmed as a backspace button. Hit it once you've finished setting alarm and want to change (since this remote is a really crappy one, hit power button multiple times until the second line of the LCD indicating the alarm turns off), or when you're typing the wrong answer for the simple math problem (hit it until the answer turns into zero)

+ Apart from number buttons, ST/REPT and red power button, other buttons have no use.


Code

clock.inoArduino (click here to download)

 

#include <IRremote.h> #include <IRremoteInt.h> #include <LiquidCrystal.h> #include "RTClib.h" /** * Go to boarddefs.h * // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc * #else * #define IR_USE_TIMER1    tx = pin 9 * //#define IR_USE_TIMER2    // tx = pin 3 */ #include <stdlib.h> RTC_DS1307 rtc; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const int buzzerPin = 10; int RECV_PIN = 9; IRrecv irrecv(RECV_PIN); decode_results results; long num[10] = {0xFF6897, 0xFF30CF, 0xFF18E7, 0xFF7A85, 0xFF10EF, 0xFF38C7, 0xFF5AA5, 0xFF42BD, 0xFF4AB5, 0xFF52AD}; int a = 0; int b = 0; int c = 0; int d = 0; int setAlarm = 0; void setup() {  lcd.begin(16, 2);  Serial.begin(9600);  irrecv.enableIRIn();  if(rtc.begin()&&rtc.isrunning()){    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));  } } void loop() {    DateTime now = rtc.now();    lcd.setCursor(0, 0);    if(now.hour()<10)lcd.print("0");    lcd.print(now.hour());    lcd.print(':');    if(now.minute()<10)lcd.print("0");    lcd.print(now.minute());    lcd.print(':');    if(now.second()<10)lcd.print("0");    lcd.print(now.second());    lcd.print("       ");    getAlarm(); } void getAlarm(){  int ques1 = rand()%100+1;  int ques2 = rand()%100+1;  int ans = ques1 + ques2;  if (irrecv.decode(&results)){    Serial.println(results.value, HEX);    irrecv.resume();    if(results.value==0xFFB04F){        setAlarm=1;    }else if(results.value==0xFFFFFFFF){      setAlarm = setAlarm;      }  }  if(digitalRead(buzzerPin)==HIGH){    setAlarm=5;    }  while(setAlarm==1){    lcd.setCursor(0,0);    lcd.print("Set Hour");    lcd.setCursor(0,1);    if(irrecv.decode(&results)){      for(int i = 0; i<10; i++){        if(results.value==num[i]){          a = a*10+i;        }else if(results.value==0xFFFFFFFF){          a = a;          }        irrecv.resume();      }      if(a<24){        lcd.print(a);        if(results.value==0xFFB04F){          setAlarm=2;        }      }else{        lcd.clear();        setAlarm = 1;        a=0;      }    }  }  while(setAlarm==2){    lcd.setCursor(0,0);    lcd.print("Set Minute");    lcd.setCursor(0,1);    if(irrecv.decode(&results)){      for(int i = 0; i<10; i++){        if(results.value==num[i]){          b = b*10+i;        }else if(results.value==0xFFFFFFFF){          b = b;          }else if(results.value==0xFFB04F){          setAlarm++;        }        irrecv.resume();      }      lcd.print(a);      lcd.print(':');      if(b<60){        lcd.print(b);        if(results.value==0xFFB04F){          setAlarm=3;        }      }else{        lcd.clear();        setAlarm = 2;        b=0;      }    }  }  while(setAlarm==3){    lcd.setCursor(0,0);    lcd.print("Set Second");    lcd.setCursor(0,1);    if(irrecv.decode(&results)){      for(int i = 0; i<10; i++){        if(results.value==num[i]){         c = c*10+i;        }else if(results.value==0xFFFFFFFF){          c = c;          }else if(results.value==0xFFB04F){          setAlarm++;        }        irrecv.resume();      }      lcd.print(a);      lcd.print(':');      lcd.print(b);      lcd.print(':');      if(c<60){        lcd.print(c);        if(results.value==0xFFB04F){          setAlarm=4;        }      }else{        lcd.clear();        setAlarm = 3;        c=0;      }            }  }  while(setAlarm==4){    lcd.setCursor(0,1);    lcd.print("Alarm-");    if(a<10)lcd.print("0");    lcd.print(a);    lcd.print(':');    if(b<10)lcd.print("0");    lcd.print(b);    lcd.print(':');    if(c<10)lcd.print("0");    lcd.print(c);    if(results.value==0xFFB04F){      setAlarm=0;    }  }  DateTime now = rtc.now();  if(now.hour()==a && now.minute()==b && now.second()==c){    tone(buzzerPin, 100);    a=0;    b=0;    c=0;  }  if(irrecv.decode(&results)){    if(results.value==0xFFA25D){      a=0;      b=0;      c=0;      lcd.setCursor(0,1);      lcd.clear();    }  }  while(setAlarm==5){    lcd.setCursor(0,0);    lcd.print(ques1);    lcd.print('+');    lcd.print(ques2);    lcd.print("      ");    if(irrecv.decode(&results)){      for(int i = 0; i<10; i++){        if(results.value==num[i]){          d = d*10+i;        }else if(results.value==0xFFA25D){          d=0;          lcd.print("        ");        }        irrecv.resume();      }      lcd.print(d);    }    if(d==ans){      noTone(buzzerPin);      setAlarm=0;      lcd.setCursor(0,1);      lcd.clear();      d=0;    }  } }

This project copied from hackster.io, Project Maker: Hung-Che