Arduino Analog clock with DS1307

arduino_my_name_analogclock.png Another experiment with Arduino based on experiment with TFT 240×320 display using driver chip ILI9341 and DS1307 real time clock module.

Turn out this can be a nice analog-clock on my desk to replace the widget analog-clock of windows 7.

Update 13/Oct/2016

Analog Clock v2.4


- Use DS3231 - extreme precise does not effect by temperature like DS1307
- Clockface with date/time inside

Version 2.3

ds1307analogclockfinish.jpg ds1307analogclockfinish2.jpg ds1307analogclockfinishinside.jpg

Behind the scene

ds1307clockface.jpg ds1307clockface-backpack.jpg

The circuit

This Analog clock uses precision RTC DS1307 for time keeping and uses arduino-pro-mini clone to read the time from DS1307 and displays it on the TFT screen as Analog clock.

When using arduino Uno, you can power DS1307 RTC module directly with IO pins using A2 sink to GND, and A3 pull up to Vcc and connect the TFT display through a 5v to 3v3 level shifter module.


Time update on PC code:

If you use ArduinoPro mini (clone) like mine, you have to use a USB / Serial adaptor like this. You should not connect DTR pin because PL2303 acts weird sometime, and send DTR signal before everytime data is sent from PC. And thus it makes ArduinoPro mini restart when PC app scan the com port. Actually I got mix up between output pin and input pin of AMS1117, but somehow LCD works even it was almost 4v. After fixing, arduinoPro mini no longer restart when scanning com port.

The code consists of two part:
- Code for Arduino: Read time and draw a clock, receive time from serial connection (Com port)
- Code from PC: Auto scan from COM1 to COM16 and send time to Arduino if Analog Clock is found

Libraries and tool:

  1. Kenjutsu

    Monday, August 3, 2015 - 20:00:13


    Awesome! Which version of the Adafruit_GFX library are you using?

  2. ceez

    Monday, August 3, 2015 - 20:15:57


    The old version, which doesn’t support class Adafruit_GFX_Button.

    But the newest update of Adafruit_GFX library should work without problem since they just add new class Adafruit_GFX_Button to the library without making changes to the existing code.

  3. Kenjutsu

    Monday, August 3, 2015 - 21:47:49


    Thank you for the reply. One more question, are you using a custom version of Adafruit_ILI9341?

  4. ceez

    Monday, August 3, 2015 - 21:56:10


    Nope :)

  5. Kenjutsu

    Monday, August 3, 2015 - 22:18:43


    Thank you for the reply. The reason I asked was because of this line:

    Adafruit_ILI9341 tft = Adafruit_ILI9341();

    There does not seem to be a default/empty constructor in Adafruit_ILI9341, but by passing the correct pins to one of the overloaded constructors, it does compile :-)

  6. ceez

    Monday, August 3, 2015 - 22:44:19


    I don’t know, maybe my version is very old which I still use since Arduino IDE 1.0

    Yes, it should work.

    #define SCLK 13  // Don't change
    #define MOSI 11  // Don't change
    #define MISO 12  // Don't change
    #define CS 10
    #define DC 9
    #define RST -1 // connect to Reset of arduino or 3v3
    Adafruit_ILI9341(CS,  DC, MOSI, SCLK, RST, MISO);

    I am too lazy to update these libraries when it still works :D

  7. Donald Fischer

    Friday, May 20, 2016 - 01:54:48


    I am really impressed with this and trying to use in a larger project… I am just learning the programming (thru trial and error) and wonder if you could point me in the write direction..

    exit status 1
    no matching function for call to ‘Adafruit_ILI9341::Adafruit_ILI9341()

  8. ceez

    Friday, May 20, 2016 - 19:21:39


    Same thing was asked by Kenjutsu.

    I updated the sketch to use with official adafruit library.

    Or you can modify the source code:

    From line 135, add these line:

    #define SCLK 13  // Don't change
    #define MOSI 11  // Don't change
    #define MISO 12  // Don't change
    #define CS 10
    #define DC 9
    #define RST -1 // connect to Reset of arduino or 3v3
    Adafruit_ILI9341 tft = Adafruit_ILI9341(CS,  DC, MOSI, SCLK, RST, MISO); // Invoke standard library from adafruit
    //Adafruit_ILI9341 tft = Adafruit_ILI9341();       // Invoke custom library
  9. Donald Fischer

    Sunday, May 22, 2016 - 07:36:34


    I hope you can help… I am getting this error… The file is there

    SDKDDKVer.h: No such file or directory

    #include <SDKDDKVer.h>

  10. ceez

    Sunday, May 22, 2016 - 08:03:09


    Remove that line. It serves no purpose since this is not a driver but a simple console app. The WinSDK on my PC automatically put that line there.

  11. Fish

    Sunday, May 22, 2016 - 09:26:49


    I saved as and it worked.. Thx

  12. faruk

    Sunday, June 5, 2016 - 13:32:52


    fatal error: struct.h: No such file or directory
    i get this error :(

  13. ceez

    Sunday, June 5, 2016 - 18:26:36


    Extract the whole thing to a folder. Don’t run it inside a zip file.

  14. Daniel Fernandes

    Saturday, July 9, 2016 - 04:11:38


    Greetings Ceez!

    The sketc that is giving the error is “AnalogClock version 1.0” (not AnalogClock2.31)
    Error: no matching function for call to ‘Adafruit_ILI9341 :: Adafruit_ILI9341 ()’

    What should be corrected? Thank you

  15. ceez

    Saturday, July 9, 2016 - 15:27:48


    Solution in comment #8

  16. Daniel Fernandes

    Saturday, August 27, 2016 - 09:05:49


    Hi friend! The code is loading normally but appears multiple clock faces on display, overlapping each other; What can it be? Thank you

  17. ceez

    Saturday, August 27, 2016 - 15:39:47


    It happens because of the mechanism use to update clock face.

    In short, after about 0.9 second, it draws black hands overlap on old time (second changes or minute changes) in order to erase old clock hands, this way much faster than fill a circle or rectangle with black. After *erase* old hands, draw new color hands that reflect of new time. Since timing of the MCU (microcontroller) doesn’t match with RTC or else we don’t need RTC module, you will experience it ticks 2 seconds sometime. It happens because update interval of MCU is larger than 1 second. You can change it shorter than 1s and see the result.

    By small chance, old time is not the same as old time which has been drawn on clock face. Thus black hands were drawn on different position and so old hands are not erased.

    The way I store old time in code, in order to redraw black hands overlap, is not optimised. It just quick and dirty way to make the code works. So, bugs expected. I think it is a little bit better in version 2.3, but I still experience that bug once a day if I leave it powered on 24/7.

    Since I connect it to my PC and let it on and off with PC, that bug doesn’t show up in time frame 5-6 hours.

    So, to eliminate that bug. You should use square wave out put from DS1307 module to trigger time update instead of using sleep(900). Use code like button, check if button is high or low. Otherwise, you can use interrupt like pin change as trigger as well. Oh, and fix the code I use to store old time for erase old hands.


Add comment

Fill out the form below to add your own comments

User data

Add your comment

[color=red] TEXT [/color]
[quote] TEXT [/quote]
[code=arduino avrasm cpp css java javascript nginx perl python] TEXT [/code]
Clear format