DIY Arduino Digital Watch

in #arduino6 years ago (edited)

Make your own Arduino Digital Watch!!

P_20180604_204440.jpg

In my earlier article on learning Arduino (Learning Arduino – Part 1) I mentioned about making an Arduino smartwatch. Well I did try making that and here, I have written about how I made an Arduino watch. It’s not “smart” yet, as it only shows the time, day and date. You can link it with your smartphone by adding a Bluetooth module, for doing things like notifying for incoming calls or text messages and so on. I will cover that in another article. Here let’s see how to make an Arduino digital watch.

Components Needed

The components needed for this project are :-

1. Arduino Uno

(I used an Uno for prototyping, but will replace it with a ProMini while finalising the design and after the case is 3D printed)

arduino.png

2. 0.96” OLED screen

oled.png

3. DS1307 Real Time Clock Module

rtc.png

(The RTC module has two chips - one is the DS1307 clock IC and the other is an EEPROM chip to store the clock log.)

4. Breadboard

breadboard.png

5. Bunch of jumper cables

P_20180604_204827.jpg

Wiring diagram

The components are to be connected the manner shown.

Capture.PNG

The pins for the OLED and the RTC module was connected to the respective SDA and SCL pins in the Arduino.
Power and ground were connected to the 5v and GND of Arduino respectively.

Software – Setting time in the RTC

Now for the code part.

At first we will have to hook-up the RTC module alone and upload a program to set the correct time on it. Once it is set, it will be stored in its memory and will output the correct time from then onwards.
For this, connect the power and ground of the RTC module to the 5v and GND of Arduino, and the SDA and SCL to pins A4 and A5 respectively. Then upload the following code to the Arduino to set the current time of the computer into the RTC module.

#inlcude<RTCLib.h>
#include<Wire.h>

RTC_DS1307 rtc;
 
  void setup()
{

Serial.begin(9600);
Wire.begin();

 Rtc.begin();
Rtc.adjust(DateTime(F(__DATE__),F(__TIME__))):

}

void loop()
{
 // nothing here
// You can display the time which was set in the serial monitor if you want
}


Software – OLED and time displaying

Now, the time and date are set in the RTC module. We can read it and display it in the OLED screen. This completes our basic Arduino watch. For this connect the OLED screen as per the diagram.
The code for processing the time and displaying it on the screen is given below.

    #include<Wire.h>
    #include<Adafruit_GFX.h>
    #include<Adafruit_SSD1306.h>

    #define DS1307_ADDRESS 0x68

    byte read_second;
    byte read_minute;
    byte read_hour;
    byte read_day;
    byte read_date;
    byte read_month;
    byte read_year;

     const char *dayname[7] = {
       "Sun","Mon","Tue","Wed","Thu","Fri",”Sat”
      };


    byte binary_to_decimal(byte val)
    { 
        return((val/16*10)+(val%16));
    }

    byte decimal_to_binary(byte val)
    { 
       return((val/10*16)+(val%10));
    }

    #define OLED_RESET 4

    Adafruit_SSD1306  oled(OLED_RESET);

    void setup() {
 
        Wire.begin();
        Wire.beginTransmission(DS1307_ADDRESS);
        Wire.write(0);
        Wire.endTransmission();

        oled.begin(SSD1306_SWITCHCAPVCC);
        oled.clearDisplay();
        oled.setTextColor(WHITE);
        oled.setTextSize(1);
        oled.setFontSize(1);
 
}



     void loop() {
 
          Wire.requestFrom(DS1307_ADDRESS,7);

          read_second = binary_to_decimal(Wire.read());
          read_minute = binary_to_decimal(Wire.read());
          read_hour = binary_to_decimal(Wire.read());
          read_day = binary_to_decimal(Wire.read());
          read_date = binary_to_decimal(Wire.read());
          read_month = binary_to_decimal(Wire.read());
          read_year = binary_to_decimal(Wire.read());

          oled.clearDisplay();

          oled.setCursor(20,5);
          oled.setTextSize(2);
          oled.println(read_hour);

          oled.setCursor(43,5);
          oled.println(":");

          oled.setCursor(55,5);
          oled.println(read_minute);

          oled.setCursor(80,5);
          oled.println(":");

         oled.setCursor(89,5);
         oled.println(read_second);

         oled.setTextSize(1);
         oled.setCursor(22,25);
         oled.println(read_date);

         oled.setCursor(37,25);
         oled.println("-");

         oled.setCursor(46,25);
         oled.println(read_month);

         oled.setCursor(54,25);
         oled.println("-");

         oled.setCursor(62,25);
         oled.println(read_year);

         oled.setCursor(90,25);
         oled.println(dayname[read_day]);

         oled.display();
 
         delay(1000);  //waits for one second before refreshing

}


Conclusion

After all this, you'll get a working arduino digital watch.

P_20180604_204440.jpg

We used the RTC module to get time, store it and display it in the OLED screen. Even if you cut off the power and restart it after some time, the RTC will give the correct time.

P_20180604_204510.jpg

(Note:- The code and the circuit diagram given here are for the I2C version of the OLED screen. As you might have noticed, I am having an SPI OLED board. I had to make slight variations to the code and the wiring. I wrote with the I2C version in mind as it is more commonly available and is easier to work with.)

Now we have only one simple function that is to display time, day and date. We would like to have more in our DIY watch. This is just the first part for building a powerful smartwatch. We can add interrupts to the code and make the arduino sleep to save power and display the time only when we need it. By writing the required code, we can add menus to change the time, set alarms, play games and whatever you can imagine.

Image Source - Self (Wiring diagram made by myself with Fritzing)

Sort:  
Congratulations This post has been upvoted by SteemMakers. We are a community-based project that aims to support makers and DIYers on the blockchain in every way possible.

Join our Discord Channel to connect with us and nominate your own or somebody else's posts in our review channel.

Help us to reward you for making it ! Join our voting trail or delegate steem power to the community account.

Your post is also presented on the community website www.steemmakers.com where you can find other selected content.

If you like our work, please consider upvoting this comment to support the growth of our community. Thank you.

Thank you!! I would certainly like to know more about the maker community in Steemit!

An interesting read, you can also Join Utopian.io and post other Open Source Tutorials. If you would like to know more about it check https://join.utopian.io/guidelines/, or join the discord for any other information.

Thank you!! I'll look into Utopian.io and will post more tutorials in the future.

Hi @filler!

Your post was upvoted by utopian.io in cooperation with steemmakers - supporting knowledge, innovation and technological advancement on the Steem Blockchain.

Contribute to Open Source with utopian.io

Learn how to contribute on our website and join the new open source economy.

Want to chat? Join the Utopian Community on Discord https://discord.gg/h52nFrV

Thank you!! I really would like to participate and contribute more to this community.

Congratulations @filler! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got a First Reply

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Please do join https://discord.gg/sMv6c4 utopian-io

Coin Marketplace

STEEM 0.35
TRX 0.12
JST 0.040
BTC 70638.80
ETH 3565.34
USDT 1.00
SBD 4.73