Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
RTC Module
Introduction: The RTC (Real-Time Clock) module is an essential component in many electronic projects. It provides accurate time and date information, even when the main power source is turned off. This article aims to explain the importance and usefulness of the RTC module and provide examples of code snippets and a list of components used in those examples.
Project: In this project, we will create a digital clock using an Arduino board and an RTC module. The objective is to display the current time and date on an LCD screen. The clock will also have functionalities such as setting the time and date, as well as an alarm feature. This project can be useful for various applications, including home automation systems, data logging, and time-sensitive projects.
Components List:
Examples: Example 1: Displaying Time and Date on LCD
#include <Wire.h>
#include <Adafruit_RTClib.h>
#include <LiquidCrystal_I2C.h>
Adafruit_RTClib rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin(16, 2);
lcd.print("Time: ");
lcd.setCursor(0, 1);
lcd.print("Date: ");
rtc.begin();
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(6, 0);
lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
lcd.setCursor(6, 1);
lcd.print(now.day());
lcd.print("/");
lcd.print(now.month());
lcd.print("/");
lcd.print(now.year());
delay(1000);
}
Example 2: Setting Time and Date using Buttons
#include <Wire.h>
#include <Adafruit_RTClib.h>
Adafruit_RTClib rtc;
const int setButtonPin = 2;
const int incButtonPin = 3;
const int decButtonPin = 4;
void setup() {
pinMode(setButtonPin, INPUT_PULLUP);
pinMode(incButtonPin, INPUT_PULLUP);
pinMode(decButtonPin, INPUT_PULLUP);
rtc.begin();
}
void loop() {
DateTime now = rtc.now();
if (digitalRead(setButtonPin) == LOW) {
// Enter time setting mode
// Use incButtonPin and decButtonPin to adjust time and date
}
// Rest of the code to display time and date on LCD
}