Introduction: Alarm Clock

Hi!! In my school, me and my friends made a project, an Alarm Clock! And now, you can have one made by YOU! All you need to do is follow this step-by-step tutorial! Make it happen!
Obs: The website “Mundo projetado” was a base for our project, check it out!

http://mundoprojetado.com.br/despertador-usando-o-...

Step 1:

First, you’ll need to know the materials needed:
-1 computer;

-5 buttons;

-1 buzzer;

- 1 potentiometer;

-1 display;

-22 male-male jumper wires;

-1 Arduino;

-1 USB cable;

-7 resistors - their values must be 100, 300, 500, 700, 900, 1.1k, 1.3k or close.

Step 2:

1 Step- Here we go! For our first step you’ll need your arduino, your potentiometer, the display, 15 male-male jumper wires and 1 resistor.
Make sure that your first step of the project is exactly like the picture.

Step 3:

2 Step- you’ll need your 5 buttons, 5 male-male jumper wires, and the rest of resistors.
Make sure that your second step of the project is exactly like the picture.

Step 4:

3 Step- you’ll need your buzzer, your arduino and 2 male-male jumper wires remaining.
Make sure that your third step of the project is exactly like the picture.

Step 5:

4 Step- Now the code! You need to download the Arduino App (https://www.arduino.cc/en/Main/Software) and TimeLib(https://playground.arduino.cc/Code/Time). Almost ready! You need to copy and paste the code below in a new document in Arduino App. You just need to upload the code now!
Before you upload, check if the wires are in the right place and the arduino is connected with the computer.

Step 6:

//PROJETO CRIADO PELO SITE MUNDO PROJETADO
// Acesse: www.mundoprojetado.com.br // Versão 1.0 de um despertador criado usando uma shield LCD16x2 e um buzzer // A versão 1.0 só pode configurar um despertador que fica constante a partir do momento que é ligado // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // PARA SAIR DE ALGUMA TELA BASTA APERTAR SELECT // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include

#include LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // inicializa a biblioteca do display com os pinos de interface

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 = 13; // 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); }

void loop() { 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) < 195 && analogRead(A0) > 50 && 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) < 380 && analogRead(A0) > 195 && selec < 2) { selec++; // Baixo lcd.clear(); } if (analogRead(A0) < 790 && analogRead(A0) > 555) { //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) < 195 && analogRead(A0) > 50) { //Cima if (pos == 0) if (d1 < 23) d1 ++; if (pos == 1) if (d2 < 60) d2 ++; } if (analogRead(A0) < 380 && analogRead(A0) > 195) { //Baixo if (pos == 0) if (d1 > 0) d1 --; if (pos == 1) if (d2 > 0) d2 --; } if (analogRead(A0) < 50) if (pos < 1) { pos++; //Direita lcd.setCursor(6, 1); lcd.print(" "); } if (analogRead(A0) < 555 && analogRead(A0) > 380) if (pos > 0) { pos--; //Esquerda lcd.setCursor(6, 1); lcd.print(" "); } if (analogRead(A0) < 790 && analogRead(A0) > 555) { //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) < 195 && analogRead(A0) > 50) { //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) < 380 && analogRead(A0) > 195) { //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) < 50) if (pos < 2) { pos++; //Direita lcd.setCursor(0, 1); lcd.print(" "); } if (analogRead(A0) < 555 && analogRead(A0) > 380) if (pos > 0) { pos--; //Esquerda lcd.setCursor(0, 1); lcd.print(" "); } if (analogRead(A0) < 790 && analogRead(A0) > 555) { //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) < 790 && analogRead(A0) > 555) { //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; }

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) < 790 && analogRead(A0) > 555) { espera = true; // CONDIÇAO DO DESPERTADOR - Não tem relação com essa função break; } } }

Step 7:

Thank you! If you wanna see the video that teach you how to use your new alarm clock, click in the link!

https://www.youtube.com/watch?v=8w9aUDJdpRA