Yell at the Alarm

From Microduino Wiki
Jump to: navigation, search
Language: English  • 中文

Objective

You can DIY an alarm clock here. It can wake you up at 7:00 in the morning and the way to stop it is to shout at it. If you struggle to wake up, it's indeed a great experience to abreact mood by shouting at your noisy alarm clock.

Principle

Equipment

Module Number Function
Microduino-CoreUSB 1 Core board
Microduino-Sensorhub 1 Sensor pin board
Microduino-Sound 1 Sound detection sensor
Microduino-BUZZER 1 Buzzer sensor
Microduino-RTC 1 Time clock module
Microduino-OLED 1 Display module
Microduino-BM 1 Battery management

Hardware Buildup

  • Setup 1:Connect the CoreUSB to the computer, open the program examples, select the right board and download the program.
  • Setup2:Connect the Sound to the A2 pin of the Sensorhub, the Buzzer to D6 and the OLED to IIC.
Microduino-sensorhub rule.JPG
  • Setup3:Connect the battery to the BM.

Software Debugging

Code Description

  • Define the control pin
#define buzzer_pin 6

int micPin = A2; 
int micValue=0;

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);//Define the connection method of the OLED
  • Initial value set of the clock
void initTime() {
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century(1=1900, 0=2000), year(0-99)
  rtc.setDate(11, 4, 6, 0, 15);
  //hr, min, sec
  rtc.setTime(13, 5, 0);
}
  • Set the time and the sound of the alarm clock. Here we set the alarm to 7:0 0am. It means the clock will start alarming at 7:00am and stop 5mins after that, which can also be interrupted if there is a shout at the alarm during that time (7:00am-7:05am).
void updateAlarm() {
  if(timeHH==7&&timeMM<5) {
      if(micValue>500) {
      isRoar=true;
    }
    if(isRoar) {
      noTone(buzzer_pin);
    } else {
      tone(buzzer_pin,500); //Out the frequency in the port.  
    }
  } else {
    isRoar=false;
    noTone(buzzer_pin);
  }
}

Program

[MicroduinoRoarAlarmClock]

Result

Every morning at 7:00, the alarm goes on and will last five minutes, during which time you can also interrupt it by shouting at the clock.

Video