Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Real-Time Clock with I2C LCD Display and IO Expansion

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Real-Time Clock with I2C LCD Display and IO Expansion

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with a DS1307 Real-Time Clock (RTC) module, a PCF8574 IO Expansion Board, and a 20x4 I2C LCD display. The purpose of this circuit is to display the current date and time on the LCD, which is fetched from the DS1307 RTC module. The PCF8574 IO Expansion Board is used to expand the I/O capabilities of the Arduino UNO.

Component List

Arduino UNO

DS1307 RTC (Wokwi Compatible)

PCF8574 IO Expansion Board

Lcd 20x4 i2c

Wiring Details

Arduino UNO

DS1307 RTC (Wokwi Compatible)

PCF8574 IO Expansion Board

Lcd 20x4 i2c

Code Documentation

// Programa : Modulo I2C Display e Modulo DS1307
// Autor : Arduino e Cia

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

// Modulo RTC no endereco 0x68
#define DS1307_ADDRESS 0x68

// Modulo I2C display no endereco 0x27
LiquidCrystal_I2C lcd(0x27,2,16);

byte zero = 0x00; 

// Faça caracteres personalizados: 
byte Square[] = {  B00000,  B11111,  B10001,  B10001,  B10001,  B10001,  B11111,  B00000};
byte Bell[] = { B00100, B01110, B01110, B01110, B11111, B00000, B00100, B00000 }; 
byte Right[] = { B00000, B01000, B01100, B01110, B01111, B01110, B01100, B01000 }; 
byte Check[] = { B00000, B00001, B00011, B10110, B11100, B01000, B00000, B00000 }; 
byte Speaker[] = { B00001, B00011, B01111, B01111, B01111, B00011, B00001, B00000 }; 
byte Sound[] = { B00001, B00011, B00101, B01001, B01001, B01011, B11011, B11000 }; 
byte Left[] = { B00000, B00010, B00110, B01110, B11110, B01110, B00110, B00010 }; 
byte Lock[] = { B01110, B10001, B10001, B11111, B11011, B11011, B11111, B00000 }; 

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  lcd.begin (16,2);
  
  //A linha abaixo pode ser retirada apos setar a data e hora
  //SelecionaDataeHora(); 

  // Crie novos personagens: 
  lcd.createChar(1, Square); 
  lcd.createChar(2, Bell); 
  lcd.createChar(3, Right); 
  lcd.createChar(4, Check); 
  lcd.createChar(5, Speaker); 
  lcd.createChar(6, Sound); 
  lcd.createChar(7, Left); 
  lcd.createChar(8, Lock); // 
}

void loop()
{
  // Le os valores (data e hora) do modulo DS1307
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int segundos = ConverteparaDecimal(Wire.read());
  int minutos = ConverteparaDecimal(Wire.read());
  int horas = ConverteparaDecimal(Wire.read() & 0b111111);
  int diadasemana = ConverteparaDecimal(Wire.read()); 
  int diadomes = ConverteparaDecimal(Wire.read());
  int mes = ConverteparaDecimal(Wire.read());
  int ano = ConverteparaDecimal(Wire.read());

  // Mostra os dados no display
  lcd.setBacklight(HIGH); // liga backlight
  lcd.setCursor(8,1);
  //lcd.print("     ");
  // Acrescenta o 0 (zero) se a hora for menor do que 10
  if (horas <10)
    lcd.print("0");
  lcd.print(horas);
  lcd.print(":");
  // Acrescenta o 0 (zero) se minutos for menor do que 10
  if (minutos < 10)
     lcd.print("0");
  lcd.print(minutos);

lcd.print(":");
  // Acrescenta o 0 (zero) se segundos for menor do que 10
  if (segundos < 10)
     lcd.print("0");
  lcd.print(segundos);
  
  lcd.setCursor(2,0);
  // Mostra o dia da semana
  switch(diadasemana)
    {
      case 0:lcd.print("Dom");
      break;
      case 1:lcd.print("Seg");
      break;
      case 2:lcd