Arduino - Relógio LCD
Neste tutorial, vamos aprender a fazer um relógio LCD:
- Lendo a data e a hora do módulo RTC DS3231 e mostrando-as em um LCD I2C 16x2
- Lendo a data e a hora do módulo RTC DS1307 e mostrando-as em um LCD I2C 16x2
Você pode escolher um dos dois módulos RTC: DS3231 ou DS1307. Veja DS3231 vs DS1307
Hardware Necessário
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Divulgação: Alguns dos links desta seção são links de afiliado da Amazon. Podemos receber uma comissão pelas compras feitas por meio desses links, sem custo adicional para você. Agradecemos o seu apoio.
Buy Note: Alternatively, you can assemble the LCD I2C display using LCD 1602 Display and PCF8574 I2C Adapter Module.
Sobre o LCD e os módulos RTC DS3231 e DS1307
Se você ainda não conhece o LCD, o DS3231 e o DS1307 (pinagem, como funcionam, como programar...), aprenda sobre eles nos tutoriais a seguir:
Instalar as Bibliotecas de LCD e RTC
- Vá até o ícone Libraries na barra à esquerda do Arduino IDE.
- Pesquise “DIYables LCD I2C” e encontre a biblioteca DIYables_LCD_I2C da DIYables
- Clique no botão Install para instalar a biblioteca DIYables_LCD_I2C.

- Pesquise “RTClib” e encontre a biblioteca RTC da Adafruit. Esta biblioteca funciona tanto com o DS3231 quanto com o DS1307
- Clique no botão Install para instalar a biblioteca RTC.

- Pode ser que seja pedido para você instalar algumas outras dependências de biblioteca
- Clique no botão Install All para instalar todas as dependências de biblioteca.

Lendo a hora do módulo RTC DS3231 e mostrando-a no LCD
Diagrama de Ligação

This image is created using Fritzing. Click to enlarge image
Código Arduino - DS3231 e LCD
/*
* Este código de Arduino foi desenvolvido por pt.newbiely.com
* Este código de Arduino é disponibilizado ao público sem nenhuma restrição.
* Para tutoriais completos e diagramas de ligação, visite:
* https://pt.newbiely.com/tutorials/arduino/arduino-lcd-clock
*/
#include <DIYables_LCD_I2C.h>
#include <RTClib.h>
DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
// SETUP RTC MODULE
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (true)
;
}
// automatically sets the RTC to the date & time on PC this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = rtc.now();
int year = now.year();
int month = now.month();
int day = now.day();
int hour = now.hour();
int minute = now.minute();
int second = now.second();
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("Date: ");
lcd.print(year);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(day);
lcd.setCursor(0, 1); // start to print at the second row
lcd.print("Time: ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
delay(1000); // Update every second
}
Passos Rápidos
- Copie o código acima e abra no Arduino IDE
- Clique no botão Upload no Arduino IDE para carregar o código no Arduino
- Veja o resultado no LCD
Lendo a hora do módulo RTC DS1307 e mostrando-a no LCD
Diagrama de Ligação

This image is created using Fritzing. Click to enlarge image
Código Arduino - DS1307 e LCD
/*
* Este código de Arduino foi desenvolvido por pt.newbiely.com
* Este código de Arduino é disponibilizado ao público sem nenhuma restrição.
* Para tutoriais completos e diagramas de ligação, visite:
* https://pt.newbiely.com/tutorials/arduino/arduino-lcd-clock
*/
#include <DIYables_LCD_I2C.h>
#include <RTClib.h>
DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
// SETUP RTC MODULE
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (true)
;
}
// automatically sets the RTC to the date & time on PC this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = rtc.now();
int year = now.year();
int month = now.month();
int day = now.day();
int hour = now.hour();
int minute = now.minute();
int second = now.second();
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("Date: ");
lcd.print(year);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(day);
lcd.setCursor(0, 1); // start to print at the second row
lcd.print("Time: ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
delay(1000); // Update every second
}
Passos Rápidos
- Copie o código acima e abra no Arduino IDE
- Clique no botão Upload no Arduino IDE para carregar o código no Arduino
- Veja o resultado no LCD