Silícios LabPCBWay
Published © GPL3+

Real-Time Clock Battery Monitoring System

In this article, you will learn how to implement a feature to monitor the real-time clock battery and prevent problems in the circuit.

BeginnerFull instructions provided30 minutes8,454
Real-Time Clock Battery Monitoring System

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
wwww.pcbway.com
×1
Arduino UNO R3 - UTSOURCE
×1
LCD 16x2 Display - UTSOURCE
×1
Real Time-Clock Module - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Schematic Circuit

Code

Battery Voltage Monitor in Real Time Clock

Arduino
#include <LiquidCrystal.h>
#include <Wire.h> 
#include "RTClib.h" 
 
RTC_DS1307 rtc; 

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define tensao A0

bool ControlVbat1 = 0, ControlVbat2 = 0;

char WeekDays[7][12] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"};

void setup ()
{
  lcd.begin(16,2); 
  Serial.begin(9600); 
  if (! rtc.begin()) 
  {
    Serial.println("DS1307 não encontrado");
    while(1);
  }
  
  if (! rtc.isrunning()) 
  { 
    Serial.println("DS1307 rodando!"); 
    rtc.adjust(DateTime(2025, 6, 1, 15, 00, 00)); //Year, Month, Day, Minutes and Seconds
  }
  
  pinMode(tensao, INPUT);
}
 
void loop () 
{

    float Vbat = (5*(analogRead(tensao)))/1023;;
   
    DateTime now = rtc.now();

    lcd.setCursor(0,0);

    if(now.hour() < 10)
    {
     lcd.setCursor(0,0);
     lcd.print("0");
    }
    
    lcd.print(now.hour(), DEC );
    lcd.print(":");
    
    if(now.minute() < 10)
    {
     lcd.setCursor(3,0);
     lcd.print("0");
    }
    
    lcd.print(now.minute(), DEC);

    lcd.setCursor(8,0);
    lcd.print(now.day(), DEC );
    lcd.print("/");
    lcd.print(now.month(), DEC);
    lcd.print("/");
    lcd.print(now.year(), DEC);

    if(Vbat < 1.5 && ControlVbat1 == 0)
    {
      lcd.setCursor(0,1);
      lcd.print("                ");
      lcd.setCursor(2,1);
      lcd.print("Low Battery!");
      ControlVbat1 = 1;
      ControlVbat2 = 0;
    }
    
    Serial.println(Vbat);
    
    if(Vbat >= 1.5 && ControlVbat2 == 0)
    {
      lcd.setCursor(0,1);
      lcd.print("                ");
      lcd.setCursor(1,1);
      lcd.print("Voltage: ");
      lcd.print(Vbat);
      lcd.print("V");  
      ControlVbat1 = 0;
      ControlVbat2 = 1;
    }
    
}

Credits

Silícios Lab

Silícios Lab

72 projects • 173 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

90 projects • 146 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments