top of page
Writer's pictureSanskruti Ashtikar

How to Create a Digital Clock in TinkerCAD


Introduction


A digital clock is a fundamental electronics project that combines timekeeping with digital displays. It’s a perfect project for learning how to use components like a 7-segment display or an LCD with a microcontroller like an Arduino. In this tutorial, we’ll walk you through creating a simple digital clock using TinkerCAD. This project will help you understand how to interface a microcontroller with a display and how to manage time within an Arduino sketch.





What You Will Need


To build this project in TinkerCAD, you’ll need the following components:

  • Arduino Uno R3

  • Breadboard (Small)

  • 4-digit 7-segment display (Common Cathode)

  • 8 x 220-ohm resistors (for segment current limiting)

  • 4 x 10k-ohm resistors (for common cathode grounding)

  • DS3231 Real-Time Clock (RTC) module

  • Jumper wires


Step 1: Setting Up the Breadboard and Arduino


  1. Open TinkerCAD: Log in to your TinkerCAD account and navigate to the "Circuits" section.

  2. Create a New Circuit: Click "Create new Circuit" to open the workspace where you’ll build the digital clock.

  3. Place the Breadboard and Arduino: Drag a small breadboard and an Arduino Uno R3 onto the workspace. Position them next to each other for easy wiring.


Step 2: Wiring the 4-Digit 7-Segment Display


  1. Place the 7-Segment Display: Drag a 4-digit 7-segment display onto the breadboard. Each digit on the display shares the same segment pins (A, B, C, D, E, F, G, and DP), but has separate common cathode pins for each digit (D1, D2, D3, D4).

  2. Connect Segment Pins: Connect each of the segment pins (A, B, C, D, E, F, G, and DP) through 220-ohm resistors to the digital pins on the Arduino (e.g., D2 to D9).

  3. Connect Common Cathode Pins: Connect each of the common cathode pins (D1, D2, D3, D4) through 10k-ohm resistors to four more digital pins on the Arduino (e.g., D10 to D13). This setup allows you to control which digit is currently active.

  4. Ground Connections: Connect the ground (GND) pin of the 7-segment display to the GND rail on the breadboard.





Step 3: Connecting the DS3231 RTC Module


  1. Place the RTC Module: Drag a DS3231 Real-Time Clock module onto the workspace.

  2. Power and Ground: Connect the VCC pin of the RTC module to the 5V rail on the breadboard and the GND pin to the ground (GND) rail.

  3. I2C Connections: Connect the SDA pin of the RTC module to the A4 pin on the Arduino and the SCL pin to the A5 pin. These pins are used for I2C communication.


Step 4: Writing the Code


  1. Open the Code Editor: Click on the "Code" button at the top right of the TinkerCAD interface to open the code editor.

  2. Choose Text-Based Coding: Switch to "Text" mode to write code in Arduino’s C/C++ language.

  3. Write the Code:

#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
int segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
int digitPins[] = {10, 11, 12, 13};
const byte digitToSegment[] = {
  0b00111111, // 0
  0b00000110, // 1
  0b01011011, // 2
  0b01001111, // 3
  0b01100110, // 4
  0b01101101, // 5
  0b01111101, // 6
  0b00000111, // 7
  0b01111111, // 8
  0b01101111  // 9
};


void setup() {
  Wire.begin();
  rtc.begin();
  for (int i = 0; i < 8; i++) {
    pinMode(segmentPins[i], OUTPUT);
  }
  for (int i = 0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
  }
  Serial.begin(9600);
}
void loop() {
  DateTime now = rtc.now();
  int hours = now.hour();
  int minutes = now.minute();
  int displayDigits[] = {
    hours / 10, hours % 10,
    minutes / 10, minutes % 10
  };
  for (int i = 0; i < 4; i++) {
    displayDigit(displayDigits[i], digitPins[i]);
    delay(5);
    clearDigits();
  }
}


void displayDigit(int digit, int digitPin) {
  for (int i = 0; i < 8; i++) {
    digitalWrite(segmentPins[i], bitRead(digitToSegment[digit], i));
  }
  digitalWrite(digitPin, LOW); // Activate digit
}
void clearDigits() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(digitPins[i], HIGH); // Deactivate all digits
  }


}
  1. Explanation of the Code:

  2. The RTC_DS3231 library is used to interface with the RTC module, which keeps track of the current time.

  3. The 7-segment display is controlled by turning on specific segments to form numbers. The code handles the multiplexing required to control multiple digits with a single set of segment pins.

  4. The displayDigit function lights up the appropriate segments to form each digit, and the clearDigits function ensures only one digit is displayed at a time.


Step 5: Simulating the Circuit


  1. Start Simulation: Click the "Start Simulation" button to see your digital clock in action. The display should show the current time, updated every second.

  2. Check the Serial Monitor: You can also open the Serial Monitor to see the current time printed out, which helps with debugging and ensures the RTC is working correctly.


Step 6: Fine-Tuning and Expanding


  • Adjusting Brightness: You can experiment with the resistor values to adjust the brightness of the LEDs on the 7-segment display.

  • Adding Features: Consider adding buttons for setting the time or displaying seconds. You could also use an LCD screen for a more advanced display or add an alarm feature.


Troubleshooting Tips


  • No Display? Double-check the wiring, especially the connections between the segment pins and the Arduino. Ensure the RTC module is properly connected to the I2C pins.

  • Incorrect Time? If the time is not displaying correctly, ensure the RTC module is functioning and properly set. You might need to manually set the time in the setup function using rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); the first time you run the code.

  • Simulation Issues? Ensure all components are correctly placed in TinkerCAD and that there are no loose connections. Also, make sure the libraries used in the code are supported in TinkerCAD’s environment.





Conclusion


You’ve successfully built a simple digital clock using TinkerCAD! This project not only helps you understand how to use a 7-segment display but also introduces you to the real-time clock (RTC) module, which is crucial for keeping accurate time in electronics projects. The skills you’ve learned here can be applied to more complex projects like alarm clocks, timers, or any other application that requires timekeeping.


TinkerCAD’s intuitive interface allows you to experiment with different components and configurations, making it an excellent platform for both learning and prototyping.

Feel free to expand on this project by adding more features, such as an alarm, temperature display, or using an LCD screen for a more advanced display.


Happy tinkering!


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



4 views0 comments

Related Posts

See All

Comments


bottom of page