Arduino RTC LED clock



Arduino LED (RTC) Clock with Seconds and AM/PM indicator , 12/24 hr changing switch





First You have to download following libraries (link is given end of this page)

1. Wire.h
2. RTClib.h


Parts List





Watch the video




This is the RTC clock Module


This is the Arduino Circuit


RTC Wiring Connections




RTC Switches



Circuit Diagram (COMMON ANODE)

IF YOU USE COMMON CATHODE LED DO THE CHANGES AS FOLLOWS


POWER SUPPLY


Download Code File


Download Library Files





This is the code



/*
 4 digit 7 segment display: http://www.sparkfun.com/products/9483
 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
  */
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
// Code modified by BMIAK Basnayaka
// http://www.arduinomyprojects.blogspot.com

int digit1 = 11; 
int digit2 = 10;
int digit3 = 9; 
int digit4 = 6;
int digit5 = 5; 
int digit6 = 3; 

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 0; //Display pin 11
int segB = 1; //Display pin 7
int segC = 2; //Display pin 4
int segD = 4; //Display pin 2
int segE = 7; //Display pin 1
int segF = 8; //Display pin 10
int segG = 12; //Display pin 5
int segDP =13; // Display pin 3



#include < Wire.h >
#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm



byte SW0 = A0;
byte SW1 = A2;
byte SW2 = A1;
byte SWT = A3;
int Adhr=0;
int Admnt=0;
int D = 0;
int Z =0;

// use for hexa in zecimal conversion
long zh, uh, ore;
long zm, um, miniti;

void setup() {
  
 //Serial.begin(57600);
  Wire.begin();
  RTC.begin();
 // RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
// if you need set clock... just remove // from line above this

// part code for flashing LED
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
// Wire.write(0x00); // turns the SQW pin off
 Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
// Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

Wire.endTransmission();
  
  
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(digit5, OUTPUT);
  pinMode(digit6, OUTPUT);


//Serial.begin(9600);

pinMode(SW0, INPUT);  // N.O. push button switch
pinMode(SW1, INPUT);  // N.O. push button switch
pinMode(SW2, INPUT);  // N.O. push button switch
pinMode(SWT, INPUT);  // N.O. push button switch

digitalWrite(SW0, HIGH); // pull-ups on
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
digitalWrite(segDP, LOW);


}


void loop() {

  DateTime now = RTC.now();
  long HR = now.hour()*1000;
  long timp = (HR*10)+now.minute()*100+now.second();
  Adhr = now.hour();
  Admnt=now.minute();

int DIM = 0;

//------------------------------------------------------
//12/24 hours shitching 
//------------------------------------------------------
if (timp < 130000){
digitalWrite(segDP, LOW);}


if (digitalRead(SWT)==0){delay(300);
 if (D == 0) {
 D =1;delay(200);}
 
else{
D =0;}
}

if (D == 0){  
if (timp>=130000)
timp=timp-120000;
}

if ((D == 1)& (timp>=130000) ){ 
digitalWrite(segDP, LOW);}
else
{digitalWrite(segDP, HIGH);
}
//------------------------------------------------------


  



//int timp = (now.minute(), DEC);
//   displayNumber(12); // this is number to diplay


     
    for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber01(timp); 
     else displayNumber02(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber03(timp); 
     else displayNumber04(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber05(timp); 
     else displayNumber06(timp); 
   } 




  

if (digitalRead(SW0)==0){delay(100);Z=1;  set_time(); }// hold the switch to set time
}





void set_time()   {
  byte minutes1 = 0;
  byte hours1 = 0;
  byte minutes = 0;
  byte hours = 0;
  hours=Adhr;
  minutes=Admnt;

   // zh = hours / 16;
   // uh = hours - 16 * zh ;
   //ore = 10 * zh + uh; 
    //zm = minutes / 16;
    //um = minutes - 16 * zm ;
    //miniti = 10 * zm + um; 

    if ((hours & 0x0f) > 9) hours =  hours + 6;
      //Serial.print(hours & 0x0f);
      //Serial.print(hours);
      if (hours > 0x23) hours = 0;

        if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      //Serial.println(minutes & 0x0f);
     // Serial.println(minutes);
      if (minutes > 0x59) minutes = 0;
      
while (!(Z==0)){ // set time switch must be released to exit


 


    
   int TST = digitalRead(SW2);
    while (TST==0) // set hours
    { 
     hours++;          
     
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
     for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
   
      
      if ((hours & 0x0f) > 9) hours =  hours + 6;
      //Serial.print(hours & 0x0f);
      //Serial.print(hours);
      if (hours > 0x23) hours = 0;
      //Serial.print("Hours = ");
      if (hours <= 9) //Serial.print("0");
      //Serial.println(hours, HEX);
    delay(1);
    TST = digitalRead(SW2);
    }

   while (!(digitalRead(SW1))) // set minutes
    { 
     minutes++;  
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
     for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }

      //Serial.println(minutes);
      if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      //Serial.println(minutes & 0x0f);
     // Serial.println(minutes);
      if (minutes > 0x59) minutes = 0;
      //Serial.print("Minutes = ");
      if (minutes >= 9) //Serial.print("0");
      //Serial.println(minutes, HEX);
    delay(1);    
    }

    Wire.beginTransmission(0x68); // activate DS1307
    Wire.write(0); // where to begin
    Wire.write(0x00);          //seconds
    Wire.write(minutes);          //minutes
    Wire.write(0x80 | hours);    //hours (24hr time)
    Wire.write(0x06);  // Day 01-07
    Wire.write(0x01);  // Date 0-31
    Wire.write(0x05);  // month 0-12
    Wire.write(0x09);  // Year 00-99
    Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7. 
    Wire.endTransmission();
  
    // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 

 
    
    for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
delay(100); 
Serial.print(digitalRead(SW0));
if (digitalRead(SW0)==0) Z = 0;
 delay(300);   
  }
//Serial.print(SW2);
}



void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     //digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
      
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 


     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 

void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     //digitalWrite(segDP, HIGH);
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
     case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 

void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     //digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 

void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     //digitalWrite(segDP, HIGH);
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 

void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     //digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 

void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     //digitalWrite(digit1, DIGIT_ON);
     //digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 5:
      digitalWrite(digit5, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    case 6:
      digitalWrite(digit6, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
}
} 
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // all segment are ON
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  }
// End of the coding, BUDHUSARANAI, Best of luck.
  
}







165 comments:

  1. Code does not compile, there are wrong

    Line==Wire.beginTransmission(0x68); // activate DS1307

    ReplyDelete
  2. please help circuit diagram DS1307 pin connection Atmega328p

    ReplyDelete
    Replies
    1. sorry for my mistake,
      SCL pint to Analog pin 05
      SDA pint to Analog pin 04
      +5 to volt 5
      GND to Ground.
      ignore the other pin

      Delete
    2. This LED use common anode or cathode??

      Delete
  3. Replies
    1. But according to your diagram it is common cathode

      Delete
  4. Please give me your whatsapp number. I have to discuss to you some doubts with picture

    ReplyDelete
  5. The code is uploded to arduino. But arduino pin13 blinks everytime. Is there a error in code

    ReplyDelete
    Replies
    1. Few people had tried this and worked. There may be some mistakes with your wiring. you can upload your pictures to the following link. https://web.facebook.com/easymadescom

      Delete
  6. If I used common cathode will it work?.if we disconnect RTC pins from Arduino what will happened.I have used Arduino nano and tiny RTC module .I have told you I my previous comment that I uploaded the code to Arduino nano and Arduino pin 13 blinks. Arduino pin12 never gets on.in your diagram pin12 is connected to central segment of led display.is tiny RTC module not comfortable for this project.l have spent a lot of money for this project .so you please respond me fast.

    ReplyDelete
    Replies
    1. If you can use common anode this will be a easy project. Since it is used LEDs it is not a matter to use common anode.
      Yes, even though you have used common cathode you can work with it. But you have to change the codes. Therefore I recommend to use as described in this post common anode.
      RTC module is the memory chip, if you disconnect the wire clock with stop working but it will display some digits. LED on RTC should BLINK once a second. If the IC number is same, tiny RTC module is also work with this. But I can not recommend Arduino mini or Arduino nano for this project.

      Delete
  7. Sir,I think there is a mistake in display circuit.in first picture there are 6 NPN transistors to connect with 7 cathode pins.l think the second transistor circuit is for common anode and the first transistor circuit with led circuit is for common cathode.an I right?

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. I'm can't downlod original code from link above.
    And how wiring dot point?

    ReplyDelete
    Replies
    1. You can use LED on RTC module and link is updated.

      Delete
  11. Is Arduino nano comfortable to this project?.if no why?.

    ReplyDelete
    Replies
    1. I did not have check it yet whether or not support particular libraries with arduino nano.

      Delete
  12. How did you programmed the chip.using FDTI?

    ReplyDelete
    Replies
    1. No, Since arduino uno has inbuilt programming unit you may not need a FDTI. But if you use arduino mini then you may need FDTI.

      Delete
  13. Please add a video that explain the working of RTC switches

    ReplyDelete
  14. No,l meant the time editing switches

    ReplyDelete
    Replies
    1. Editing switchers are used to adjust the time. If you want to adjust the time 1st press “Editing Activator” switch. Then all the LEDs will start to blink. Then you can change HOURs or Minutes by pressing “Hour” and “Minutes” buttons. 12/24 button will change time mode as 24 hours clock or 12hours clock.

      Delete
  15. Common anode means all positive pin of every segment is connected together?

    ReplyDelete
  16. Which did you use in your project,common cathode or common anode?

    ReplyDelete
  17. LED on 7th pin(sqw) of ds1307 RTC is not blinking.now I didn't connect the RTC with Arduino.is the LED only blink after connecting with Arduino?.The led is Everytime on without connecting to Arduino.

    ReplyDelete
  18. Yes.i connected the Battery.But I didn't connect the SDA and SCL pin to Arduino.

    ReplyDelete
  19. Should I program the DS1307 to get 1hz output on SQW pins?

    ReplyDelete
    Replies
    1. No need to program separately. that is why 32Mhx crystal is included.

      Delete
  20. Replies
    1. But remember this, RTC module's battery is only for keeping memory. LED blink only when that circuit is powered 5V to VCC pin.

      Delete
  21. Should I connect the RTC to Arduino when the code is uploading?

    ReplyDelete
    Replies
    1. Yes, then PC time will be uploaded to the RTC module.

      Delete
  22. What will be showing in serial monitor of Arduino ide?

    ReplyDelete
    Replies
    1. I have stopped printing data by "//" on Serial Monitor. If you can see "0" or "1" on serial monitor which means that you have pushed or releases SW0 switch. having removed "//", you can see hours, minutes and seconds accordingly.

      Delete
  23. In my PC the serial monitor running these symbols //()'""[]\

    ReplyDelete
    Replies
    1. If you want to get data from serial monitor find "//Serial.begin(9600);" command and delete "//" marks and upload.

      Delete
  24. In common Anode transistor circuit the Anode of LED is connected to Collector of NPN transistor and Cathode of the LED is connected to Collector of PNP transistor.That means Anode of LED to GND and Cathode of LED to 5v?pls clarify.

    ReplyDelete
    Replies
    1. There is a small correction on LED wiring, I marked it by red colour. Yes you are correct.

      Delete
  25. Hi sir.my project is working.But the brightness of some segment is become very low.what is the reason?

    ReplyDelete
    Replies
    1. use a power supply at least 500mA. It is depend on the type of LEDS. Make sure to use same colour LED and same type of LEDs. Further if you problem not solved, let me know.

      Delete
    2. Hi sir.It was just a problem in my soldering.i solved it and it is now working well.Thank you so much.

      Delete
  26. Time accuracy is low for DS 1307 ic.can replace the fs1307 with ds3231 RTC which is more accurate.

    ReplyDelete
    Replies
    1. My congratulations and if you want to change the accuracy try to change the amount given to the BRIGHTNESS.DS3231 is the one

      Delete
  27. Will ds3231 work with RTClib.h?. when I using ds1307 it loses approximately 4minuts/day.so can I replace ds3231 instead of ds1307?.In many blogs it is showed that ds3231 has a precision of 1ppm.pls clarify.

    ReplyDelete
    Replies
    1. I did not have a issue about 4 minutes error. you have to adjust the code of BRIGHTNESS

      Delete
    2. Sir I solved that problem by changing RTC chip.now it is working well.i also had a problem of automatic changing of 12/24 h format.i also made a solution for this by adding a 10k Resistor b/W Arduino pin A3 and Vcc.

      Delete
    3. Well done. nice to hear new upgrades to this project. keep it up study and practice well.

      Delete
  28. Can i use ds3231 rtc module instead of ds1307 rtc ?

    ReplyDelete
    Replies
    1. yes, you may. but you may have to change the library.

      Delete
  29. Where 15 regulator ics (7805) are uses?
    Please give me complete wiring diagram.

    ReplyDelete
    Replies
    1. No 15 regulator ICs had used. only one is required

      Delete
  30. Does the DP run the colons?

    ReplyDelete
  31. You show the buttons wired to 5v but your code shows they should be grounded and pulled high in software.

    ReplyDelete
    Replies
    1. Got it working but in the 12hr mode the first digit is a zero. I want it blank like yours. What part of your code does this.

      Delete
    2. Edit this part

      for(int i = 100 ; i >0 ; i--) {
      if (timp >= 100000) displayNumber01(timp);
      else displayNumber02(timp);
      }

      for(int i = 100 ; i >0 ; i--) {
      if (timp >= 100000) displayNumber03(timp);
      else displayNumber04(timp);
      }

      for(int i = 100 ; i >0 ; i--) {
      if (timp >= 100000) displayNumber05(timp);
      else displayNumber06(timp);
      }

      Delete
  32. Not yet, still building. But was just asking are the buttons grounded or tied to 5v. it seems the schematic contradicts the code.

    ReplyDelete
  33. Arduino digital pin output current is 40ma max.. But you use 4 led in series it consumes 80ma

    ReplyDelete
    Replies
    1. That is why I have given the power to LED by Transistors.

      Delete
  34. Good work bro thanks for sharing your experience good luck

    ReplyDelete
  35. Brother, I try it on Proteus, but it not work...plz help ,,how to do this....please please please.

    ReplyDelete
    Replies
    1. 1st check LED wiring. Give separate power to LED and check that all the LEDs are working and polarity is correct. Not working mean? I need more information.

      Delete
  36. Brother, i upload a pic on facebook, please see this,,i am try common anode & common Cathode but its not working properly..

    link= (https://www.facebook.com/photo.php?fbid=1731130863608067&set=p.1731130863608067&type=3&theater)

    ReplyDelete
    Replies
    1. Where is the 3V battery to power the RTC module?

      Delete
  37. have you built the project or it is just simulation?

    ReplyDelete
  38. Hello
    How to connect AM/PM LED? There is no way on the diagram

    ReplyDelete
    Replies
    1. ConnEct an LED through 220ohm resiator to pin 13.

      Delete
  39. Can i change NPN transistor as 2N2222 ?

    ReplyDelete
  40. Hello
    Mama hadapu clock eke 11 pin eken signal enne neha. digit 1 eka on wenne ne. aneth digit 5ma blink wenawa.

    ReplyDelete
    Replies
    1. Wiring check karanna. samaharawita 11 pin eka dead wela ethi. ehema welanam IC eka change karanna wei.

      Delete
  41. All led blank. Time not show

    ReplyDelete
  42. WHEN I UPLOAD CODE, ALL DIGIT SHOW 8 NUMBER WITH BLINKING & TIME IS NOT SHOWING
    SO WHATS FALT HERE

    ReplyDelete
    Replies
    1. check wirings again and the transisters types, it should be correctly NPN and PNP

      Delete
  43. i'm using seven segment display with direct connect to atmega328, not using transistor
    so why this not showing number

    ReplyDelete
    Replies
    1. Because the transistors change the anode and cathode, If you use SSD directly, you have to change some codes. And also it is depend on the common polarity of SSD.

      Delete
  44. yes you are right bro, finaly its work
    i changed it polarity in code, HIGH TO LOW & LOW TO HIGH
    THANKS BRO YOU ARE GOOD ENGINEER

    ReplyDelete
  45. There is one more thing bro that setting switches not work
    pushbutton connected to vcc 5v with 1k resistance
    what to do now

    ReplyDelete
    Replies
    1. The you have to troubleshoot it. 1st add code under void setup as Serial.begin(9600);

      then next to the button code: Eg if it is SW0 button add a code as Serial.print("SW0 : ");
      Serial.println(digilalRead(SW0));

      Then run serial monitor and press SW0 switch. and check the readings. you have to repeat same thing if you want to check all the other switchers as well. Then you can find out switchers are working or not. if the reading is always same, there is an issue in wiring. *** When serial print is working, your clock will be mad. do not worry. If you can not upload the codes, just disconnect pin 0 and pin 1 from SSD.

      Delete
    2. Some times that issue had come. therefore I changed the switches wiring diagram. Check the updates.

      Delete
  46. when i connect switches to ground instead of vcc 5v then its working well

    ReplyDelete
  47. becouse i used digital pins 2,3,4,5 not analog input pins,

    ReplyDelete
  48. Please Anura, I am still building this project but am using the common cathode , please tell me what I need to change in the code or hardware for the project to work like the common anode. I will be expecting your reply soon. Thank you :-)

    ReplyDelete
  49. If you change the transistors as i shown in this post above, you no need to change the codes.

    ReplyDelete
  50. If i change RTC DS3231, what code part have to change?

    ReplyDelete
    Replies
    1. you have to change the library
      https://github.com/rodan/ds3231

      Delete
  51. I changed library but here have error like this

    ledclks:115: error: 'RTC' was not declared in this scope

    DateTime now = RTC.now();

    ReplyDelete
  52. Hi sir send me hex file and fuse bit
    Arduino file not upload compiler error
    S0 plz send me hex file and fuse bit
    [email protected]

    ReplyDelete
  53. RTC DS3231 danwa nam code eke mokakda wenas krna one

    ReplyDelete
  54. Please give me your whatsapp number. I have to discuss to you some doubts with picture 9977776662 my no

    ReplyDelete
  55. Send a msg to Easymades Facebook page

    ReplyDelete
    Replies
    1. Brother i did it successfully, one problem is that - in 12 hour mode, (hour Digit Show "0" after 11 hour, like : (0:01:10). Please help.

      Delete
  56. Replies
    1. Check this part


      /*
      4 digit 7 segment display: http://www.sparkfun.com/products/9483
      Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
      */
      // modified connexion by niq_ro from http://nicuflorica.blogspot.com
      // dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
      // Code modified by BMIAK Basnayaka
      // http://www.arduinomyprojects.blogspot.com

      int digit1 = 11;
      int digit2 = 10;
      int digit3 = 9;
      int digit4 = 6;
      int digit5 = 5;
      int digit6 = 3;

      //Pin mapping from Arduino to the ATmega DIP28 if you need it
      //http://www.arduino.cc/en/Hacking/PinMapping
      int segA = 0; //Display pin 11
      int segB = 1; //Display pin 7
      int segC = 2; //Display pin 4
      int segD = 4; //Display pin 2
      int segE = 7; //Display pin 1
      int segF = 8; //Display pin 10
      int segG = 12; //Display pin 5
      int segDP =13; // Display pin 3



      #include < Wire.h >
      #include "RTClib.h"
      RTC_DS1307 RTC;

      // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
      // original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
      // add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
      // add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm



      byte SW0 = A0;
      byte SW1 = A2;
      byte SW2 = A1;
      byte SWT = A3;
      int Adhr=0;
      int Admnt=0;
      int D = 0;
      int Z =0;

      // use for hexa in zecimal conversion
      long zh, uh, ore;
      long zm, um, miniti;

      void setup() {

      //Serial.begin(57600);
      Wire.begin();
      RTC.begin();
      // RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
      // if you need set clock... just remove // from line above this

      // part code for flashing LED
      Wire.beginTransmission(0x68);
      Wire.write(0x07); // move pointer to SQW address
      // Wire.write(0x00); // turns the SQW pin off
      Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
      // Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

      Wire.endTransmission();


      pinMode(segA, OUTPUT);
      pinMode(segB, OUTPUT);
      pinMode(segC, OUTPUT);
      pinMode(segD, OUTPUT);
      pinMode(segE, OUTPUT);
      pinMode(segF, OUTPUT);
      pinMode(segG, OUTPUT);
      pinMode(segDP, OUTPUT);

      pinMode(digit1, OUTPUT);
      pinMode(digit2, OUTPUT);
      pinMode(digit3, OUTPUT);
      pinMode(digit4, OUTPUT);
      pinMode(digit5, OUTPUT);
      pinMode(digit6, OUTPUT);


      //Serial.begin(9600);

      pinMode(SW0, INPUT); // N.O. push button switch
      pinMode(SW1, INPUT); // N.O. push button switch
      pinMode(SW2, INPUT); // N.O. push button switch
      pinMode(SWT, INPUT); // N.O. push button switch

      digitalWrite(SW0, HIGH); // pull-ups on
      digitalWrite(SW1, HIGH);
      digitalWrite(SW2, HIGH);
      digitalWrite(segDP, LOW);


      }


      void loop() {

      DateTime now = RTC.now();
      long HR = now.hour()*1000;
      long timp = (HR*10)+now.minute()*100+now.second();
      Adhr = now.hour();
      Admnt=now.minute();

      int DIM = 0;

      //------------------------------------------------------
      //12/24 hours shitching
      //------------------------------------------------------
      if (timp < 130000){
      digitalWrite(segDP, LOW);}


      if (digitalRead(SWT)==0){delay(300);
      if (D == 0) {
      D =1;delay(200);}

      else{
      D =0;}
      }

      if (D == 0){
      if (timp>=130000)
      timp=timp-120000;
      }

      Delete
  57. Please give me your whatsapp number. I have to discuss to you some doubts with picture my no 9977776662

    ReplyDelete
  58. Brother, hero- I check the code, but it is not done,,,,please help

    ReplyDelete
    Replies
    1. Find the following code and delete it, the check the time
      if (D == 0){
      if (timp>=130000)
      timp=timp-120000;
      }

      Delete
  59. Brother, i find & delete the code...now it is works only 24Hour mood..

    ReplyDelete
  60. now find this part
    //Serial.begin(9600);

    and remove "//" mark.
    Serial.begin(9600);

    and add again following

    if (D == 0){
    if (timp>=130000)
    timp=timp-120000;
    }

    Serial.print(timp);

    now, run Serial monitor. The check what is the amount shown in at 1:00 pm?



    ReplyDelete
  61. i check it, it is ok..& RTC give time accurately.

    ReplyDelete
  62. SirI want know 12hrs code only please send me code file

    ReplyDelete
    Replies
    1. Find the following code

      if (D == 0){
      if (timp>=130000)
      timp=timp-120000;
      }

      and replace as follows
      if (timp>=130000){
      timp=timp-120000;
      }

      Delete
  63. hello sir my project is completed thank U . but i have an a problem in 12 hr mode there are no pin or digram for am/pm led light indicator thanks

    ReplyDelete
    Replies
    1. It is happy to me. Yes, you can add an LED to Digital pin 13 with 120 ohm resistor.

      Delete
  64. Sir, I have successfully completed the project as per your guidelines, Thank you so much for guiding us. I want to increase the brightness of LEDs so that it will be easily viewable in daylight also, please help.

    ReplyDelete
    Replies
    1. Congratulations. Yes, if you need more current you have to give a current with more amps then if you need more, change the transistors and use MOSFETs (P- channel and N –Channel) as necessary. But 1st give the power through 1N5408 diode to regulator and connect the 12 to LEDS before the diode. Give about 1A to 3A current and use a heat sink to 7805.

      Delete
  65. sir,i am using 8 led insted of five .can u suggest which type of N channel or P channel MOSfet i wanna use and how to wire them .i am using 5v 2amp powersupply.

    ReplyDelete
    Replies
    1. 5V is not enough. So Use a separate power supply to BC 557 Transistor and give about 8V using 7808 regulator.

      Delete
  66. thanks sir ,if i change power supply 5v to 8v it will work ? how many amp power supply iwill use


    ReplyDelete
    Replies
    1. give only 5v to arduino, but about 8v to LEDs. 1A may be adequate.

      Delete
  67. ok thanks, im using 12v 1amp output of a voltage regulator 7808 .im using 5mm Square Head Red LED it is oky with 8v?

    ReplyDelete
  68. Yes. 1st add 480ohm resistor before the LED.

    ReplyDelete
  69. done but when the digit increases from 1 to 8 it will get dimmer .
    i think the pnp transistor is not give enough power

    ReplyDelete
  70. may i use bc369 pnp transistor instead of bc557

    ReplyDelete
    Replies
    1. Yes You can use it. But I have no idea about the switching speed of that transistor.If the switching speed low, all the LED will light up.

      Delete
  71. thanks. the clock time is not precise it will increases after some time
    may i change the rtc module?

    ReplyDelete
    Replies
    1. This happens because of the quality and the condition of the crystal. When you solder the crystal make sure not to over heat it. Try with a new good quality crystal and solder terminals one by one with a reasonable delay holding the terminals with a plier.
      Best of luck.

      Delete
  72. i use DS1307 rtc module
    insted of making it

    ReplyDelete
  73. are u talking about arduino crystal or rtc crystal ?

    ReplyDelete
  74. This comment has been removed by the author.

    ReplyDelete
  75. thanks it will working fine but flickering
    im using s8550 insted of bc557
    does this effect it?
    thanks ones again

    ReplyDelete
    Replies
    1. It may be due to few reasons. howerver, try to change the brightness value of the code.

      Delete
  76. Sir I am current doing your clock at the moment but am stuck with a problem which is,can I add seconds to the newer version of your clock? The Ssd clock.if yes how do I do?

    ReplyDelete
  77. The latest one,I mean the 4 digit type

    ReplyDelete
    Replies
    1. yes you can. Use SSDs instead of LEDs.Only change is, you do not want to use the transistors and find the relevant legs of SSDs.

      Delete
  78. Sir, I don't want to use transistor. I connected the display directly to Adruino, but not working. Which code I have to Change?

    ReplyDelete
  79. The you want this kind of a code. see the following link https://youtu.be/g1qX_f4JzUk

    ReplyDelete
  80. Sir I made it successfully. Thank you so much for sharing this project. But I am facing one problem. When I press "time Set" switch, all digit blinking normally, but hour and minute value changed (-6) every time I press time set switch.

    ReplyDelete
  81. Sir, Cannot post the code.
    ERROR appears.

    Your HTML cannot be accepted: Must be at most 4,096 characters

    ReplyDelete
  82. I have upload the same code that you shared on this post.

    ReplyDelete
  83. Hello Sir

    i have completed this project with 6Digit 7 Segment.
    now i want add Date and display every 1 minute.
    can you do this?

    ReplyDelete

-->
Copyright © 2013 Easy Mades