DIY Arduino Digital Watch

filler(58)
Published in
#arduino
Words
594
Reading
3 min
8y
Listen to this post
~4 min

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
#include

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
    #include
    #include

    #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)