Alarm Clock

Hey! Do you want to learn how to create your very own alarm clock? Follow this step-by-step tutorial and you'll be able to do it easily. Have fun!

Obs.: This project was based on the alarm clock of the website "Mundo Projetado". Although, me and my group had to make some improvements. Here is the link to the original project: http://mundoprojetado.com.br/despertador-usando-o....

Step 1: Materials

To build the alarm clock, you'll need:

  • 1 computer;
  • 5 buttons;
  • 1 display;
  • 1 arduino;
  • 1 buzzer;
  • 1 potentiometer;
  • 1 USB cable;
  • 1 breadboard;
  • 7 resistors - their values must be 100, 300, 500, 700, 900, 1.1 k, 1.3 k or close;
  • 22 male-male jumper wires.

Step 2: Build Circuit 1

To build circuit 1, you'll need the display, the arduino, the potentiometer, 15 of the jumper wires and one of the resistors.

Follow the image and you should succeed!

Step 3: Build Circuit 2

To build circuit 2, you'll need all of the buttons, five of the jumper wires and the six remaining resistors.

Follow the image and you should succeed!

Step 4: Build Circuit 3

To build circuit 3, you'll need the buzzer, the arduino and the two remaining jumper wires.

Follow the images and you should succeed!

Step 5: The Code

First, you need to download the Arduino app (https://www.arduino.cc/en/Main/Software) and TimeLib (https://playground.arduino.cc/Code/Time). Then, you can copy and paste the code below in a new document in the Arduino app. Don't forget to upload the code!

Important: before you upload the code, don't forget to:

  • Check if you put the jumper wires in the right places of the arduino;
  • Connect the arduino to the computer.
#include <timelib.h><br></timelib.h>
#include 
<liquidcrystal.h>
LiquidCrystal lcd(12,11, 5, 4, 3, 2); // inicializa a biblioteca do display com os pinos de interface</liquidcrystal.h>
byte setaC[8] = { // simbolo da setinha na configuraçao
  B00100,
  B00100,
  B01110,
  B10101,
  B00100,
  B00100,
  B00100,
  B00100,
};
byte relogio[8] = { // simbolo do relogio
  B00000,
  B10001,
  B01110,
  B10101,
  B10111,
  B10001,
  B01110,
  B00000,
};
// Variaveis-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
String menu[3] = {"Mostrar horas", "Definir alarme", "Mudar as horas"}; // Frases do menu
char selec = 0; // Variavel do menu principal
int alarme[2] = {06, 00}; // Variavel do alarme
bool telap = true, telaa = false, telah = false, telac = false, espera = false, ativado = true; // Variaveis de controle das telas
//Musica do despertador------------------------------------------------------------------------------------------------------------------------------------------------------------------
char* musica[] = {"Re", "Mi", "Fa", "Sol", "Do", "La", "Fa", "Do", "Fim"}; //Game of Thrones
int duracao[] = {500, 500, 500, 500, 500, 500, 500, 500};
void tocar(char* mus[], int tempo[]);
int buz = 10; // Pino do Buzzer
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {
  // LIQUIDCRYSTAL
  lcd.createChar(2, relogio); // cria o desenho do relogio
  lcd.createChar(1, setaC); // cria o desenho do relogio
  lcd.begin(16, 2);
  // Relogio
  setTime(12, 00, 0, 1, 1, 2017); // Define hora/min/segundo - dia/mes/ano
  
  digitalWrite(A0, INPUT_PULLUP); // Seta o PULLUP no A0
  pinMode(buz, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  Serial.println(analogRead(A0));
  while (telap) { // Tela principal
    lcd.setCursor(0, 0); // Escreve as opçoes do menu
    lcd.print(menu[selec]);
    lcd.setCursor(0, 1);
    if (selec < 2) lcd.print(menu[selec + 1]);
    
    if (!espera && ativado) { // Simbolo do relogio caso o despertador esteja ativo
      lcd.setCursor(15, 0);
      lcd.write(2);
    }
    
    //--------------------------------------------Testa os botoes
    if (analogRead(A0) < 995 && analogRead(A0) > 985 && selec > 0) {
      selec--;  // Cima
      lcd.clear();
    }//lcd.setCursor(3,0); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(9,1); lcd.print(" ");}
    if (analogRead(A0) < 980 && analogRead(A0) > 970 && selec < 2) {
      selec++;  // Baixo
      lcd.clear();
    }
    if (analogRead(A0) < 850 && analogRead(A0) > 835) { //Select
      telap = false;
      if (selec == 0) telah = true; // Tela de horas
      if (selec == 1) telaa = true; // Tela do alarme
      if (selec == 2) telac = true; // Tela de configuracao
      lcd.clear();
    }
    Analise(); // Analisa se esta na hora de despertar
    delay(200);
  }
  //-----------------------------------------------------------------Tela Configuração do Relógio
  int d1 = hour(), d2 = minute(), pos = 0; // Variaveis para a tela de configuração
  while (telac) { 
    lcd.setCursor(5, 0);
    if (d1 < 10) lcd.print("0"); lcd.print(d1); lcd.print(":"); if (d2 < 10) lcd.print("0"); lcd.print(d2);
    if (pos == 0) {
      lcd.setCursor(6, 1);  //Indica a posiçao da setinha
      lcd.write(1);
    }
    if (pos == 1) {
      lcd.setCursor(8, 1);
      lcd.write(1);
    }
    //--------------------------------------------------------Testa os botoes
    if (analogRead(A0) < 995 && analogRead(A0) > 985) { //Cima
      if (pos == 0) if (d1 < 23) d1 ++;
      if (pos == 1) if (d2 < 60) d2 ++;
    }
    if (analogRead(A0) < 980 && analogRead(A0) > 970) { //Baixo
      if (pos == 0) if (d1 > 0) d1 --;
      if (pos == 1) if (d2 > 0) d2 --;
    }
    if (analogRead(A0) < 935 && analogRead(A0) > 925) if (pos < 1) {
        pos++;  //Direita
        lcd.setCursor(6, 1);
        lcd.print(" ");
      }
    if (analogRead(A0) < 920 && analogRead(A0) > 910) if (pos > 0) {
        pos--;  //Esquerda
        lcd.setCursor(6, 1);
        lcd.print(" ");
      }
    if (analogRead(A0) < 850 && analogRead(A0) > 835) { //Select
      setTime(d1, d2, 0, 11, 11, 2017);
      telac = false; telap = true; lcd.clear();
    }
    Analise(); //Analisa se esta na hora de despertar
    delay(100);
  }
  //-----------------------------------------------------------------Tela de Alarme
  d1 = alarme[0], d2 = alarme[1], pos = 0; //Variaveis para a tela de configuração
  int d3 = ativado;
  while (telaa) { 
    lcd.setCursor(0, 0);
    if (d1 < 10) lcd.print("0"); lcd.print(d1); lcd.print(":"); if (d2 < 10) lcd.print("0"); lcd.print(d2);
    lcd.setCursor(7, 0);
    if (d3) lcd.print("Ativado");
    if (!d3) {
      lcd.setCursor(6, 0);
      lcd.print("Desativado");
    }
    if (pos == 0) {
      lcd.setCursor(1, 1);  // Indica a posiçao da setinha
      lcd.write(1);
    }
    if (pos == 1) {
      lcd.setCursor(3, 1);
      lcd.write(1);
    }
    if (pos == 2) {
      lcd.setCursor(10, 1);
      lcd.write(1);
    }
    //--------------------------------------------------------Testa os botoes
    if (analogRead(A0) < 995 && analogRead(A0) > 985) { //Cima
      if (pos == 0) if (d1 < 23) d1 ++;
      if (pos == 1) if (d2 < 60) d2 ++;
      if (pos == 2) if (d3 < 1) {
          d3 ++;
          lcd.setCursor(6, 0);
          lcd.print(" ");
        }
    }
    if (analogRead(A0) < 980 && analogRead(A0) > 970) { //Baixo
      if (pos == 0) if (d1 > 0) d1 --;
      if (pos == 1) if (d2 > 0) d2 --;
      if (pos == 2) if (d3 > 0) d3 --;
    }
    if (analogRead(A0) < 935 && analogRead(A0) > 925) if (pos < 2) {
        pos++;  //Direita
        lcd.setCursor(0, 1);
        lcd.print(" ");
      }
    if (analogRead(A0) < 920 && analogRead(A0) > 910) if (pos > 0) {
        pos--;  //Esquerda
        lcd.setCursor(0, 1);
        lcd.print(" ");
      }
    if (analogRead(A0) < 850 && analogRead(A0) > 835) { //Select
      alarme[0] = d1;
      alarme[1] = d2;
      ativado = d3;
      telaa = false; telap = true; lcd.clear();
    }
    Analise(); // Analisa se esta na hora de despertar
    delay(100);
  }
  while (telah) { //-----------------------------------------------------------------Tela de horas
    lcd.setCursor(3, 0);
    lcd.print(getHour());
    if (!espera && ativado) { // Simbolo do relogio caso o despertador esteja ativo
      lcd.setCursor(15, 0);
      lcd.write(2);
    }
    if (analogRead(A0) < 850 && analogRead(A0) > 835) { //Select
      telah = false; telap = true; lcd.clear();
    }
    Analise();
    delay(500);
  }
  delay(300);
}
void Analise() { // Analisa se deu hora de despertar
  if (hour() == alarme[0] && minute() == alarme[1] && !espera && ativado) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("Segure select");
    lcd.setCursor(3, 1);
    lcd.print("para parar");
    while (!espera) {
      tocar(musica, duracao);
      if (analogRead(A0) < 790 && analogRead(A0) > 555) espera = true;
      delay(200);
    }
    lcd.clear();
  }
  if (espera && second() == 0 && ativado) {
    espera = false;
  }
}
String getHour() { // Retorna uma string com a hora h:m:s
  String saida = "";
  if (hour() < 10)
    saida += "0";
  saida += hour();
  saida += ":";
  if (minute() < 10)
    saida += "0";
  saida += minute();
  saida += ":";
  if (second() < 10)
    saida += "0";
  saida += second();
  return saida;
}
<p>void tocar(char* mus[], int tempo[]) {
  int tom = 0;
  for (int i = 0; mus[i] != "Fim"; i++) {
    if (mus[i] == "Do") tom = 262;
    if (mus[i] == "Re") tom = 294;
    if (mus[i] == "Mi") tom = 330;
    if (mus[i] == "Fa") tom = 349;
    if (mus[i] == "Sol") tom = 392;
    if (mus[i] == "La") tom = 440;
    if (mus[i] == "Si") tom = 494;
    if (mus[i] == "Do#") tom = 528;
    if (mus[i] == "Re#") tom = 622;
    if (mus[i] == "Fa#") tom = 370;
    if (mus[i] == "Sol#") tom = 415;
    if (mus[i] == "La#") tom = 466;
    if (mus[i] == "Pausa") tom = 0;
    tone(buz, tom, tempo[i]);
    delay(tempo[i]);
    if (analogRead(A0) < 995 && analogRead(A0) > 835) {
      espera = true;  // CONDIÇAO DO DESPERTADOR - Não tem relação com essa função
      break;
    }
  }
}</p>

Step 6: How to Use the Alarm Clock

Before you start actually using the alarm clock, there are a few things you should know:

  • The potentiometer is used to regulate the luminosity of the screen. Rotate it to see what's best for you;
  • To see the function of each button, check the second image above.

With that in mind, let's change the clock and set the alarm.

There are three options in the main menu: "Mostrar horas", "Definir alarme" and "Mudar as horas". To choose one, use the UP, DOWN and SELECT buttons. Firstly, you should go to "Mudar as horas" and change the time according to another clock or your cell phone, using the UP, DOWN, RIGHT, LEFT and SELECT buttons. Then, press SELECT to go back to the main menu. Now, go to "Definir alarme" to set the alarm. Using the LEFT, RIGHT and SELECT buttons, choose when you want the alarm to ring. When it does, the buzzer will ring until you press SELECT to stop it.

Go to https://drive.google.com/a/escolaeleva.com.br/fil.. to check out the alarm clock working!

Step 7: My Experience

Although we faced some challenges along the way, me and my group managed to overcome them all with the help of our teachers (and Google, of course :)

I think this was a very challenging project, but it was really fun to see it work!

I hope you have a great experience as well!

If you have any questions, suggestions of improvements, or anything you'd like to talk about, please leave a comment bellow!

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • Big and Small Contest

      Big and Small Contest
    • First Time Author

      First Time Author

    3 Discussions

    0
    None

    Nice design. And because you are using an Arduino you can have your clock activate any number of other devices too.

    1 reply