On several systems that use time and date to perform certain tasks, it is critical to use real-time clock chips.

But one of the big problems is that it needs a battery to, keep the time and date count when the system is off.

On the computer, for example, we have a Real-Time Clock and when the battery is low voltage, the time and date are displayed with wrong values.

So, to solve this problem in projects, we can monitor the battery voltage.

Thus, when the battery is below a limit value, the system will generate an alarm in order to perform the exchange.

In this article, we will create a system to monitor the battery and generate an alarm for the user to change the battery.

To construct this project you'll need the following electronic components.

Supplies:

Project Development

In this project, we will create a complete system of configuration and presentation of the date and time. Our goal is to present only the date and hour and, mainly, to focus on monitoring the battery of the real-time clock.

With this monitoring, we will display its voltage value while the date and time are displayed on the LCD.

Case the voltage value is less than 1.5V, the system will alert the user, to inform a voltage low level of the battery.

Hereafter, we present the screen with an alert message of a low level of voltage in Figure 1.

1.jpg

Figure 1 - Screen with a message of the low level of voltage.

Now, we will present the step by step process to construct a simple project using Arduino UNO.

To construct this project, you need to use this circuit presented in Figure 2.

2.jpg

Figure 2 - Circuit Electronic Schematic to monitor the Battery Voltage.

Through this circuit, see that in the Real-Time Clock module have a pin named of VBat. With this pin, we connect in the analog pin AN0 to verify the battery voltage and to inform in LCD 16 x 2.

Now, see the project and we will learn how the code works. The code is presented below.

#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;  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;   }   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;   }
}    

In this code, we made the configs of LCD, Real Time Clock, its hour initializations and variable declaration.

        float Vbat = (5*(analogRead(tensao)))/1023;    

After this, the data and hours are collected from the real-time clock module. And so, its values are presented in the LCD 16x2.

 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(),...
Read more »