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

Hello, all !!

This is my project of a digital clock with RTC (Real Time Clock) using a LED display of 04 digits and 07 segments including features of temperature and humidity.

To control the display I have used an Arduino Uno and 02 chips 74HC595 (8 bit shift register with output latches).

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

The assembly is very simple but you need take care with the wiring.

Be patient, follow the schematics and enjoy it.

(See VIDEO)

Step 1: 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

The assembly of components is very easy but you need to follow the schematics with care about the wiring connections.

If you want to use another LED display, check the datasheet to update the output wiring (jumpers) of 74HC595.

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. dht11 (library for the 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 the program "SetTime" that you can find here or in the library/example of DS1307RTC on Arduino Software.

2 - Recompile and reload the program of Digital_Clock on Arduino.

With 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 turn it on.

Step 4: Conclusion

The main lesson for me in this project is related to the logic to manage the display (data multiplexing) using shift registers and also the combination of different sensors in same application.

I hope you have enjoyed this project where I also had the opportunity to contribute to you with a little bit more information about Arduino programming.

Best regards.

LAGSILVA

March 22, 2015

(Last update: 17.Jun.2017)

Comments

author
CoşkunM (author)2015-09-13

Display CC (FYQ-5642AX/)?

author
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

Display LED 4 x 7 - Common Anode.JPG
author
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
author
irfan jkh (author)2017-07-16

What if i using 4 one digit 7segment display?

author
lagsilva (author)irfan jkh2017-07-16

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

author
esloch (author)2017-07-02

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

author
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.

author
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 ...

author
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 :)

author
lagsilva (author)esloch2017-07-02

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

author
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

FIKR706J4IPU6B3.LARGE.jpg
author
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.

author
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 ...

author
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!

author
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

author
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 ...

:(

author
esloch (author)lagsilva2017-07-01

the brightness control work fine .. thanks :)

author
lagsilva (author)esloch2017-07-01

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

author
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 :/

author
soumitraseth (author)2017-06-20

I mam beginner with AURDINO . Thank All

author
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

author
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

author
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...

author
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

author
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?

author
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

author
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

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

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

Screenshot 2017-06-07 21.25.31.png
author
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

author
AMARNATH S (author)lagsilva2017-06-07

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

author
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

author
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.

author
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.

author
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


author
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

author
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

author
Ed Marjosef (author)lagsilva2017-01-29

Thank you sir

author
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

author
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

author
DavyR1 (author)lagsilva2016-09-30

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

author
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

author
lagsilva (author)Veigrillen2016-09-17

Hello, Veigrillen,

Thank you !! I hope you have success with this project.

It sounds me there is some missing library.

Did you install the following libraries into your Arduino folder ?


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

If you have done that, please try the following:

1) Download again the file "Digital_Clock_V1_English.ino".

2) Open it on a word editor (WordPad, for example) and copy all the text.

3) Create a new file on Arduino Software.

4) Clean all the statements of new file and paste the text you have copíed on item #2.

5) Recompile the program and inform me the results.

Good luck!!

author
Veigrillen (author)lagsilva2016-09-18

Thank you so mutch. :)
I finally got rid of the error codes, but encountered another problem.

I got the wrong RTC module. I got an DS3231N, and not the DS1307, so im not able to complete the "mission.

Unless there is an easy workaround?

Thanks again.

author
lagsilva (author)Veigrillen2016-09-18

Good news, Veigrillen !!

I do not see any issue if you use the DS3231 RTC.

Both modules use I2C bus and you can apply same library.

In fact the DS3231 is much more accurate than DS1307 !!

Just take care with corresponding connections SDA, SCL, Vcc and GND.

Take a look on this tutorial:

http://tronixstuff.com/2014/12/01/tutorial-using-d...

Let me know about your tests.

author
Veigrillen (author)lagsilva2016-09-19

Well, i got everything uploaded, and my led lights up, but i recon theres something wrong.. :)

https://youtu.be/FXtVAHPSeSc

author
lagsilva (author)Veigrillen2016-09-26

Hello, Veigrillen,

Any progress ?

Did you revise the connections and find out what is the issue ?

author
Veigrillen (author)lagsilva2016-09-27

Uhm,, im a complete newbie, and didnt know that i could just reverse the connectors, so I just ordered a new led display with Common Anode. (They havnt arrived yet)

I feel kinda stupid now ;-)

Do you know if there is a "walkthroug" to reverse them?

Right now i got an SMA420564 display

Thanks in advance

author
lagsilva (author)Veigrillen2016-09-27

Yes, it is possible to use a Common Cathode display, but you need to update all instructions of the program.

With right programming, you can control this hardware as you want!

For example, the following statements to set the Display #1 must be updated.

From:

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1

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

digitalWrite(latchPin, HIGH);

To:

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~8); //Set DISPLAY 1

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

digitalWrite(latchPin, HIGH);

The sign ~ inverts the signal from HIGH to LOW or vice versa.

Try to update all statements related to setup of the digits of display.

author
Veigrillen (author)lagsilva2016-09-28

Hi buddy, and thanks for taking the time to help me.

Your last post really helped, and Im almost there..

Three of the four digits are working almost perfect,

As you can se of the video, there are some issues, and i'we gone over the connectors and cables, and all seem to be correct.

https://youtu.be/6ZX0xNYYdic

Here is the code that i'we used:

/* Digital Clock

Digital Clock with LED Display - 4 Digits x 7 Segments

Display Time, Temperature and Relative Humidity

V1.1 - 10.Fev.2016

*** Notes of revision V1.1 ***

- Translated the remarks/comments into English

- Added optional statements to show the Temperature in Fahrenheit Degrees (ºF)

*/

#include <Time.h> //Time Library

#include <DS1307RTC.h> //Real Time Clock Library

#include <Wire.h> //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)

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

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

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

int clockPin = 8; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)

int latchPin = 9; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)

int dataPin = 10; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)

int hora, minuto, temp, umid;

int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;

int unidadeTemp, dezenaTemp, unidadeUmid, dezenaUmid;

unsigned long ti;

int chk; //Variable to read the sensor DHT11

//Digits Matrix - 0 a 9

byte num[] = {

B01111110, // Zero

B00110000, // One

B01101101, // Two

B01111001, // Three

B00110011, // Four

B01011011, // Five

B01011111, // Six

B01110000, // Seven

B01111111, // Eight

B01111011, // Nine

};

void setup() {

pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output

pinMode(clockPin, OUTPUT);

pinMode(dataPin, OUTPUT);

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

//setTime(15, 05, 00, 13, 02, 2016);

}

void loop() {

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

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

hora = hour();

minuto = minute();

unidadeHora = hora % 10;

dezenaHora = hora / 10;

unidadeMinuto = minuto % 10;

dezenaMinuto = minuto / 10;

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);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~4); //Set DISPLAY 2

shiftOut(dataPin, clockPin, LSBFIRST, num[unidadeHora]); //Set the Hour (unit)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~2); //Set DISPLAY 3

shiftOut(dataPin, clockPin, LSBFIRST, num[dezenaMinuto]); //Set the Minute (ten)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set DISPLAY 4

shiftOut(dataPin, clockPin, LSBFIRST, num[unidadeMinuto]); //Set the Minute (unit)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~4); //Set LED of dots

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

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set DISPLAY 4

shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)

digitalWrite(latchPin, HIGH);

}

delay(500); //Wait for half second before go ahead to show the next feature

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

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

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

//Optional calculation of Temperature in Fahrenheit degrees (ºF). Remove the comments ("//") of following statement to use it.

//temp = (temp*18+5)/10+32;

while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Temperature

unidadeTemp = temp % 10;

dezenaTemp = temp / 10;

digitalWrite(latchPin, LOW);

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

shiftOut(dataPin, clockPin, LSBFIRST, num[dezenaTemp]); //Set the Temperature (ten)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~4); //Set DISPLAY 2

shiftOut(dataPin, clockPin, LSBFIRST, num[unidadeTemp]); //Set the Temperature (unit)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~2); //Set DISPLAY 3

shiftOut(dataPin, clockPin, LSBFIRST, B01100011); //Set the degree symbol [º]

digitalWrite(latchPin, HIGH);

//Show the Temperature in Celsius degrees (ºC)

//Set the following statements as comments with "//" to show the Temperature in Fahrenheit (ºF)

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set DISPLAY 4

shiftOut(dataPin, clockPin, LSBFIRST, B01001110); //Set the symbol of Celsius [C]

digitalWrite(latchPin, HIGH);

//Show the Temperature in Fahrenheit degrees (ºF)

//Remove the indication of comments "//" on following statements to show the Temperature in Fahrenheit (ºF)

//digitalWrite(latchPin, LOW);

//shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4

//shiftOut(dataPin, clockPin, LSBFIRST, ~B01000111); //Set the symbol of Fahrenheit [F]

//digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set DISPLAY 4

shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)

digitalWrite(latchPin, HIGH);

}

delay(500); //Wait for half second before go ahead to show the next feature

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

umid = DHT.humidity; //Reading the Humidity

while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Humidity

unidadeUmid = umid % 10;

dezenaUmid = umid / 10;

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~8); //Set DISPLAY 1

shiftOut(dataPin, clockPin, LSBFIRST, num[dezenaUmid]); //Set the Humidity (ten)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~4); //Set DISPLAY 2

shiftOut(dataPin, clockPin, LSBFIRST, num[unidadeUmid]); //Set the Humidity (unit)

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~2); //Set DISPLAY 3

shiftOut(dataPin, clockPin, LSBFIRST, B01100011); //Set the upper symbol of percentage [%] of Humidity

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set DISPLAY 4

shiftOut(dataPin, clockPin, LSBFIRST, B00011101); //Set the lower symbol of percentage [%] of Humidity

digitalWrite(latchPin, HIGH);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, LSBFIRST, ~1); //Set Display 4

shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)

digitalWrite(latchPin, HIGH);

}

delay(500); //Wait for half second before to restart

}

author
lagsilva (author)Veigrillen2016-09-28

Great progress!!! I am really happy with that!!

Please, update the following statement for all these instances in the program:

.........

shiftOut(dataPin, clockPin, LSBFIRST, ~255); //Reset the DISPLAY 4 (to avoid some flicking)

.........

In fact, ~255 means 0 (zero). You can replace by this if you prefer!

I think it will work this time ! :)

About This Instructable

31,879views

57favorites

License:

Bio: I am a Mechanical Engineer and an enthusiastic Maker. I like to develop new ideas combining electronics and programming.
More by lagsilva:Analog Clock With LED Matrix and ArduinoChinese Rings PuzzleTalking Clock with Arduino
Add instructable to: