Electronics by Manmohan Pal: Building a P10 RTC Clock with Arduino | Tutorial by Manmohan Pal

Building a P10 RTC Clock with Arduino | Tutorial by Manmohan Pal

Building a P10 RTC Clock with Arduino | Tutorial by Manmohan Pal



Description:

Building a P10 RTC Clock with Arduino | Tutorial by Manmohan Pal

In this step-by-step tutorial, learn how to build a P10 RTC (Real-Time Clock) using Arduino! In this project, I’ll guide you through the entire process of setting up a P10 LED matrix display and integrating it with a real-time clock module to create a functional clock display.

What you will learn in this tutorial:

  • How to connect a P10 LED matrix to an Arduino
  • Setting up and programming the RTC (Real-Time Clock) module
  • Displaying real-time time on the P10 matrix display
  • Tips and tricks for troubleshooting and optimizing your project

Materials you will need:

  • Arduino (e.g., Arduino Uno)
  • P10 LED Matrix
  • RTC (Real-Time Clock) Module
  • Jumper wires and breadboard
  • Power source for your Arduino

This project is perfect for Arduino enthusiasts looking to take on a fun and practical challenge. By the end of this video, you will have a working P10 RTC clock that you can display in your home, office, or workshop!

🔔 Don't forget to like, share, and subscribe for more awesome Arduino tutorials!


How to Make a P10 RTC Clock Using Arduino

In this tutorial, you'll learn how to build a real-time clock (RTC) using an Arduino and a P10 LED matrix display. This project will allow you to display the current time on the P10 matrix and showcase your Arduino skills.

Materials Required:

  1. Arduino (e.g., Arduino Uno, Nano, or Mega)
  2. P10 LED Matrix Module
  3. RTC Module (e.g., DS3231 or DS1307)
  4. Jumper Wires
  5. Breadboard
  6. Power Source for Arduino

Step-by-Step Guide

Step 1: Connect the Components

Before you start coding, let's first connect the components to your Arduino:

  1. Connect the P10 LED Matrix:

    • The P10 matrix has a lot of pins, but you only need a few for this project. Use a P10 to Arduino wiring diagram to connect the required pins.
    • For example:
      • VCC (P10) to 5V (Arduino)
      • GND (P10) to GND (Arduino)
      • A/B/C/D pins to the corresponding pins on your Arduino (usually pin 2, 3, 4, 5 for data transfer)
      • CLK and LAT to specific Arduino pins (you may use pins like 6 and 7)
  2. Connect the RTC Module (DS3231/DS1307):

    • VCC (RTC) to 5V (Arduino)
    • GND (RTC) to GND (Arduino)
    • SDA (RTC) to A4 (Arduino Uno) / SDA pin (on other Arduino models)
    • SCL (RTC) to A5 (Arduino Uno) / SCL pin (on other Arduino models)



Step 2: Install Necessary Libraries

To interact with the P10 matrix and the RTC module, we need to install the following libraries:

  1. Adafruit GFX Library – For managing the display.
  2. Adafruit LED Backpack Library – For controlling the P10 matrix.
  3. RTClib – To interface with the RTC module (e.g., DS3231/DS1307).

In Arduino IDE:

  1. Go to Sketch > Include Library > Manage Libraries.
  2. Search for Adafruit GFX and install it.
  3. Search for Adafruit LED Backpack and install it.
  4. Search for RTClib and install it.

Step 3: Write the Code

Here’s a simple example of how the code could look for displaying the current time on the P10 LED matrix:

//////////////////////////////////////////////////////////////////////////////////

/*

//---------------------------------------Arduino P10 Digital Clock------------------------------------
/*
#####################################################################################################################################################
#                                                                        #
# -RTClib.h : https://github.com/adafruit/RTClib                                                                                                     #
#                                                                                                                                                    #
#      Installation:                                                                                                                                 #
# Arduino Uno       DS1307                                                                                                                           #
#    A5 ---------> SCL                                                                                                                               #
#    A4 ---------> SDA                                                                                                                               #
#    5V ---------> VCC                                                                                                                               #
#   GND ---------> GND                                                                                                                               #
######################################################################################################################################################

######################################################################################################################################################
                                                                                                                                                 #
#      Installation:                                                                                                                                 #
# Arduino Uno    P10 Panel                                                                                                                           #
#    13 ---------> S / CLK                                                                                                                           #
#    11 ---------> R                                                                                                                                 #
#     9 ---------> nOE / OE                                                                                                                          #
#     8 ---------> L / SCLK                                                                                                                          #
#     7 ---------> B                                                                                                                                 #
#     6 ---------> A                                                                                                                                 #
#   GND ---------> GND                                                                                                                               #
#                                                                                                                                                    #
# The P10 panel can still turn on without 5V Power Input if it only uses one panel, but to increase brightness it must be added with 5V Power Input. #
# 5V Power Input must also be used if using more than one P10 Panel.                                                                                 #
######################################################################################################################################################
*/

//--------------------------------------------------------------------------------------Wire and RTC Library
#include <Wire.h>
#include "RTClib.h"
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------The SPI, DMD, TimerOne and Font libraries are used.
#include <SPI.h>      
#include <DMD.h>    
#include <TimerOne.h>  
#include "SystemFont5x7.h"
#include "Font_6x14.h" //-> This font only contains numbers from 0-9
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------Configuration P10
#define DISPLAYS_ACROSS 1 //-> Number of P10 panels used, side to side.
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
//--------------------------------------------------------------------------------------

RTC_DS1307 rtc; //-> RTC Declaration

//--------------------------------------------------------------------------------------Variables for time and date
int _day, _month, _year, _hour24, _hour12, _minute, _second, _dtw;
int hr24;
String st;
char nameoftheday[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char month_name[12][12] = {"January","February", "March", "April", "May", "June", "Jult", "August", "September", "October", "November", "December"};
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------Variable for Millis
const long interval = 1000; //-> Retrieve time and date data every 1 second
unsigned long previousMillis = 0;

const long interval_for_date = 75; //-> For scroll speed
unsigned long previousMillis_for_date = 0;
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------Variable to display hours and minutes
char hr_24 [3];
String str_hr_24;
char mn [3];
String str_mn;
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------ScanDMD()
void ScanDMD() {
  dmd.scanDisplayBySPI();
}

//--------------------------------------------------------------------------------------setup
void setup() {
  Serial.begin(115200);
  Serial.println("Arduino RTC DS1307");
  delay(1000);
 
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled (Set the time and date based on your computer time and date)
    // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //-> Set the time and date based on your computer time and date. If that doesn't work, use this line of code outside of "if (! rtc.isrunning())"
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  // following line sets the RTC to the date & time this sketch was compiled (Set the time and date based on your computer time and date)
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //-> Set the time and date based on your computer time and date. Use this line of code if it doesn't work in "if (! rtc.isrunning())"
  //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  // If the time and date are successfully set, then deactivate the code line (make the code a comment), then re-upload the code.
  // if not done then the time and date will return to the beginning when it was set when arduino is reset or restarted.

  Timer1.initialize(1000);          
  Timer1.attachInterrupt(ScanDMD);  
  dmd.clearScreen(true);  
}
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------loop
void loop() {
  //_____________________________________________________millis() to display time
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis; //-> save the last time

    GetDateTime(); //-> Retrieve time and date data from DS1307
   
    dmd.selectFont(Font_6x14);

    //=====================================================Showing the clock in P10
    str_hr_24=String(_hour24);
    str_hr_24.toCharArray(hr_24,3);

    if (_hour24<10) {
      dmd.drawString(0, 0, "0", 1, GRAPHICS_NORMAL);
      dmd.drawString(7, 0, hr_24, 1, GRAPHICS_NORMAL);
    }
    else {
      dmd.drawString(0, 0, hr_24, 2, GRAPHICS_NORMAL);
    }
    //=====================================================

    //=====================================================Showing ":" in P10
    if (_second %2 == 0) {
      dmd.drawFilledBox(15,3,16,4, GRAPHICS_OR);
      dmd.drawFilledBox(15,11,16,12, GRAPHICS_OR);
    }
    else {
      dmd.drawFilledBox(15,3,16,4, GRAPHICS_NOR);
      dmd.drawFilledBox(15,11,16,12, GRAPHICS_NOR);
    }
    //=====================================================

    //=====================================================Showing minutes in P10
    str_mn=String(_minute);
    str_mn.toCharArray(mn,3);

    if (_minute<10) {
      dmd.drawString(19, 0, "0", 1, GRAPHICS_NORMAL);
      dmd.drawString(26, 0, mn, 1, GRAPHICS_NORMAL);
    }
    else {
      dmd.drawString(19, 0, mn, 2, GRAPHICS_NORMAL);
    }
    //=====================================================

    //=====================================================Call the scrolling_date() subroutine to display the date.
    if (_second==11) { //-> Display the date when seconds equal to 11
      scrolling_date();
    }
    //=====================================================
  }
  //_____________________________________________________
}
//--------------------------------------------------------------------------------------

//------------------------------------------------------------------------Subroutine to retrieve or update the time and date from DS1307
void GetDateTime() {
  DateTime now = rtc.now();
  _day=now.day();
  _month=now.month();
  _year=now.year();
  _hour24=now.hour();
  _minute=now.minute();
  _second=now.second();
  _dtw=now.dayOfTheWeek();

  hr24=_hour24;
  if (hr24>12) {
    _hour12=hr24-12;
  }
  else if (hr24==0) {
    _hour12=12;
  }
  else {
    _hour12=hr24;
  }

  if (hr24<12) {
    st="AM";
  }
  else {
    st="PM";
  }  
}
//------------------------------------------------------------------------

//------------------------------------------------------------------------Subroutine to display days, months and years
void scrolling_date() {
  dmd.clearScreen(true);
  delay(100);

  //=====================================================Holds date data to display
  String Date = String(nameoftheday[_dtw]) + ", " + String(_day) + "-" + String(month_name[_month-1]) + "-" + String(_year);
  char dt[50];
  Date.toCharArray(dt,50);
  int i=32+10;
  int j=strlen(dt)+(strlen(dt)*5);
  //=====================================================

  dmd.selectFont(SystemFont5x7);

  while(1) {
    //_____________________________________________________millis() to display time
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis; //-> save the last time
     
      //=====================================================Showing the clock in P10
      str_hr_24=String(_hour24);
      str_hr_24.toCharArray(hr_24,3);
 
      if (_hour24<10) {
        dmd.drawString(2, 0, "0", 1, GRAPHICS_NORMAL);
        dmd.drawString(8, 0, hr_24, 1, GRAPHICS_NORMAL);
      }
      else {
        dmd.drawString(2, 0, hr_24, 2, GRAPHICS_NORMAL);
      }
      //=====================================================
     
      //=====================================================Showing ":" in P10
      GetDateTime(); //-> Retrieve time and date data from DS1307
      if (_second %2 == 0) {
        dmd.drawString(14, 0, ":", 2, GRAPHICS_OR);
      }
      else {
        dmd.drawString(14, 0, ":", 2, GRAPHICS_NOR);
      }
      //=====================================================
     
      //=====================================================Showing minutes in P10
      str_mn=String(_minute);
      str_mn.toCharArray(mn,3);
 
      if (_minute<10) {
        dmd.drawString(19, 0, "0", 1, GRAPHICS_NORMAL);
        dmd.drawString(25, 0, mn, 1, GRAPHICS_NORMAL);
      }
      else {
        dmd.drawString(19, 0, mn, 2, GRAPHICS_NORMAL);
      }
      //=====================================================
    }
    //_____________________________________________________

    //_____________________________________________________millis() for display & scrolling date
    unsigned long currentMillis_for_date = millis();
    if (currentMillis_for_date - previousMillis_for_date >= interval_for_date) {
      previousMillis_for_date = currentMillis_for_date; //-> save the last time
     
      i--;
      dmd.drawString(i, 9, dt, strlen(dt), GRAPHICS_NORMAL);
      if (i<=~j) {
        dmd.clearScreen(true);
        delay(100);
        return;
      }
    }
    //_____________________________________________________
  }
}
//------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////


Step 4: Upload the Code to Arduino

  1. Connect your Arduino to the computer via USB.
  2. Select the correct board and port under Tools > Board and Tools > Port.
  3. Click Upload to send the code to your Arduino.

Step 5: Test the RTC Clock

After uploading the code, the P10 LED matrix should start displaying the current time, updating every second. You should see something like 12:34 on the display.

Step 6: Troubleshooting

If you encounter issues, try the following:

  • Check wiring: Make sure the pins are correctly connected according to the diagram.
  • RTC not working: If the time is not being displayed correctly, ensure the RTC module is properly connected and powered.
  • Matrix not showing text: Double-check the library installation and matrix wiring.

Conclusion

You have successfully built a P10 RTC clock using Arduino! You can further customize the project by adding features like setting the time via buttons, using different displays, or adding additional functionalities such as alarms or temperature readings.


How to Build a Remote-Controlled RGB Seven-Segment Clock Seven segment LED Clock 1) How to Make Large RGB seven Segment Digit Internet Clock Part 1 by Manmohan Pal https://www.youtube.com/watch?v=KxhkELaH3aQ 2) Building an RGB Seven Segment LED Clock with 74hc595 Shift Register | Manmohan Pal's DIY Project https://www.youtube.com/watch?v=IGh_bX84h_Q 3) Large 7 segment LED clock 12 volt 6 digit Internet clock with date time and Alarm by Manmohan Pal https://www.youtube.com/watch?v=kup7MsJp-lY 4) How to make Large 7 Segment Digital Clock with RTC and Shift Register 74HC595 by Manmohan Pal https://www.youtube.com/watch?v=GXgH4jcbi0o 5) How to make LED clock using Arduino, 4 digit 7 segment LED digital clock DIY kit by Manmohan Pal https://www.youtube.com/watch?v=v14LN6b8WLw&t=28s 6) 6 Digit Seven Segment LED Clock with RTC by Manmohan Pal https://www.youtube.com/watch?v=UirHPF0TMsg 7)P10 Internet Clock using NodeMcu Esp8266 by Manmohan Pal https://www.youtube.com/watch?v=Y99YEBIsJfY 8) seven segment RTC alarm clock with date and time using Arduino Atmega328 https://www.youtube.com/watch?v=ccaB8ebgwvc 9) How to make 6 digit Seven segment Internet clock using Nodemcu Esp8266 and Shift Register IC 74HC595 https://www.youtube.com/watch?v=3tFGPuOlNZA 10) 12 digit Seven Segment clock with Date and Time using shift register ic and Nodemcu https://www.youtube.com/watch?v=c_EcSwTEIx8 11) P10 RTC Clock by Manmohan Pal https://youtu.be/GJ2orUOi8og

Youtube video Tags,

  • Arduino RTC Clock,
  • P10 Clock Tutorial,
  • Arduino P10 Project,
  • RTC Clock Arduino,
  • Arduino Time Clock,
  • P10 LED Clock,
  • Arduino Tutorial,
  • How to Make an RTC Clock,
  • Manmohan Pal Arduino,
  • Arduino P10 RTC Clock,
  • DIY Arduino Projects,
  • Real-Time Clock Arduino,
  • Arduino LED Clock,
  • P10 LED Matrix,
  • Arduino Electronics Project,

  • No comments:

    Post a Comment