Relógio Digital TM1637 com Configuração de Hora e Alarme – Prototipo Arduino Nano
Componentes e Materiais
- 1x Arduino Nano R3
- 1x Display TM1637 4 dígitos
- 1x Módulo RTC DS1302
- 1x LED Azul SparkFun LilyPad (5 pcs)
- 1x Buzzer
Sobre o Projeto
Este é um protótipo do mecanismo de configuração de hora e alarme que planejo usar em meus próximos projetos de relógio digital. Espero que você o ache útil. Se pensar em alguma melhoria, por favor me avise. Ficaria mais do que feliz em analisá-las e potencialmente incorporá-las ao meu código.
Você pode assistir ao tutorial completo em meu canal. Se você gosta deste conteúdo e quer me apoiar na criação de vídeos semelhantes, acesse minha página no Patreon: https://www.patreon.com/MariosIdeas ou PayPal.
Código
Exibindo hora do módulo RTC com funcionalidade de configuração de hora e alarme Arduino
Este código lê a hora atual do módulo RTC. Também permite atualizar a hora atual e configurar a hora do alarme. As ações de configuração são realizadas usando 3 botões.
// Mario's Ideas
// TM1637 Digital Clock with Setup and Alarm Functionality
#include <Arduino.h>
#include <TM1637Display.h>
#include <virtuabotixRTC.h>
// Módulo RTC
// PINOS CLK, DAT, RST
virtuabotixRTC myRTC(A1, A2, A3);
// Variáveis para armazenar valores anteriores lidos do RTC
int minutes;
int hours;
// Variáveis para armazenar a hora em que o alarme deve disparar
int Alarm_minutes = 05;
int Alarm_hours = 18;
uint8_t Blank[] = {0x0};
int POSITION = 0;
int digits[4];
int interval = 0;
#define Alarm 9
#define Buzer 13
#define Led 8
boolean Alarm_set = false;
boolean Alarm_in_progress = false;
boolean Setup_on = false;
#define CLK 4
#define DIO 5
TM1637Display clock(CLK, DIO);
void setup() {
attachInterrupt(digitalPinToInterrupt(2), Press_A_Button, RISING);
attachInterrupt(digitalPinToInterrupt(3), Press_B_Button, RISING);
pinMode(Alarm, INPUT);
pinMode(Buzer, OUTPUT);
pinMode(Led, OUTPUT);
digitalWrite(Buzer, LOW);
clock.setBrightness(0x0f);
Serial.begin(9600);
}
void Press_A_Button() {
if (interval > 3) {
if (Setup_on == false) {
Setup_on = true;
if (Alarm_set == true) {
digits[0] = (int)Alarm_hours / 10;
digits[1] = Alarm_hours - ((int)Alarm_hours / 10) * 10;
digits[2] = (int)Alarm_minutes / 10;
digits[3] = Alarm_minutes - ((int)Alarm_minutes / 10) * 10;
} else {
digits[0] = (int)myRTC.hours / 10;
digits[1] = myRTC.hours - ((int)myRTC.hours / 10) * 10;
digits[2] = (int)myRTC.minutes / 10;
digits[3] = myRTC.minutes - ((int)myRTC.minutes / 10) * 10;
}
} else {
POSITION++;
if (POSITION == 4) {
if (Alarm_set == true) {
Alarm_minutes = digits[3] + digits[2] * 10;
Alarm_hours = digits[1] + digits[0] * 10;
} else {
myRTC.setDS1302Time(0, digits[3] + digits[2] * 10, digits[1] + digits[0] * 10,
myRTC.dayofweek, myRTC.dayofmonth, myRTC.month, myRTC.year);
clock.showNumberDec(digits[0], false, 1, 0);
clock.showNumberDec(digits[1], false, 1, 1);
clock.showNumberDec(digits[2], false, 1, 2);
clock.showNumberDec(digits[3], false, 1, 3);
}
POSITION = 0;
Setup_on = false;
}
}
interval = 0;
}
}
void Press_B_Button() {
if (interval > 3) {
if (Setup_on) {
digits[POSITION] = digits[POSITION] + 1;
if (POSITION == 0 && digits[POSITION] == 3) digits[POSITION] = 0;
if (POSITION != 0 && digits[POSITION] == 10) digits[POSITION] = 0;
interval = 0;
}
}
interval = 0;
}
void loop() {
if (digitalRead(Alarm) == HIGH && Alarm_set == false) {
if (interval > 30) {
digitalWrite(Led, HIGH);
Alarm_set = true;
delay(300);
}
} else {
if (digitalRead(Alarm) == HIGH && Alarm_set == true) {
if (interval > 30) {
Alarm_set = false;
Alarm_in_progress = false;
digitalWrite(Led, LOW);
delay(300);
}
}
}
myRTC.updateTime();
if (Setup_on == true) {
clock.showNumberDec(digits[0], false, 1, 0);
clock.showNumberDec(digits[1], false, 1, 1);
clock.showNumberDec(digits[2], false, 1, 2);
clock.showNumberDec(digits[3], false, 1, 3);
delay(200);
clock.setSegments(Blank, 1, POSITION);
delay(200);
clock.showNumberDec(digits[0], false, 1, 0);
clock.showNumberDec(digits[1], false, 1, 1);
clock.showNumberDec(digits[2], false, 1, 2);
clock.showNumberDec(digits[3], false, 1, 3);
} else {
if (myRTC.minutes == Alarm_minutes && myRTC.hours == Alarm_hours && Alarm_set == true && Setup_on == false) {
Alarm_in_progress = true;
}
if (Alarm_in_progress) {
digitalWrite(Buzer, HIGH);
delay(1000);
digitalWrite(Buzer, LOW);
delay(1000);
}
if (myRTC.minutes != minutes) {
clock.showNumberDecEx((int)myRTC.hours / 10 * 1000 + (myRTC.hours - ((int)myRTC.hours / 10) * 10) * 100 +
(int)myRTC.minutes / 10 * 10 + myRTC.minutes - ((int)myRTC.minutes / 10) * 10,
(0x80 >> 1), true);
minutes = myRTC.minutes;
hours = myRTC.hours;
}
}
if (interval < 200) interval++;
}
Esquemáticos

Processo de manufatura
- Sensores Analógicos vs Digitais: Tipos, Aplicações e Exemplos Práticos
- Construa um Alarme de Água Headless para Raspberry Pi 2 com Adafruit T-Cobbler Plus
- Construa um Robô com Raspberry Pi e Python: Guia Completo
- Fiix e IDC Mostram Como a Transformação Digital Impulsiona a Confiabilidade na Manufatura
- Prevenindo Paradas Maiores: Como o Monitoramento por Emissão Acústica Salvou Tempo e Dinheiro de um Fabricante de Alimentos
- 8 Maneiras Comprovadas de Reduzir Custos de Manutenção e Aumentar a Receita com Software de Manutenção Digital
- Integrando Sensor Termopar com Arduino Portenta H7 usando CI MAX6675
- Acelerando Transformação Digital: Plataforma IoT Edge-to-Cloud da Cisco & IBM
- Construa um Relógio Despertador Confiável com RTC DS1302 e Arduino UNO
- Entendendo a Funcionalidade e Inovação de Rolamentos em Máquinas Modernas