Create Clock in Arduino  Step by Step Guide ▷ 2021

One of the best features of Arduino, is its versatility and ease of use, since it is a platform based on free software and hardware that supports creators and developers. Therefore, it is a great tool for create open source electronics projects.

Among the main jobs it allows to perform Arduino, found the clocks. By default, these are ideal to start practicing and become more familiar with the tricks that the platform offers.

Worth knowing how to create a clock with Arduino and what uses it can be given; which, you can find out in this post. As well as the best kits available on the market to implement these ideas.

What do I need to create an Arduino clock from scratch? Used materials

To build such an accessory with the help of Arduino, certain items are required software and hardware dependent. In the case of software, it is only necessary to use the Arduino integrated development environment (or Arduino IDE) which is the multiplatform app written in programming language Java.

In terms of hardware, it is recommended use an arduino board (either Arduino UNO or any other model), like, an RTC module and male-female cables. If you want to create a digital clock, you should also use: a 7-segment and 4-digit display, a breadboard (breadboard), a 9V battery, a pair of push buttons and 6 220 ohm resistors (or Similar).

Learn step by step to create a clock with Arduino from scratch to use in other projects

As we highlighted above, it is necessary to use software and hardware elements when building a clock with Arduino.

Therefore, during the creation process, it is worth considering the following step-by-step methods:

Via Software

Via Software

Initially, you have to make the clock with Arduino hand in hand with the development environment of this platform. Based on a library (in this case, Time.h) that must be installed by any of the following ways: Adding Library. Zip, through the library folder or through the Library Manager. To add the Time library to the Arduino IDE, simply click on the tab “Program”, select the option “Include Library” and choose “Time” in the listing.

This will add the following code to the software:

#include <Time.h>

#include <TimeLib.h>

void setup() {

// put your setup code here, to run once:

} 

void loop() {

// put your main code here, to run repeatedly:


}

To run the first clock functions with Arduino (hour, minutes and seconds), the code corresponds to:

#include <Time.h>

#include <TimeLib.h>

void setup() {

Serial.begin(9600);

}

void loop() {

// Imprimimos la hora

Serial.print("Hora: ");

Serial.print(hour());

Serial.print(":");

Serial.print(minute());

Serial.print(":");

Serial.println(second());

delay(1000);

}

To set the code correctly, it is worth considering that eIn the setup () function, the serial monitor is started to display the data:

void setup() {

Serial.begin(9600);

}

In the loop () function, the functions are used:

Serial.print(hour()); Para devolver la hora.

 

Serial.print(minute()); Para devolver los minutos.

 

Serial.println(second()); Para devolver los segundos.

 

Serial.print(day()); Para devolver el día del mes.

 

Serial.print(month()); Para devolver el mes.

 

Serial.println(year ()); Para devolver el año.

Later, to put the correct time on the clock with Arduino, use the setTime (…) function which can be called in different ways, depending on the various parameters to return one type of foundation or another; depending on the needs of the creator or user. In this case, the data are important: hour, minutes, seconds, day, month and year, as follows: setTime (hour, minutes, seconds, day, month, year);

Thus, the modified code would be the following, for example:

void setup() {

begin(9600);

// Establecemos la hora y la fecha

setTime(11, 40, 6, 14, 8, 2021);

}

By Hardware

By Hardware

To build a clock with Arduino from hardware, RTC component required. Well, these use a crystal oscillator or the frequency of the network and they serve to have a real time clock that hinders the errors that the Time.h library usually throws (sometimes it loses the time). In general, RTCs have an alternative power supply that is used when the main power is off and guarantees the preservation of the time and date at all times.

Within the extensive range of RTCs suitable for Arduino, the components stand out DS3231 and DS1307 which are closed circuits. Between these two solutions, the DS3231 is much more accurate than the DS1307, because it has an internal oscillator in which temperature changes do not intervene and only, it can present a lag of a few minutes during the year. While, the DS1307 may lag 5 minutes per month, due to extreme temperatures that tend to affect its accuracy.

Likewise, the DS3231 has certain alarm functions (that is, it can work as an alarm clock too). However, both components are capable of generate a square wave of various frequencies (to serve as a clock signal) and have an EEPROM memory. Regarding the connection, this is simple because both DS3231 and DS1307 use the I2C bus.

In summary, depending on the Arduino model that is used, the pins that should be used are:

  • Arduino UNO, PRO MINI: SDA = A4 and SCL = A5.
  • Arduino LEONARDO, YUN: SDA = 2 and SCL = 3.
  • Arduino MEGA, DUE: SDA = 20 and SCL = 21.
  • Arduino MKR1000: SDA = 11 and SCL = 12.

Notably, SDA is the data signal and SCL is the clock signal.

If you have any questions, leave them in the comments, we will answer you as soon as possible, and it will surely be of great help to more members of the community. Thanks! 😉

Saharay Pérez

Author: Saharay Pérez

My passion is technology and social networks, I research and document the latest news and tricks from Facebook, Twitter, Instagram, WhatsApp and any social network.

You may be interested:

Leave a Comment