Project showcase
Multifunctional Watch With Arduino Uno

Multifunctional Watch With Arduino Uno

This watch includes temperature reading, timer and alarm functions.

  • 4,264 views
  • 2 comments
  • 8 respects

Components and supplies

Apps and online services

About this project

In this video, I show you how my watch looks like and how it works.

Code

Codes for Multifunctional WatchC/C++
I'm totally beginner to C programming language,so this is really beginner's codes,long codes,but the most important it works as what i want ! Yeah i copied some codes from other's project,but that is how we learn coding right.xoxo.Total time for coding and research are about 30 hours.And you need the libraries for RTC,Button and LCD.You can find it at github.com
#include <LiquidCrystal.h>      //  
#include <Button.h>             //  
#include <DS3231.h>             //  RTC

int buzzer = 13;                                                //set  .   13
uint8_t hh = 0, mm = 0, ss = 0;                                 //set  ,, RTC
uint8_t timerMode = 0 ,setMode=0, setAlarm=0, alarmMode=0 ;     //set    
uint8_t alarmHH =0 ,alarmMM =0 ,alarmSS=0;                      //   
uint8_t timerhh=0, timermm=0, timerss =0;                       //   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);                          // LCD 
DS3231 rtc(SDA,SCL);                                            // RTC
Time t;                                                         //    t

#define DN_PIN 7                                                  //set  pin
#define UP_PIN 8                                                  //set  pin
#define SET_PIN 9                                                 //set  
#define ALR_PIN 10                                                //set   
#define PULLUP true                                               //aktifkan  
#define INVERT true                                               //If invert ==true,HIGH=released,LOW=pressed
#define DEBOUNCE_MS 20                                            //state  react with button
#define REPEAT_FIRST 500                                          //state  untuk tekan berapa lama button
#define REPEAT_INCR 100                                           // increase kan number

//Declare push buttons
Button btnDN(DN_PIN, PULLUP, INVERT, DEBOUNCE_MS);                //set 1st button utk decrement
Button btnUP(UP_PIN, PULLUP, INVERT, DEBOUNCE_MS);                //set 2nd button utk increment
Button btnSET(SET_PIN, PULLUP, INVERT, DEBOUNCE_MS);              //set button utk function timer
Button btnALR(ALR_PIN, PULLUP, INVERT, DEBOUNCE_MS);              //set button utk function alarm

enum {WAIT, INCR, DECR};                                          //The possible states for the state machine
uint8_t STATE;                                                    //The current state machine state
int count;                                                        //The number that is adjusted
int lastCount = -1;                                               //Previous value of count (initialized to ensure it's different when the sketch starts)
unsigned long rpt = REPEAT_FIRST;                                 //A variable time that is used to drive the repeats for long presses



void setup() {
  
Serial.begin(9600);
lcd.begin(16,2);
pinMode(buzzer,OUTPUT);
rtc.begin();
lcd.setCursor(0,0);
lcd.print("Welcome Shaqib!");
delay(2000);
lcd.clear();
//rtc.setTime(12,24,00);

}

void loop() {

t=rtc.getTime();
hh=t.hour,DEC;
mm=t.min,DEC;
ss=t.sec,DEC;

btnSET.read();
btnUP.read();                             
btnDN.read();
btnALR.read();

if(setMode==0 && setAlarm==0 ){
tunjukJamTemp();
tunjukTimer();}

if(setMode!=0 && setAlarm==0 && alarmMode==0 ){delay(100);}
if(setMode==1 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(7,1);lcd.print("  ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==2 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(10,1);lcd.print("  ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==3 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(13,1);lcd.print("  ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==4 && setAlarm==0 && alarmMode==0 ){tunjukJamTemp();tunjukTimer();stepDown();delay(1000);}



if(setMode==0 && setAlarm!=0 && alarmMode==0 ){delay(100);}
if(setMode==0 && setAlarm==2 && alarmMode==0 ){lcd.setCursor(0,0);lcd.print("  ");delay(100);    lcd.setCursor(0,0);
    if(alarmHH<10){lcd.print("0");}
    lcd.print(alarmHH);lcd.print(":");
    if(alarmMM<10){lcd.print("0");}
    lcd.print(alarmMM);lcd.print(":");
    if(alarmSS<10){lcd.print("0");}
    lcd.print(alarmSS);lcd.setCursor(0,1);
    lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==3 && alarmMode==0 ){lcd.setCursor(3,0);lcd.print("  ");delay(100);    lcd.setCursor(0,0);
    if(alarmHH<10){lcd.print("0");}
    lcd.print(alarmHH);lcd.print(":");
    if(alarmMM<10){lcd.print("0");}
    lcd.print(alarmMM);lcd.print(":");
    if(alarmSS<10){lcd.print("0");}
    lcd.print(alarmSS);lcd.setCursor(0,1);
    lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==4 && alarmMode==0 ){lcd.setCursor(6,0);lcd.print("  ");delay(100);    lcd.setCursor(0,0);
    if(alarmHH<10){lcd.print("0");}
    lcd.print(alarmHH);lcd.print(":");
    if(alarmMM<10){lcd.print("0");}
    lcd.print(alarmMM);lcd.print(":");
    if(alarmSS<10){lcd.print("0");}
    lcd.print(alarmSS);lcd.setCursor(0,1);
    lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==5 && alarmMode==0 ){alarmMode=1;setAlarm=0;}

setupAlarm();
Alarm(alarmHH,alarmMM);

btnSET.read();
btnUP.read();                             
btnDN.read();
btnALR.read();


switch (STATE) {
        
        case WAIT:                            
            if (btnSET.wasPressed())
               { setMode = setMode+1;}
            if (btnALR.wasPressed())
               { setAlarm = setAlarm+1;} 
            if (btnUP.wasPressed())
                STATE = INCR;
            else if (btnDN.wasPressed())
                STATE = DECR;
            else if (btnUP.wasReleased())    
                rpt = REPEAT_FIRST;
            else if (btnDN.wasReleased())
                rpt = REPEAT_FIRST;
            else if (btnUP.pressedFor(rpt)) {  
                rpt += REPEAT_INCR;            
                STATE = INCR;
            }
            else if (btnDN.pressedFor(rpt)) {
                rpt += REPEAT_INCR;
                STATE = DECR;
            }
            break;

        case INCR:                               
            if (setMode==1 && setAlarm==0 && alarmMode==0 && timerhh<23)timerhh=timerhh+1; 
            if (setMode==2 && setAlarm==0 && alarmMode==0 && timermm<59)timermm=timermm+1;
            if (setMode==3 && setAlarm==0 && alarmMode==0 && timerss<59)timerss=timerss+1;
            if (setMode==0 && setAlarm==2 && alarmMode==0 && alarmHH<23)alarmHH=alarmHH+1;
            if (setMode==0 && setAlarm==3 && alarmMode==0 && alarmMM<59)alarmMM=alarmMM+1;
            if (setMode==0 && setAlarm==4 && alarmMode==0 && alarmSS<59)alarmSS=alarmSS+1;
            STATE = WAIT;
            break;

        case DECR:                               
            if (setMode==1 && setAlarm==0 && alarmMode==0 && timerhh>0)timerhh=timerhh-1; 
            if (setMode==2 && setAlarm==0 && alarmMode==0 && timermm>0)timermm=timermm-1;
            if (setMode==3 && setAlarm==0 && alarmMode==0 && timerss>0)timerss=timerss-1;
            if (setMode==0 && setAlarm==2 && alarmMode==0 && alarmHH>0)alarmHH=alarmHH-1;
            if (setMode==0 && setAlarm==3 && alarmMode==0 && alarmMM>0)alarmMM=alarmMM-1;
            if (setMode==0 && setAlarm==4 && alarmMode==0 && alarmSS>0)alarmSS=alarmSS-1;
            STATE = WAIT;
            break;
    }
}

 void stepDown() {
 if (timerss > 0) {
 timerss -= 1;
 } else {
 if (timermm > 0) {
 timerss = 59;
 timermm -= 1;
 } else {
 if (timerhh > 0) {
 timerss = 59;
 timermm = 59;
 timerhh -= 1;
 } else {
  for(int i=0;i<30;i++){
lcd.setCursor(0,0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(10,0);
lcd.print(rtc.getTemp());
lcd.print("C");
btnSET.read();
if(btnSET.wasPressed()){digitalWrite(buzzer,LOW);i=30;}else{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);}
}
setMode=0;

  }
 }
 }
 }
 
void tunjukTimer(){
lcd.setCursor(0, 1);
 lcd.print("Timer:");
 lcd.print(" ");
 (timerhh < 10) ? lcd.print("0") : NULL;
 lcd.print(timerhh);
 lcd.print(":");
 (timermm < 10) ? lcd.print("0") : NULL;
 lcd.print(timermm);
 lcd.print(":");
 (timerss < 10) ? lcd.print("0") : NULL;
 lcd.print(timerss);
   }

void tunjukJamTemp(){
  lcd.setCursor(0,0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(10,0);
lcd.print(rtc.getTemp());
lcd.print("C");

}

void Alarm(uint8_t alarmHH,uint8_t alarmMM){
  if(alarmMode==1 && alarmHH==hh && alarmMM==mm){
   for(int i=0;i<30;i++){
lcd.setCursor(0,0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(10,0);
lcd.print(rtc.getTemp());
lcd.print("C");
lcd.setCursor(0, 1);
 lcd.print("Timer:");
 lcd.print(" ");
 (timerhh < 10) ? lcd.print("0") : NULL;
 lcd.print(timerhh);
 lcd.print(":");
 (timermm < 10) ? lcd.print("0") : NULL;
 lcd.print(timermm);
 lcd.print(":");
 (timerss < 10) ? lcd.print("0") : NULL;
 lcd.print(timerss);
 
btnALR.read();
if(btnALR.wasPressed()){digitalWrite(buzzer,LOW);i=30;}else{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);}
    }
    alarmMode=0;
    setAlarm=0;
  }}

void setupAlarm(){
  if(setMode==0 && setAlarm==1 && alarmMode==0 ){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Set Your Alarm");
    lcd.setCursor(0,0);
    if(alarmHH<10){lcd.print("0");}
    lcd.print(alarmHH);lcd.print(":");
    if(alarmMM<10){lcd.print("0");}
    lcd.print(alarmMM);lcd.print(":");
    if(alarmSS<10){lcd.print("0");}
    lcd.print(alarmSS);
  }
}

Schematics

Circuit diagram of the watch
R339v4gffxqynvjjfmsc

Comments

Similar projects you might like

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 43,118 views
  • 21 comments
  • 121 respects

ArduTester V1.13: The Arduino UNO Transistor Tester

Project tutorial by plouc68000

  • 11,577 views
  • 36 comments
  • 42 respects

Arduino Powered CPR Feedback Device

Project showcase by David Escobar

  • 5,732 views
  • 8 comments
  • 27 respects

3-Bit Binary Calculator Using Arduino Uno

Project showcase by 22warehamD

  • 5,122 views
  • 9 comments
  • 13 respects

ARDUINO UNO or TRINKET PRO 5V 6 Chasing LEDS with POT and PB

Project tutorial by MichDragstar

  • 2,198 views
  • 2 comments
  • 5 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 116,664 views
  • 29 comments
  • 106 respects
Add projectSign up / Login