Complete Digital Clock With Presence Sensor (RTC - Alarm - PIR - Temperature - Humidity - Dew Point)




Hi there,

I already have done some digital clocks projects with Arduino including LED and LCD displays, but this one is more special because I have introduced a new feature with a movement sensor (PIR).


  • Main Features
  1. PIR (Presence Infrared Sensor)
  2. RTC (Real Time Clock)
  3. Alarm
  4. Temperature
  5. Humidity
  6. Dew Point
  7. Encoder to set time & alarm
  8. Permanent memory for the time & alarm data even with power supply turned off
  • PIR main functions
  1. Turns on the display only when it is detected some movement around the clock.
  2. Turns off the the alarm if some movement is detected.

If you or your children have a deep sleep and it's hard to wake up in the morning, this last function is perfect for you because the alarm keeps itself activated with a noisy buzzer until the sensor detect the movement of your body.

Definitely you must get up from the bed and keep yourself moving !

Shake your body !!

Step 1: Bill of Material

Before I introduce you to the bill of material I would like to explain the reason what I decided to apply an I2C LED display in this project.

In fact I have tested this project with a LCD display (16 cols x 2 lines and also 20 cols x 4 lines) but I did not like about the results to visualize them. They are good to be visualized at a short distance but not to be viewed at some faraway meters in a sleep room.

A second option was to apply a common display of LED (4 digits x 7 segments) but in this case I would need to put more components for the multiplexing of the outputs of Arduino as you can see in this another project of mine: Digital Clock with RTC.

A last reason (and more important) was the fact I was interested to learn about how to work with the I2C displays because is always important for me to improve my acknowledgement about different components, increasing my "arsenal" for future projects and programing.

But now, let's see the list of material you need for this project:

  • Arduino UNO
  • Arduino NANO (optional)
  • Display CATALEX 4 digits x 7 segments (TM1637)
  • PIR sensor module
  • RTC module (DS1307)
  • Temperature & Humidity sensor module (DHT11)
  • Rotary Encoder Decoder module (KY-040)
  • Buzzer 5V
  • Sensor Shield for Arduino UNO (optional)
  • Sensor Shield for Arduino Nano (optional)
  • Wires
  • Protoboard (optional)

Note: I am from Brazil and almost all of the electronics components available for Arduino (modules, sensors, shields) come from China. I know you can have another options (even better) in your local market for those components and probably you can use them but take care with some specific libraries you maybe must update for them.

Step 2: Assembly

The assembly of components is very easy.

Just follow the assembly diagram and pay attention with the connections among the components.

Here is the summary of the main signal pins of sensors and modules to be connected on Arduino:

  • Display DIO: Digital Pin #2
  • Display CLK: Digital Pin #3
  • Encoder SW: Digital Pin #4
  • Encoder DT: Digital Pin #5
  • Encoder CLK: Digital Pin #6
  • PIR: Digital Pin #7
  • Buzzer: Digital Pin #8
  • DHT11: Digital Pin #10
  • RTC SDA: Analog Pin # A4
  • RTC SCL: Analog Pin #A5

Note: On diagram is shown the Arduino Nano for an application with more compact size but in the pictures you can see my prototype version using an Arduino Uno and a Sensor Shield to facilitate all the assembly but of course you can use protoboards to connect all components too.

Step 3: Program & Libraries

The Arduino program is attached on this page and there are also some libraries you must download and copy to your Arduino library folder :

  • TM1637Display.h - Library of Display TM1637 (I2C)
  • Bounce2.h - Library to read the Encoder key
  • TimerOne.h - Library of Timer1 #include
  • Time.h - Time Library
  • DS1307RTC.h - Library of Real Time Clock (RTC)
  • Wire.h - Library of Wire to support DS1307RTC (Real-Time Clock)
  • dht11.h - Library of Temperature and Humidity Sensor

Note: The program uses a timer to read the encoder every 1 milliseconds. This is really important to give the user an acceptable response all time that is necessary to use the encoder that has a double function: one is to set the function to be adjusted and another is to adjust the values of hours and minutes of time and of alarm.

Step 4: Setup

  • LED Display

When the digital clock is running and detecting the presence of someone near to it, all the features will be shown on LED Display during a period of two seconds of viewing for each one and according with the following sequence:

Time >> Temperature >> Humidity >> Dew Point

Symbols of:

1) Time: numbers of Hours & Minutes

2) Temperature: in Celsius degrees (ºC)

3) Humidity: in percentage (%)

4) Dew Point: in Celsius degrees but viewed on the display with a different symbol to avoid confusion with Temperature feature.

Important: The LED display will keep working only when someone is moving around the clock. In case of none movement detected, the display turns off.

  • Rotary Encoder & Switch

The uses of rotary encoders reduces the amount of keys for the setups and also simplifies its functionality for the users.

In this project the rotary encoder is used when necessary to set the time and the alarm as follows:

  1. Press once the switch of encoder to start the adjustments
  2. Rotate the encoder to set the hour of the alarm
  3. Press once the switch of encoder to move to next step
  4. Rotate the encoder to set the minutes of the alarm
  5. Press once the switch of encoder
  6. Rotate the encoder to turn on or turn off the alarm
  7. Press once the switch of encoder to move to next step
  8. Rotate the encoder to set the hour of time
  9. Press once the switch of encoder
  10. Rotate the encoder to set the minutes of time
  11. Press once the switch of encoder
  12. Rotate the encoder to turn on or turn off the time adjustments
  13. Press once the switch to finish the adjustments

Note: The time and the alarm adjustments are recorded into the memory of RTC. Even you turn off the power supply of Arduino, the RTC will keep all the data due its own 3V battery on the module.

  • PIR

The PIR module has available two keys for adjustments:

  1. Sensibility for the presence (movements) around the sensor.
  2. Time to keep the sensor turned on.

This both adjustments you can do as you prefer. Personally, I set the sensibility for almost the maximum and I set the time to show all features on LED display just once (approximately 8 to 10 seconds).

  • Dew Point

This is an important information to give you an idea about the relationship of human comfort due to temperature and the air humidity of an ambient.

Definition (from Wikipedia):

"The dew point (dew point temperature or dewpoint) is the temperature at which dew forms and is a measure of atmospheric moisture. It is the temperature to which air must be cooled at constant pressure and water content to reach saturation. A higher dew point indicates more moisture in the air; a dew point greater than 20 °C (68 °F) is considered uncomfortable and greater than 22 °C (72 °F) is considered to be extremely humid."

Calculation (in Celsius degrees):

In this project I applied a simplified formula but with a good enough approximation for personal uses:

Dew Point = Temperature - (100 - Humidity) / 5

  • Temperature Scale:

The program of this project use the Celsius degrees scale for the temperature and this is the standard for the DHT11 sensor.

If you prefer to see the temperatures in Fahrenheit degrees um must convert them as follows:

Fahrenheit = Celsius * 1.8 + 32

Step 5: Next Steps

For now this project is only a prototype to test the concept of my idea but in the next steps I want to develop a nice box and put all the main components of the clock on a single board with a microcontroller.

I hope you have enjoyed this project and please send me your comments.

Kind regards,





    • Backyard Contest

      Backyard Contest
    • Beauty Tips Contest

      Beauty Tips Contest
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    13 Discussions


    Reply 1 year ago

    Very nice. I'd love to share some INO baseline functionality code / sketches / make them even better + add support for displays, etc. :)

    Could someone share the baseline code with me so I can add some more functionality (and get this baseline schematic configured + working)?


    Question 1 year ago

    NICE WORK! Anyone have the actual baseline code to get started outside of the libraries? Just need the simple logic controlling the schematic shown. Thanks team!


    1 year ago on Step 5

    NICE WORK! Anyone have the actual baseline code to get started outside of the libraries? Just need the simple logic controlling the schematic shown. Thanks team!


    2 years ago

    how can we compile skech there is a problem dht no such file or directory error plz help me sir.

    2 replies

    Reply 2 years ago

    See the tutorial about libraries installation:


    3 years ago

    you definitely got the most out of that display. Well done

    1 reply

    Reply 3 years ago

    Thank you! Your comment inspires me to go on and to go further.