Introduction: Digital Clock RTC With LED Display of 4 Digits and 7 Segments

Hello, everybody!


This is my project of a digital clock with RTC (Real Time Clock) using a LED display of 4 digits and 7 segments including interesting features of temperature and humidity. In the control of display I have used an Arduino Uno R3 and 02 ICs of 74HC595 (8 bit shift register with output latches).

The use of shift register is important to save output ports of Arduino. You only need 3 outputs to control the display. With it you transfer serial data into 8 parallel outputs.

There are two breakouts: one for the sensor of temperature (ºC - Celsius / ºF - Fahrenheit degrees) and humidity (% - in percentage) and another one for the RTC.

The assembly is very simple and you just need take care with the wiring. Be patient, follow the schematics and enjoy it.

(See VIDEO)

Note: Code updated to revision V1.3 in Oct.2017


- Introduction of the colon (double dot) flicking in the hours.

- Introduction of brightness control in the code.

Step 1: Material

Picture of Material

Material list:

- 01 x DS1307 (Real Time Clock)

- 01 x DHT11 (Temperature and Humidity sensor)

- 02 x 74HC595 (8 bit shift register with output latches - 3 state)

- 08 x Resistors of 150 Ohms (Brown, Green, Brown)

- 01 x FYQ-5642BX (Common Anode LED Display 04 digits and 07 segments or equivalent but take care with the pins numbers)

- 01 x Arduino Uno

- 01 x Breadboard

- 01 x Kit of jumpers

Step 2: Assembly

Picture of Assembly

The assembly of components is very simple but you need to follow the schematics with care due to the wire connections. There are 2 shift registers in this project: one to control each segment of the display and another one to control what is the display on.


Important:

If you want to use another kind of LED display, you need to check its datasheet in order to update the output wiring (jumpers) of 74HC595 and also you must update the corresponding logics of Arduino's software.

Step 3: Programming

To run the program on Arduino you need to have the following libraries:

  1. Time (library for date & time)
  2. DS130RTC(library for the Real Time Clock)
  3. Wire (library used to support the RTC)
  4. DHT_Sensor_Libray (Adafruit's library for DHT sensor of Temperature and Humidity)

For the numbering (0 to 9), I have created a table with binary representation of each segment (A to G) that forms the digit as following:

  • B01111110 - 0
  • B00110000 - 1
  • B01101101 - 2
  • B01111001 - 3
  • B00110011 - 4
  • B01011011 - 5
  • B01011111 - 6
  • B01110000 - 7
  • B01111111 - 8
  • B01111011 - 9

To show in the LED display the data in sequence of time, temperature and humidity, I have used a "timer" with functions millis() and while().

In this case, each information is presented on the display and after 3 seconds moves to the next one.

Simple and very efficient.

You can apply this function millis() in several different ways to manage the time during the program running.

In many situations you can use it in the place of some timer library.

Another usefull function is digitalWrite(). With this function you can simplify the writting of data into the shift registers.

Take a look on it in the Arduino's home page at http://arduino.cc/en/Reference/DigitalWrite

- How to setup the time of internal clock of RTC module:

1. To update or setup the time of RTC module, load and run the program "SetTime " (you can find it on the library/example of DS1307RTC on Arduino IDE).


2. Reload and run again the program of "Digital Clock".

Following this procedure, the RTC module will keep the right time due its battery pack attached and you do not need to recompile the "Digital Clock" program every time you use it.

Comments

CoşkunM (author)2015-09-13

Display CC (FYQ-5642AX/)?

lagsilva made it! (author)CoşkunM2015-09-24

Hello,

Sorry for my delay to answer you and thank you for your question.

This information was missing and I will update it on Instructables.

The display is CA as you can see in the image below.

The code number of display is just for reference but you can use another similar one.

Regards,

Luís Antonio

MOHAMED ASIFA (author)2017-11-29

you have said that you have published another project to set time with push button can you plz share the website link

MOHAMED ASIFA (author)2017-11-29

i need to add led for blinking but if i add blink code in loop ,seven segment switches off when led goes on and if led goes off segment lights on how can i solve this?

MOHAMED ASIFA (author)2017-11-28

Can i change for 12hours time format what should I change code?

lagsilva (author)MOHAMED ASIFA2017-11-28

Try to update for the following statements:

hora=hour() %12;

if (hora==0) {

hora=12;

}

MOHAMED ASIFA (author)lagsilva2017-11-29

Thank you it's working

MOHAMED ASIFA (author)2017-11-27

Second segment below is not working and sometimes it look like this you can in video what could be problem either circuit or program?

lagsilva (author)MOHAMED ASIFA2017-11-28

Probably is a circuit issue. Check the connections and also check individually all LEDs of the display with failure.

Shivam gautam (author)2017-09-26

thanks for great instructable

in my case dots are not working ...whats the problem?

lagsilva (author)Shivam gautam2017-10-01

Shivam gautam,

Probably the LED display is not exactly the same of this project.

You need to check the electrical diagram of your display and try to identify what pin controls the colon / dots.

d67uttam (author)2017-07-18

Please provide straight forward circuit diagram of the project and how to get following libraries "


  1. Time (library for date & time)
  2. DS130RTC(library for the Real Time Clock)
  3. Wire (library used to support the RTC)
  4. dht11 (library for the sensor of Temperature and Humidity)"In which directory to be kept all these directory so that main program can be downloaded without error. My self hobbyist and want to build this clock circuit
irfan jkh (author)2017-07-16

What if i using 4 one digit 7segment display?

lagsilva (author)irfan jkh2017-07-16

You can do it replicating same wiring connections of 4 digits 7 segment display.

esloch (author)2017-07-02

technical question : no way to change the 8 protection resistances with only 4 connected to commun anode pins ?

lagsilva (author)esloch2017-07-02

Good question! I had this concern too!

When you make some electronic circuit you must know all technical limitations of the components you are using and the basis of these information are in their datasheets.

In my project, all segments of LED display are limited by their maximum current and so they are protected by individual resistors.

If you connect the resistors only to common pins, you need to consider the maximum current when all 7 segments will be on.

In this case it can works well with only 1 resistor, but the brightness of that segment will be lower.

Another point you need to consider is the limit of each port of -595- shift register.

esloch (author)2017-07-02

I want ask if it's possible to add simple if routine that verify if the hour decimal number is 0 (B01111110) then he no display it ...

esloch (author)esloch2017-07-02

make it ... too easy ... :

if (dezenaHora != 0) {

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)

shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]); //Set the Hour (ten)

digitalWrite(latchPin, HIGH);

}

I think I love arduino :)

lagsilva (author)esloch2017-07-02

The power of the Arduino comes from the code you make. ;-)

esloch made it! (author)2017-06-29

Hello

I sucess (with difficulty) to run this beautiful clock ... I would like to make some light changes on the code:

1- add two pushbuttons to manually change hours and minutes

2- use a variable resistance (photoresist type) in order to decrease the luminosity automatically in the absence of light

3- I also want to modify the display time delay ... I would like it to be much longer than the delay to display of temperature and humidity ...

If you can help me ... I start under arduino

Thank you

lagsilva (author)esloch2017-06-30

Hello, Esloch,

Congratulations! Great job and thanks for sharing!!

Related to your questions:

1- I have published here another projects using push buttons. Take a look on them to understand the electrical connections and the associated Arduino's code.

Question 2 and 3 are correlated due to the design of this clock.

The following statements control the duration of each feature being shown.

If you want less brightness in the LEDs, try add a delay statement inside the "whille" loop and change the time of delay and check the results of brightness in the display:

ti = millis(); // Initial time for the Timer of Hour/Time

while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour

delay(50); //Change this value to define the range of brightness you want

hora = hour();

minuto = minute();

....

One way to automatize this process is to use an analog port to read the LDR and convert it to a variable range to be used into delay function, like this example:

while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour

int val =analogRead(0); //Port 0 to read the LDR

val =map(val,0,1023,0,100);
delay (val);

hora = hour();

minuto = minute();

...

Note: Increasing the time delay, the flicking of display will increase too.

esloch (author)lagsilva2017-07-01

Thank you for your answer

To follow and understand, especially that I start under arduino, I try to attack code modifications one by one

I want to reduce the hide time between dispalys ... it's controled with delay (500) ... if I change it to delay (200) ... this change take effect only in the last delay ... I try also to remove it ... suppose I no want hide time between displays ... work only in the last ...

lagsilva (author)esloch2017-07-01

Esloch,

All delays statements have a function in the code and they are working.

If you remove the statements of delay(500) there will be no interval anymore.

Try do the opposite such as test. Use a delay (3000) for all of them.

In this case you will see an interval of 3 seconds between features changes.

Maybe you are not realizing any difference now because delay(500) means a half of second only!

esloch (author)lagsilva2017-07-01

I think the problem is that to read information of the DHT sensor it takes some time ... some think like 300 ms .. to place a lower time in delay has no effect ... we must always wait for this time reading

I think

esloch (author)lagsilva2017-07-01

I remove the statements delay (500) ... and it's remain some delay between the display of clock and temperature ... and between the display of temperature and humidity ... but no between humidity and clock ...

:(

esloch (author)lagsilva2017-07-01

the brightness control work fine .. thanks :)

lagsilva (author)esloch2017-07-01

I did some tests and I suggest use the delay time between 1 to 20 to control the brightness.

esloch (author)esloch2017-06-29

for the 3 point :

- I success to change display time (change (millis() - ti) < 3000) ... work fine)

- I try to change the wait time between displays ... I change delay(500); to delay(100); ... but only the last delay take effect (between humidiy and time) ... strange :/

soumitraseth (author)2017-06-20

I mam beginner with AURDINO . Thank All

TanoT2 (author)2017-06-14

Hello sir!

I am new to Arduino and I've been trying to do this same project but I have encountered several problems of which, some I have been able to solve and others not ... So I turn to your help to see if I can finish it!

sketch_jun14e:6: error: expected unqualified-id before numeric constant

#define DHT11 11 //Define al pin 11 como sensor DHT11

^

C:\Users\Cejas\Desktop\sketch_jun14e\sketch_jun14e.ino:7:1: note: in expansion of macro 'DHT11'

DHT11 DHT; //Define el nombre DHT al sensor de temperatura y humedad

^

C:\Users\Cejas\Desktop\sketch_jun14e\sketch_jun14e.ino: In function 'void loop()':

C:\Users\Cejas\Desktop\sketch_jun14e\sketch_jun14e.ino:83:53: warning: large integer implicitly truncated to unsigned type [-Woverflow]

shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Configura los LEDs de los doble puntos

^

sketch_jun14e:94: error: expected primary-expression before '.' token

chk = DHT.read(DHT11_PIN); //Lee la data del sensor DHT11

^

sketch_jun14e:94: error: 'DHT11_PIN' was not declared in this scope

chk = DHT.read(DHT11_PIN); //Lee la data del sensor DHT11

^

sketch_jun14e:97: error: expected primary-expression before '.' token

temp = DHT.temperature; //Lee la temperatura en grados centígrados (ºC)

^

sketch_jun14e:132: error: expected primary-expression before '.' token

umid = DHT.humidity; //Lectura de humedad

^

exit status 1

expected unqualified-id before numeric constant


(I'm using Arduino Mega with all the bookstores mentioned ...)


By another way, I wanted to ask if you could add 2 pushbuttons to "set" the time, for example every time you press a button add +1 hour and the other that adds +1 minute.


First of all, thanks for your help! greetings from Argentina

lagsilva (author)TanoT22017-06-15

Hello, TanoT2,

Thank you to try to replicate this project.

I have some comments:

1) I see you have done some changes in the original code.

2) Did you try to run my original code?

3) Did you see any errors after compilation of original code?

3) In your version of code, you need to fix the following declaration:

#define DHT11_PIN 11 //Sensor DHT11 conected to the pin 11 on Arduino

Pls, try again and keep me informed.

Saudações do Brasil,

LAGSILVA

TanoT2 (author)lagsilva2017-06-15

Hello again!

Yes, I tried with the original code and this was the error: (also want to say that I tried to copy all the code and execute it in a new file and the same thing...)

Arduino:1.8.2 (Windows 7), Tarjeta:"Arduino Mega ADK"

sketch_jun15a:16: error: 'dht11' does not name a type

dht11 DHT; //Define the name DHT for the sensor of Temperature and Humidity

C:\Users\Cejas\Desktop\sketch_jun15a\sketch_jun15a.ino: In function 'void loop()':

C:\Users\Cejas\Desktop\sketch_jun15a\sketch_jun15a.ino:92:53: warning: large integer implicitly truncated to unsigned type [-Woverflow]

shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots

sketch_jun15a:102: error: expected primary-expression before '.' token

chk = DHT.read(DHT11_PIN); //Read data of sensor DHT11

sketch_jun15a:105: error: expected primary-expression before '.' token

temp = DHT.temperature; //Reading the Temperature in Celsius degree (ºC)

sketch_jun15a:152: error: expected primary-expression before '.' token

umid = DHT.humidity; //Reading the Humidity

exit status 1

'dht11' does not name a type

I tried with different libraries of the dht11 on the internet, and if you compare them, they are differen .... I used this one: https://github.com/adafruit/DHT-sensor-library

AND I had to rename the DHT.h and DHT.cpp to dht11.h and dht11.cpp to "fix" the error:
no such a file or directory error

#include <dht11.h> // Temperature and Humidity Library

Im confused...

lagsilva (author)TanoT22017-06-16

Hello Tano T2,

If you use another library you must update the main code to use the correspondent statements of new library.

Libraries sometime are updated by their authors and an older code that use them must be updated too. Maybe this is the case here and I need to update my code for current versions of DHT libraries, but I won't do it for now.

Anyway I included at Step 3 of this Instructable the DHT11 library I have used when I developed this project.

Please, try to download and install it in your Arduino IDE and tell me if finally it works.

Regards,

LAGSILVA

TanoT2 (author)lagsilva2017-06-16

ALMOST DONE!!

Finally worked! Only shows me an error with double points:

In function 'void loop()':

warning: large integer implicitly truncated to unsigned type [-Woverflow]

shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000);

And both, the temperature and humidity indicates 0 ° C and 0% ... I'm using a DHT22, is it compatible?

lagsilva (author)TanoT22017-06-17

Hello Tano T2,

There are some differences between DHT11 and DHT22. This last one is more accurated.

I have updated my code to use DHT library of Adafruit that can be used for both types of sensor.

Try download it and set the code according to the sensor version you are using in the following statements:

//#define DHTTYPE DHT11 // DHT 11

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

Please, inform me about the results.

Regards,

LAGSILVA

lagsilva (author)TanoT22017-06-17

Tano T2,

Great news !!

I do not see this warning message in my Arduino IDE. Maybe the code will run because it is not an error, but the root cause must be investigated.

Probably the indication of 0ºC and 0% is because the data of DHT was not read correctly.

As I told you, the main code must be updated to use more recent libraries of DHT.

Try investigate about differences between DHT22 and DHT11 and keep me informed about your progress. From my side I will do it too.

Note: I think all this road blocks are very good for everyone learn more and more. Investigation, tryouts and learning are part of the maker world. Go ahead, be patient and be curious all the time!

Regards,

LAGSILVA

AMARNATH S made it! (author)2017-06-07

i had some erros in coding. please help me clear this..

lagsilva (author)AMARNATH S2017-06-07

Did you add all libraries into your Arduino's IDE ?

You need install all the followings libraries before compile the code:

<Time.h> : Time Library

<DS1307RTC.h> : Real Time Clock Library

<Wire.h> : Wire Library

<dht11.h> : Temperature and Humidity Library

AMARNATH S (author)lagsilva2017-06-07

yes, i was added the all libraries.
but still this error will be came again and again,,!

lagsilva (author)AMARNATH S2017-06-16

Hello Amarnath,

I have added in Step 3 of this Instructable the DHT11 library I have used when I developed this project.

Please, try install it in your Arduino IDE and tell me if it finally works.

Regards,

LAGSILVA

lagsilva (author)AMARNATH S2017-06-08

1) Check the directories structures of libraries in your Arduino installation. Probably the compiler is not finding the dht11 library.

2) Try Google "arduino error does not name a type". I found many solutions for this error. Maybe one of them can fix it.

Grrrmachine (author)2017-03-21

Great work! I built my own version in an hour and your code worked perfectly.

I have one small issue though. I'm using two 2-digit displays instead of one 4-digit, so I don't have the central dots between hour and minute. Instead, a single decimal point lights for the second digit. I guess this is set by this part of the code:

shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots

Is there any way to also make the decimal point for digit to also light at this time? That way I can rotate my second 2-digit display by 180 degrees to recreate the double dots.

lagsilva (author)Grrrmachine2017-03-21

Grrrmachine,

Thank you very much!!

Please, post a photo of your project here.

If your display are with the LEDs not inclined some degrees, I think it is feasible to put one of them upside down. If not, the result could be a little bit strange due to the different angles of inclination of both displays when you rotate one of them by 180 degrees.

The logic of sequence to control the LED of the displays of my project is:

Dot - A - B - C - D - E - F - G

For your project you must consider the transfer function for the 2nd. display:

Dot - E - F - G - A - B - C - D

I see you have two ways to apply this logic:

1) Change wire connection of 2nd display according with 2nd sequence.

2) Create a second byte num2[ ] with new sequence to be applied in the 2nd display and update the code (in this case you can mantain same wiring connection of original project).

//Digits Matrix - 0 to 9 - For 1ST. Display

byte num1[] = {

B01111110, // Zero

B00110000, // One

B01101101, // Two

B01111001, // Three

B00110011, // Four

B01011011, // Five

B01011111, // Six

B01110000, // Seven

B01111111, // Eight

B01111011, // Nine

};

//Digits Matrix - 0 to 9 - For 2ND. Display

byte num2[] = {

B01101111, //

B00000110, //

B01011101, //

B00011111, //

B00110110, //

B00111011, //

B01111011, //

B00001110, //

B01111111, //

B00111111, //

};

Good luck and keep me posted on your progress!

Regards,

LAGSILVA


Ed Marjosef (author)2017-01-29

Sir Lagsilva i have a question, can i not include the sensor temperature and humidity sensor?.... Will it affect the circuit or not?.. Thank you

lagsilva (author)Ed Marjosef2017-01-29

Hello, Ed Marsjosef,

I am understanding you want only the clock function running, without the temperature and humidity information been displayed.

Yes, you can delete the sensor and the circuit will be not affected.

Without the sensor, the code will consider as 0 (zero) the values of temperature and humidity.

Regards,

LAGSILVA

Ed Marjosef (author)lagsilva2017-01-29

Thank you sir

DavyR1 (author)2016-09-28

Hi Lagsilva,

I really enjoy your projects and can tell you are a real enthusiast by the way you respond to fellow builders especially beginners like myself! I'll be following your builds with interest. You have a real talent for explaining things and should do some full build videos which I'm sure would be popular! Keep the projects coming!

Davy

lagsilva (author)DavyR12016-09-29

Hello, Davy,

Thank you very much for your feedback!

I am not a specialist, I am really an enthusiast of this technology that help us to learn more, to be curious, to be inventive, to be better than yesterday!

Everyone is a beginner in something because we do not know everything.

But we can learn!! All the time!

Regards,

Luís

DavyR1 (author)lagsilva2016-09-30

It's your enthusiasm that shines through! Keep it up! ;-)

Veigrillen (author)2016-09-17

Hello.

Thank you so mutch for a great idea. :-)
Bought the parts yesterday, and assembled today.

BUT, i get this errorcode trying to verify the script.

Could you help?

______________________

In file included from C:\Users\arnes\Downloads\Digital_Clock_V1_English\Digital_Clock_V1_English.ino:13:0:

C:\Users\arnes\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared

static bool read(tmElements_t &tm);

^

C:\Users\arnes\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared

static bool write(tmElements_t &tm);

^

Digital_Clock_V1_English:16: error: 'dht11' does not name a type

dht11 DHT; //Define the name DHT for the sensor of Temperature and Humidity

^

C:\Users\arnes\Downloads\Digital_Clock_V1_English\Digital_Clock_V1_English.ino: In function 'void setup()':

Digital_Clock_V1_English:50: error: 'setSyncProvider' was not declared in this scope

setSyncProvider(RTC.get); // Update the time with data of RTC (Real Time Clock)

^

C:\Users\arnes\Downloads\Digital_Clock_V1_English\Digital_Clock_V1_English.ino: In function 'void loop()':

Digital_Clock_V1_English:63: error: 'hour' was not declared in this scope

hora = hour();

^

Digital_Clock_V1_English:64: error: 'minute' was not declared in this scope

minuto = minute();

^

C:\Users\arnes\Downloads\Digital_Clock_V1_English\Digital_Clock_V1_English.ino:92:53: warning: large integer implicitly truncated to unsigned type [-Woverflow]

shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots

^

Digital_Clock_V1_English:102: error: 'DHT' was not declared in this scope

chk = DHT.read(DHT11_PIN); //Read data of sensor DHT11

^

exit status 1

'dht11' does not name a type

About This Instructable

36,934views

58favorites

License:

Bio: I'm a Mechanical Engineer and an enthusiastic Maker. I like to create and code my projects using the Arduino.
More by lagsilva:Digital Clock With Mirrored Display Driven by AccelerometersAnalog Clock With LED Matrix and ArduinoChinese Rings Puzzle
Add instructable to: