Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Creating a Digital Clock with Arduino

Importance and Utility of Digital Clocks

Digital clocks have become an essential part of our daily lives. They are used in various applications such as home appliances, offices, schools, and transportation systems. The accuracy and reliability of digital clocks make them a popular choice for timekeeping. Additionally, digital clocks can be easily integrated into other projects or systems, providing synchronized time information.

Project: Creating a Digital Clock

In this project, we will create a digital clock using an Arduino board. The clock will display the current time in hours, minutes, and seconds. It will also have the ability to adjust the time manually. The objectives of this project are to understand the basics of timekeeping with Arduino and to learn how to interface a display module for time output.

List of Components:

  • Arduino Uno board x1
  • DS1307 Real Time Clock (RTC) module x1
  • 16x2 LCD display module x1
  • Potentiometer (10k ohm) x1
  • Jumper wires
  • Breadboard

You can find these components at the following links:

  • Arduino Uno board: [link]
  • DS1307 RTC module: [link]
  • 16x2 LCD display module: [link]
  • Potentiometer: [link]

Examples:

Example 1: Displaying the Current Time

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS1307RTC.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Digital Clock");
}

void loop() {
  tmElements_t currentTime;
  if (RTC.read(currentTime)) {
    lcd.setCursor(0, 1);
    lcd.print("Time: ");
    lcd.print(currentTime.Hour);
    lcd.print(":");
    lcd.print(currentTime.Minute);
    lcd.print(":");
    lcd.print(currentTime.Second);
  }
  delay(1000);
}

Example 2: Manual Time Adjustment

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS1307RTC.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Digital Clock");
}

void loop() {
  tmElements_t currentTime;
  if (RTC.read(currentTime)) {
    lcd.setCursor(0, 1);
    lcd.print("Time: ");
    lcd.print(currentTime.Hour);
    lcd.print(":");
    lcd.print(currentTime.Minute);
    lcd.print(":");
    lcd.print(currentTime.Second);
  }

  if (Serial.available()) {
    String input = Serial.readStringUntil('\n');
    int newHour = input.substring(0, 2).toInt();
    int newMinute = input.substring(3, 5).toInt();
    int newSecond = input.substring(6, 8).toInt();
    RTC.adjust(DateTime(currentTime.Year, currentTime.Month, currentTime.Day, newHour, newMinute, newSecond));
  }

  delay(1000);
}

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.