Project tutorial
Arduino Wristwatch

Arduino Wristwatch

A wristwatch that consists of Arduino UNO, an RTC (DS1307), and SSD1306 128x32 OLED screen.

  • 250 views
  • 1 comment
  • 0 respects

Components and supplies

Apps and online services

About this project

My ambition was to create a minimal size project that can show off my talent. Anyways, this project consists of Arduino IDE, Real-Time Clock, and an OLED screen. I have created a wristwatch that consists of an OLED screen that displays the date and time.

In this project, these two modules are connected by means of the I2C wire system, or it is commonly called a Two-Wire Interface. In this interfacing technique, the Arduino UNO acts as the Master device, while the OLED screen and RTC act as the Slave device.

Remember that RTC has a specific I2C Address that is 0x68, and the OLED screen has another specific I2C address that is 0x3C. Hence, this allows the Arduino UNO to communicate these two devices very easily.

In the program, I have added various Bitmaps to make my project look beautiful. I have added the battery charging Icon, No battery Icon,The percentage battery Icon, and also various event-related Icons.

This program consists of various functions that perform when a Menu button is pressed, it adds to the menu and stores the result to the variable menu.

For example, menu = menu + 1, hence, the new number stored in the menu is 1, we have initialized the menu with zero i.e menu = 0;

In that specific loop, I have added the call function like DisplayDateTime();, at the bottom of the program, you will find all functions, here I mention the above function for the call function voidDisplayDateTime(), and in this way, all the functions are present in the program.

Another thing that I have added in the menu program is the battery charging and the discharging function. The LiPo battery charger i.e. TP4056 module input pin is connected to the Arduino analog pin A1 i.e. powerRead = A1, using the ADC conversion formula, detects the voltage entering the Arduino UNO. Once, it detects the voltage, then it displays the battery icon on the OLED screen.

Another analog pin is used to monitor the percentage of the charging left in the battery by using the variable i.e. voltRead = A2, using the same ADC conversion, detects charging left in the battery, and when the battery is low, then it shows the low battery icon on the screen.

I have provided the specific links of the library that will allow you to communicate with the device very easily.

Here is the link for RTC Library:> https://github.com/adafruit/RTClib

Here is the library for Adafruit GFX :> https://github.com/adafruit/Adafruit-GFX-Library

Here is the link for Adafruit_SSD1306 :>https://github.com/adafruit/Adafruit_SSD1306

I have also provided the code, which is very simple and easy to understand.

It is expected that by the end of this month, I will design the case for this project, right now it is still in this condition.

Code

Arduino WristwatchArduino
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>

#define OLED_RESET LED_BUILTIN
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS1307 rtc;
int button1 = 11;  // For modes
int button2 = 12;  // For increment 
int powerRead = A1;
int voltRead = A2;
float powerVoltage = 0.0;
float batteryVoltage = 0.0;
int hourupg, minuteupg, secondupg, dayupg, monthupg, yearupg;
int menu = 0;
char DAY[7][12] = {"Sunday",   "Monday",   "Tuesday",   "Wednesday",   "Thrusday",   "Friday",   "Saturday"};

// 'Battery Charger sign_3', 10x16px
const unsigned char battery [] PROGMEM = {
  0x1e, 0x00, 0x1e, 0x00, 0x7f, 0x80, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0xf7, 0xc0, 0xf7, 0xc0, 
  0xe1, 0xc0, 0xe1, 0xc0, 0xfb, 0xc0, 0xfb, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x7f, 0x80
};

const unsigned char no_battery [] PROGMEM = {
  0x1e, 0x00, 0x12, 0x00, 0x3f, 0x40, 0x20, 0x80, 0x21, 0x00, 0x23, 0x00, 0x23, 0x00, 0x25, 0x00, 
  0x29, 0x00, 0x11, 0x00, 0x21, 0x00, 0x21, 0x00, 0x61, 0x00, 0xa1, 0x00, 0x21, 0x00, 0x3f, 0x00
};

// 'ChargedBatteryIcon', 25x10px
const unsigned char chargedBattery [] PROGMEM = {
  0x7f, 0xff, 0xfc, 0x00, 0xff, 0xff, 0xfe, 0x00, 0xdc, 0xe7, 0x72, 0x00, 0xdc, 0xef, 0x7b, 0x00, 
  0xdc, 0xef, 0x7b, 0x80, 0xdc, 0xef, 0x7b, 0x80, 0xdc, 0xef, 0x7b, 0x00, 0xdc, 0xe7, 0x72, 0x00, 
  0xe3, 0x00, 0x96, 0x00, 0x7f, 0xff, 0xfe, 0x00
};

// 'batteryIconCharging_horizontal', 25x10px
const unsigned char batteryChargeIcon [] PROGMEM = {
  0x7f, 0xff, 0xf0, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0xc0, 0x60, 0x0f, 0x80, 
  0xc3, 0xf0, 0x0d, 0x80, 0xc0, 0x3f, 0x0d, 0x80, 0xc0, 0x38, 0x0f, 0x80, 0xc0, 0x00, 0x0c, 0x00, 
  0xc0, 0x00, 0x0c, 0x00, 0x7f, 0xff, 0xf0, 0x00
};




void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.setTextSize(1);
  Wire.begin();
  rtc.begin();
  display.clearDisplay();
  display.display();

  if (!rtc.begin())
  {
    display.setCursor(0, 0);
    display.print("RTC Error");
    display.display();
  }
  else if(!rtc.isrunning())
  {
    display.setCursor(0, 0);
    display.print("RTC is not working");
    display.display();
  }
  else
  {
    display.clearDisplay();
    display.setCursor(0, 0);
    display.print("Initializing");
    for(int i = 12; i <= 17; i++)
    {
      delay(200);
      display.print(".");
      display.display();
    }
    delay(2000);
    display.clearDisplay();
    display.display();
  }
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  menu = 0;
}


void loop()
{
  if (digitalRead(button1) == LOW)
  {
    menu = menu + 1;
  }
  if (menu == 0)
  {
    DisplayDateTime();
  }
  if (menu == 1)
  {
    DisplaySetHour();
  }
  if (menu == 2)
  {
    DisplaySetMinute();
  }
  if (menu == 3)
  {
    DisplaySetDay();
  }
  if (menu == 4)
  {
    DisplaySetMonth();
  }
  if (menu == 5)
  {
    DisplaySetYear();
  }
  
  if (menu == 6)
  {
    if (batteryVoltage >= 5.0)
    {
      BatteryDisplay();
    }
    else
    {
      display.clearDisplay();
      display.setCursor(0, 0);
      display.print("Battery is not");
      display.setCursor(0, 12);
      display.print("connected");
      display.display();
    }
  }

  if (menu == 7)
  {
    if (powerVoltage >= 3.7)
    {
      BatteryCharging();
    }
    else
    {
      display.clearDisplay();
      display.setCursor(0, 0);
      display.print("Please connect the");
      display.setCursor(0, 12);
      display.print("battery");
      display.display();
    }
  }
  
  if (menu == 8)
  {
    Storing();
    delay(500);
    menu = 0;
  }
  delay(100);
  
  powerVoltage = analogRead(powerRead) * (5.0 / 1023.0);
  if (powerVoltage >= 4.69)
  {
    display.drawBitmap(0, 13, battery, 10, 16, WHITE);
  }
  batteryVoltage = analogRead(voltRead) * (3.7 / 1023.0);
  if (batteryVoltage >= 0.00)
  {
    display.drawBitmap(0, 13, no_battery, 10, 16, WHITE);
  }
  
}


void DisplayDateTime()
{
  DateTime now = rtc.now();
  
  //display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(17, 15);

  if (now.hour() <= 9)
  {
    display.print("0");
  }
  display.print(now.hour(), DEC);
  hourupg = now.hour();
  display.print(":");

  if (now.minute() <= 9)
  {
    display.print("0");
  }
  display.print(now.minute(), DEC);
  minuteupg = now.minute();
  display.print(":");
  
  if (now.second() <= 9)
  {
    display.print("0");
  }
  display.print(now.second(), DEC);
  secondupg = now.second();
  
  display.setCursor(0, 0);
  display.setTextSize(1);
  display.print(DAY[now.dayOfTheWeek()]);

  display.setCursor(65, 0);
  if (now.day() <= 9)
  {
    display.print ("0");
  }
  display.print(now.day(), DEC);
  dayupg = now.day();
  display.print("/");
  
  if (now.month() <= 9)
  {
    display.print("0");
  }
  display.print(now.month(), DEC);
  monthupg = now.month();
  display.print("/");
  
  display.print(now.year(), DEC);
  yearupg = now.year();

  display.display();
  delayMicroseconds(5);
  display.clearDisplay();
}

void DisplaySetHour()
{
  display.clearDisplay();
  
  DateTime now = rtc.now();

  if (digitalRead(button2) == LOW)
  {
    if (hourupg == 23)
    {
      hourupg = 0;
    }
    else
    {
      hourupg = hourupg + 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set Hour: ");
  display.setCursor(40, 20);
  display.print(hourupg, DEC);
  display.display();
  delay(100);
}

void DisplaySetMinute()
{
  
  if (digitalRead(button2) == LOW)
  {
    if(minuteupg == 59)
    {
      minuteupg = 0;
    }
    else
    {
      minuteupg = minuteupg + 1;
    }
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Set Minutes: ");
  display.setCursor(40, 20);
  display.print(minuteupg, DEC);
  display.display();
  delay(100); 
}

void DisplaySetDay()
{
  if (digitalRead(button2) == LOW)
  {
    if (dayupg == 31)
    {
      dayupg = 1;
    }
    else
    {
      dayupg = dayupg + 1;
    }
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Set Day: ");
  display.setCursor(40, 20);
  display.print(dayupg, DEC);
  display.display();
  delay(100);
}

void DisplaySetMonth()
{
  if (digitalRead(button2) == LOW)
  {
    if (monthupg == 12)
    {
      monthupg = 1;
    }
    else
    {
      monthupg = monthupg + 1;
    }
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Set Month: ");
  display.setCursor(40, 20);
  display.print(monthupg, DEC);
  display.display();
  delay(100);
}

void DisplaySetYear()
{
  if (digitalRead(button2) == LOW)
  {
    if (yearupg == 2099)
    {
      yearupg = 2000;
    }
    else
    {
      yearupg = yearupg + 1;
    }
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Set Year: ");
  display.setCursor(40, 20);
  display.print(yearupg, DEC);
  display.display();
  delay(100);
}

void Storing()
{
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Saving in Progress");
  rtc.adjust(DateTime(yearupg, monthupg, dayupg, hourupg, minuteupg, secondupg));
  display.display();
  delay(200);
}

void BatteryDisplay()
{
  int volts;
  batteryVoltage = analogRead(voltRead);
  volts = (batteryVoltage / 1023) * 100;

  if (volts == 100)
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, chargedBattery, 25, 16, WHITE);
    display.setCursor(30, 20);
    display.print("Charged: ");
    display.print(volts);
    display.print("%");
    display.display();
    delay(100);
  }
  else if (volts < 100)
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, chargedBattery, 25, 16, WHITE);
    display.setCursor(30, 20);
    display.print("Remaining: ");
    display.print(volts);
    display.print("%");
    display.display();
    delay(100);
  }
  else
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, chargedBattery, 25, 16, WHITE);
    display.setCursor(30, 20);
    display.print("No battery");
    display.display();
    delay(100);
  }
  
}

void BatteryCharging()
{
  int pvolts;
  powerVoltage = analogRead(powerRead);
  pvolts = (powerVoltage / 1023) * 100;

  if(pvolts == 100)
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, batteryChargeIcon, 25, 10, WHITE);
    display.setCursor(30, 20);
    display.print("Charged: ");
    display.print(pvolts);
    display.print("%");
    display.display();
    delay(100);
  }
  else if (pvolts < 100)
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, batteryChargeIcon, 25, 10, WHITE);
    display.setCursor(30, 20);
    display.print("Charging: ");
    display.print(pvolts);
    display.print("%");
    display.display();
    delay(100);
  }
  else
  {
    display.clearDisplay();
    display.drawBitmap(40, 10, batteryChargeIcon, 25, 10, WHITE);
    display.setCursor(0, 20);
    display.print("Connect to charger if battery is down");
    display.display();
    delay(100);
  }
} 

Schematics

Top side
Top side ht9wsskcp1
Bottom side
Bottom part 1qzejydk95

Comments

Similar projects you might like

Pixie: An Arduino Based NeoPixel Wristwatch

Project tutorial by Konstantin Dimitrov

  • 7,931 views
  • 5 comments
  • 47 respects

Binary Wristwatch

Project showcase by thallia

  • 2,223 views
  • 0 comments
  • 12 respects

Adjusting Dual Clock using DS3231 on 1.8" ST7735 Display

Project showcase by FLORICA Tudor-Nicusor

  • 8,142 views
  • 3 comments
  • 18 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 70,041 views
  • 71 comments
  • 218 respects

Arduino101 / tinyTILE BLE: Match-Making Sunglasses

Project tutorial by Kitty Yeung

  • 14,795 views
  • 5 comments
  • 46 respects

Arduino 101 - Intel Curie Pattern Matching Dress

Project tutorial by Kitty Yeung

  • 12,989 views
  • 19 comments
  • 62 respects
Add projectSign up / Login