ESP32-RTC (Real Time Clock)
Aim:
To display Date
and Time on the serial monitor using ESP 32 microcontroller development board.
Description:
Interfacing
Real Time Clock module with ESP 32 to display date and time on the serial
monitor.
Hardware
required:
ESP32-Microcontroller Development board
Pin connection:
Pin
Mapping:
RTC
|
ESP32
|
SDA
|
I021
|
SCL
|
I022
|
Procedure:
1.
The above pin connection shows how
to display date and time using RTC in ESP32 board.
2.
Do the connections as shown in the pin diagram and
pin mapping.
3.
Connect the USB cable to the board.
4.
Open Arduino IDE .Select DOIT ESP32 DEVKIT V1in
boards and select COM port.
5.
Verify the program and Upload it.
6.
Open the serial monitor to observe the output.
Program:
/* Date and time functions using a DS1307 RTC connected
via I2C and Wire lib */ #include<Wire.h>
#include"RTClib.h" RTC_DS1307RTC;
charrec;
void setup(void)
{
Serial.begin(9600);
Wire.begin();
RTC.begi n();
delay(1000);
//while(!Serial.available());
//{
// rec=Serial.read();
// if(rec=='2')
/* This line sets the RTC with an explicit
date & time, for example to set January 16, 2019 at 12.32pm you would call:
rtc.adjust(DateTime(2019, 1, 16, 12, 32, 45))
*/
RTC.adjust(DateTime("Mar 22 2019","10:32:45"));
//}
}
void loop(void)
{
/*Getting the current Time and storing it into a DateTime
object */ DateTimenow=RTC.now();
Serial.print(now.year(),DEC);
Serial.print('/'); Serial.print(now.month(),DEC);
Serial.print('/'); Serial.print(now.day(),DEC); Serial.print(' ');
Serial.print(now.hour(),DEC);
Serial.print(':'); Serial.print(now.minute(),DEC);
Serial.print(':'); Serial.print(now.second(),DEC);
Serial.println();
delay(1000);
}