Interfacing of RTC Module DS1307 with Arduino | Proteus Simulation
In today's lecture, we will discuss the Interfacing of RTC Module DS1307 with Arduino, we will design a Proteus Simulation.
Simulation tools such as Proteus Design Suite allow engineers and students to test and verify their designs virtually before implementing them in physical hardware. Using simulation, one can check the working of circuits, debug errors in code, and understand system behavior without the risk of damaging components. Proteus is particularly favored for simulating Arduino-based embedded projects because it provides a library of common microcontrollers, sensors, and display modules.
The DS1307 RTC module is widely used in embedded applications due to its simplicity and reliability. It communicates with microcontrollers like Arduino using the I2C protocol, which uses only two data lines: SDA (Serial Data) and SCL (Serial Clock).
- Seconds
- Minutes
- Hours
- Day of the week
- Date
- Month
- Year
- Operates at low voltage (typically 5V)
- Includes a battery backup to maintain time when the system is powered down
- Communicates with microcontrollers using the I2C protocol
- Maintains a 24-hour clock format
- Has internal registers to store time and calendar information
Arduino communicates with the DS1307 module through the I2C bus. The microcontroller sends a request to the module to read the current time and receives the data stored in the RTC registers. This data can then be displayed on an LCD, sent to other devices, or used to trigger time-based operations.
The following libraries are required:
- RTC DS1307 library for Proteus – enables the module to be used in the virtual Proteus environment.
- Arduino library for Proteus – facilitates I2C communication between Arduino and the RTC module.
- LCD library – used to interface and display data on an LCD.
- Download the required library files.
- Extract the downloaded ZIP or RAR folder.
- Copy the .LIB and .IDX files for Proteus.
- Paste these files into the Library folder of the Proteus installation directory.
- Restart Proteus.
After following these steps, the DS1307 RTC module will be available in the component library for use in circuit design.
- Open Proteus Design Suite.
- Click Pick Devices (P).
- Search for Arduino Uno.
- Select and place the Arduino on the workspace.
- Click Pick Devices.
- Search for DS1307 RTC Module (ensure library is installed).
- Place it on working area.
- Click Pick Devices.
- Search for LM044L (20x4 LCD
- Place it next to the RTC and Arduino.
- Click Pick Devices.
- Search for POT-HG.
- Place it near the LCD.
- This will allow contrast adjustment for the display.
- Select Terminal Mode in Proteus.
- Add 5V and GND.
- Place them appropriately in the workspace.
Making Connections in Proteus
- Connect VCC of RTC to 5V, GND to GND.
- Connect SDA to A4, SCL to A5 on Arduino.
- Connect LCD pins as per the table above.
- Connect potentiometer sides to 5V and GND, middle pin to LCD VO.
- Ensure all wires are neatly routed to avoid confusion during simulation.
- Open the new project in Arduino IDE.
- Paste the code there:
- Hit the run button and wait for the loading.
- Copy the hex file address:
- Got to the circuit and click on Arduino.
- Paste the file address here:
- Click OK.
- Run the circuit to test.
- Wire.h library allows Arduino to communicate with I2C devices, such as the DS1307 RTC.
- LiquidCrystal.h is used to interface the LCD with Arduino.
- RTClib.h is a dedicated library for working with the DS1307 module and simplifies reading and writing time and date information.
2. LCD and RTC Initialization
The RTC_DS1307 rtc; object creates an interface to communicate with the RTC module.- LiquidCrystal lcd(...) sets the Arduino pins connected to the LCD (RS, E, D4-D7).
- Using a 4-bit mode reduces the number of pins needed on Arduino while still providing full functionality of the LCD.
This array helps display the day name instead of a numeric value.- The dayOfTheWeek() function from RTClib returns a number (0–6), which is then mapped to a day string from this array.
4. Setup Function
lcd.begin(20, 4); initializes the LCD with 20 columns and 4 rows.- Wire.begin(); starts I2C communication.
- RTC check: If the RTC module is not detected, the code displays an error and stops execution (while(1);).
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); sets the RTC time to match the time when the Arduino code is compiled. This is optional if you want the RTC to maintain time independently.
- DateTime now = rtc.now(); retrieves the current time and date from the RTC module.
- The LCD displays:
- Day of the week on row 0
- Date on row 1 in DD/MM/YYYY format
- Time on row 2 in HH:MM:SS format
- delay(500); updates the LCD every 0.5 seconds to provide near-real-time information.
6. Helper Function for Formatting Digits
- Ensures single-digit numbers are prefixed with 0 for proper time formatting.
- For example, 7:5:3 becomes 07:05:03 on the LCD.
Step 1: Open Arduino IDE
- Open Arduino IDE and paste the RTC code above.
Step 2: Verify the Code
- Click the Verify (✔) button to compile the code.
- Ensure there are no errors.
Step 3: Enable Verbose Output
- Go to File → Preferences
- Enable Show verbose output during compilation
- Click OK.
Step 4: Locate the HEX File
- Compile the code again.
- Scroll the output console to find a line ending with .hex.
- This is your compiled Arduino program ready for Proteus simulation.
- Double-click on Arduino in Proteus.
- In the Arduino properties, paste the path to your HEX file.
- Click OK.
- Click Play in Proteus.
- Adjust the potentiometer to see the LCD contrast change.
- The LCD will display the day, date, and time in real-time.
- Timekeeping by Crystal Oscillator
- The DS1307 uses a 32.768 kHz crystal oscillator for accurate time measurement.
- I2C Communication
- Arduino communicates with the RTC using SDA and SCL lines.
- Reading Time
- Arduino sends a request to the RTC.
- The RTC responds with current seconds, minutes, hours, date, month, year, and day of the week.
- Battery Backup
- Even if Arduino is powered off, the RTC keeps time using a CR2032 battery.
- Displaying Time
- Arduino converts raw data to readable format.
- The formatted data is displayed on a 20x4 LCD.
1. Digital Clocks and Wall Timers
- Simple digital clocks use DS1307 for accurate time display.
- In wall timers, RTC ensures correct switching of devices at scheduled times.
2. Data Logging Systems
- RTC is crucial in data loggers for industrial or laboratory use.
- Records date and time of sensor measurements.
- Enables tracking environmental parameters over time.
- Home or industrial alarms depend on precise time triggers.
- RTC modules ensure alarms are activated at the correct time.
4. Time-based Automation
- In smart irrigation, RTC triggers pumps at set times.
- In lighting automation, RTC turns lights on/off based on time.
5. Attendance Systems
- RTC provides accurate timestamps for employee attendance.
- Integrated with RFID or biometric systems for reliable time logging.
- RTC modules are used in factories for automation schedules.
- Machines start and stop at precise times without human intervention.
- Microwave ovens, washing machines, and coffee makers use RTC for scheduling operations.
- IoT devices use RTC to timestamp events.
- For instance, smart sensors log temperature, humidity, or motion with exact timestamps.
- Surveillance cameras use RTC to timestamp footage.
- Ensures proper time tracking for recording and reviewing security events.
- RTC can trigger bells, displays, or announcements according to a schedule.

Discussie (0 opmerking(en))