In this post we are going to construct a cool looking analog clock using Arduino and servo motors. We will learn how to set time to RTC module and how to control servo motors which are essential knowledge to construct this analog clock.
We will see:
- What is RTC?
- How to set time to RTC module
- What is servo motor?
- How to control servo motor
- Circuit diagram
- Program code
- Layout and description of the clock
The internet is filled with circuit diagrams of digital clocks but we can hardly find any circuit diagram of analog clocks, this is because analog clocks involves mostly with mechanical parts like gears with least electronics and the mechanism of gears is a overkill for an average hobbyist.
In this project there will be utilizing mechanical as well as electronic parts and these are readily and easily available on market. You will just need a couple of servo motors, an RTC module and an Arduino board of your wish, the finished project will look like the above featured image, you can add your creativity to improve the look of the clock.
Overview of construction:
- The servo motors can rotate 180 degree in both directions. There are two motors one for hours hand and one for minute hand.
- Each hour marking is with difference of 15 degree angle and each minute is with difference of 3 degree angle.
- The markings of minutes (0, 5, 10, 15…) are with 15 degree angle difference, the minute hand moves 3 degree every minute, hours hand moves 15 degree every hour pointing the correct numbers.
- The RTC module will keep track of time and arduino controls both the servo motors.
Now let’s explore about the components and modules involved in this project.
What is RTC?
RTC stands for Real Time Clock Module, which is used for tracking the correct time accurately. It is designed for microcontrollers and microprocessors which can keep track of time even after disconnecting the power for longer period.
It has a backup 3V lithium cell which can last more than a year. The module has DS1307 IC which is the one keeps track of time and it is connected to quartz crystal oscillator which provides the clock signal for the IC.
It not only tracks the time but also tracks date, month, year with leap year compensation up to year 2100. It consumes only 500uA which gives very long battery life and it can detect power failure and switch to battery mode automatically.
All computer devices and digital watches boasts RTC module.
It communicates to microcontroller or microprocessor with I2C or IIC or “I square C” protocol which involves only two wires between the master and salve device.
Now you know what RTC module is and what it is used for, we will learn how to set time to this DS1307 RTC module later in this article.
What is Servo Motor?
Servo motor is a type of motor whose actuator can be precisely controlled and can stay in a particular angle. It fights against any external force acting on the actuator and stay in the requested position. This is achieved by providing a feedback signal to the motor’s controllers.
Servo motors can only rotate 180 degree and it is controlled by PWM signal. The servo motor consists of complex gear mechanism, a DC motor and a controller with a feedback system.
The DC motor is fitted inside the housing of servo, so does the gears and the controller. The gears will reduce the speed of rotation at the output but it increases the torque which we want from a servo motor.
How to control Servo motor?
Servo motor has 3 pins, red is +5V, brown is –Ve and orange is PWM input. Applying 1 ms to 2 ms PWM signal we can sweep the actuator from 0 to 180 degree. By applying 1 millisecond signal the actuator will point at 0 degree, by applying PWM at 1.5 milliseconds the actuator will point at 90 degree angle and applying 2 milliseconds the actuator will point at 180 degree angle.
Let’s see how PWM signal looks like for 1 ms, 1.5 ms and 2 ms PWM signals:
1 millisecond PWM for zero degree:
1.5 milliseconds PWM for 90 degree angle:
2 milliseconds for 180 degree angle:
By sending train of signals from 1 to 2 ms we can set the actuator to our desire angle. Now you know how to control the actuator’s angle of the servo motor, but we no need to apply the PWM signals, Arduino will take care of the pulsing procedure for servo; we just need to input the desire angle, arduino will take care of the rest.
Circuit Diagram for Analog Clock Using Arduino:
The circuit is fairly simple and self-explanatory, just connect the wiring as per the schematic. You can choose any Arduino board.
Download the following library files:
Now let’s see how to set time to RTC:
- Construct the given circuit fully.
- Open the Arduino IDE.
- Go to Files > Examples > DS1307RTC > SetTime
- Upload the sketch to the arduino.
- After uploading the code, open the serial monitor.
- It will say the time is set.
- Now go to Examples > DS1307RTC > ReadTest
- And upload that code and open serial monitor.
- It should say “ok” and display the time.
After the above time setting procedure you can upload the below main program code to arduino:
Program for analog clock using Arduino:
Layout and Description: