0% found this document useful (0 votes)
41 views

Real Time Clock DS1307

DS1307

Uploaded by

khoiphamvk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Real Time Clock DS1307

DS1307

Uploaded by

khoiphamvk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Real time DS1307

In this sketch, we will make a digital clock to display the real time(DS1307) and
temperature(LM35) in Serial monitor.

Hardware Required
 Arduino
 LM35
 DS1307
 Jump wire
 Breadboard

Theory
DS1307 RTC Module

The DS1307 can keep track of seconds, minutes, hours, days, dates, months, and
years. It can work in either a 12-hour or 24-hour format and has an AM/PM indicator.
For months with fewer than 31 days, it automatically adjusts the date at the end of the
month, including leap year corrections (valid up to 2100).

(DS1307 RTC IC, Backup Battery, Onboard 24C32 EEPROM)

LM35

The LM35 outputs the voltage linearly proportional to the Centigrade temperature.
The output scale factor of the LM35 is 10 mV/°C. It means that the temperature is
calculated by dividing the voltage (mV) in output pin by 10.

Install DS1307 Library In Arduino IDE: RTClib

Link: adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library (github.com)

OR you can import library like this:


If you received some error missing library, try to import this Adafruit_BuSio
Circuit
Let’s connect the RTC and LM35 to the Arduino.

Arduino DS1307
Arduino LM35
5V VCC
5V VCC
GND GND
A0 OUT
A4 SDA
GND GND
A5 SCL

(Block diagram and Circuit diagram shows the wire connection).

Code
// Date and time functions using a DS1307 RTC connected via I2C and
Wire lib
#include <RTClib.h>

// UNCHANGABLE PARAMATERS
#define SUNDAY 0
#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATURDAY 6
// event on Monday, from 13:50 to 14:10
uint8_t WEEKLY_EVENT_DAY = MONDAY;
uint8_t WEEKLY_EVENT_START_HH = 13; // event start time: hour
uint8_t WEEKLY_EVENT_START_MM = 50; // event start time: minute
uint8_t WEEKLY_EVENT_END_HH = 14; // event end time: hour
uint8_t WEEKLY_EVENT_END_MM = 10; // event end time: minute
const int sensorPin = A0;
float sensorValue;
float voltageOut;

float temperatureC;
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};

void setup () {
Serial.begin(9600);

// SETUP RTC MODULE


if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

// sets the RTC to the date & time on PC this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

// sets the RTC with an explicit date & time, for example to set
// January 21, 2021 at 3am you would call:
// rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0));

void loop () {
sensorValue = analogRead(sensorPin);
voltageOut = (sensorValue * 5000) / 1024;

// calculate temperature for LM35 (LM35DZ)

temperatureC = voltageOut / 10;


DateTime now = rtc.now();

printTime(now);
}
void printTime(DateTime time) {
Serial.print("TIME: ");
Serial.print(time.year(), DEC);
Serial.print('/');
Serial.print(time.month(), DEC);
Serial.print('/');
Serial.print(time.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[time.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(time.hour(), DEC);
Serial.print(':');
Serial.print(time.minute(), DEC);
Serial.print(':');
Serial.println(time.second(), DEC);

Serial.print("temperature: ");
Serial.println(temperatureC);
delay(5000);
}

Demonstrations
 After upload the Arduino, open the serial monitor to see the result.

 If the serial monitor print “Couldn’t find RTC”, check if the SDL pin and SCL pin
is connected to right position or not?

(Demonstrations with photos of experiments)


References
ds1307.pdf (analog.com)
In-Depth: Interface DS1307 RTC(Real Time Clock) Module with Arduino
(lastminuteengineers.com)
Cảm biến nhiệt độ LM35 và cách sử dụng nó trong môi trường Arduino | Cộng đồng
Arduino Việt Nam
Arduino - LM35 Temperature Sensor | Arduino Tutorial (arduinogetstarted.com)
RTClib: RTC_DS1307 Class Reference (adafruit.github.io)

You might also like