Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Digital Clock with Alarm and Temperature Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Digital Clock with Alarm and Temperature Display

Circuit Documentation

Summary

This circuit is a digital clock with an alarm feature, utilizing an Arduino UNO microcontroller. It includes a DS3231 RTC module for timekeeping, a 16x2 I2C LCD for display, a DHT11 sensor for temperature and humidity readings, pushbuttons for user input, and a buzzer for the alarm. The circuit is designed to display the current time, date, and temperature, and allows the user to set an alarm.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. DS3231 RTC

    • Description: Real-Time Clock module.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  3. 16x2 I2C LCD

    • Description: 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  4. Pushbutton

    • Description: Momentary pushbutton switch.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  5. Buzzer

    • Description: Piezoelectric buzzer.
    • Pins: PIN, GND
  6. KY-015 DHT11 Temperature-Humidity Sensor Module

    • Description: Temperature and humidity sensor.
    • Pins: VCC, GND, DOUT

Wiring Details

Arduino UNO

DS3231 RTC

16x2 I2C LCD

Pushbutton 1

Pushbutton 2

Pushbutton 3

Buzzer

KY-015 DHT11 Temperature-Humidity Sensor Module

Code Documentation

#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <Wire.h>  
#include <EEPROM.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define bt_time   A0
#define bt_up     A1
#define bt_down   A2
#define bt_alarm  A3
#define buzzer 8

DS3231  rtc(SDA, SCL);

Time  t; 

int hh = 0, mm = 0, ss = 0, dd = 0, bb = 0, set_day;
int yy = 0;
String Day = "  ";

int AlarmHH  = 21, AlarmMM  = 22, AlarmSS  = 23, setMode = 0, setAlarm = 0, alarmMode=0;

int stop=0, mode=0, flag=0;

uint8_t HH;
uint8_t MM;

byte bell_symbol[8] = {
    B00100,
    B01110,
    B01110,
    B01110,
    B01110,
    B11111,
    B01000,
    B00100
};
byte thermometer_symbol[8] = {
    B00100,
    B01010,
    B01010,
    B01110,
    B01110,
    B11111,
    B11111,
    B01110
};

void setup(){
    Serial.begin(9600);
    rtc.begin(); 

    pinMode(bt_time,  INPUT_PULLUP);
    pinMode(bt_up,    INPUT_PULLUP);
    pinMode(bt_down,  INPUT_PULLUP);
    pinMode(bt_alarm, INPUT_PULLUP);
    pinMode(buzzer, OUTPUT);

    lcd.createChar(1, thermometer_symbol);
    lcd.createChar(2, bell_symbol);
    
    lcd.begin(16, 2); 
    lcd.backlight();
    lcd.setCursor(1,0); 

    lcd.setCursor (0,0);
    lcd.print(" DIGITAL CLOCK  ");
    lcd.setCursor (0,1);
    lcd.print("   With Alarm ");
    delay (2000);
    lcd.clear();

    stop=EEPROM.read(50);
    if(stop==0){  
    }else{WriteEeprom ();}

    EEPROM.write(50,0); 
    ReadEeprom(); 
}

void loop(){  
    t = rtc.getTime();
    Day = rtc.getDOWStr(1);

    if (setMode == 0){
        hh = t.hour,DEC;
        mm = t.min,DEC;
        ss = t.sec,DEC;
        dd = t.date,DEC;
        bb = t.mon,DEC;
        yy = t.year,DEC;
    }  

    if(setAlarm==0){
        lcd.setCursor(0,0); 
        lcd.print((hh/10)%10);
        lcd.print(hh % 10); 
        lcd.print(":");
        lcd.print((mm/10)%10);
        lcd.print(mm % 10);
        lcd.print(":");
        lcd.print((ss/10)%10);
        lcd.print(ss % 10);
        lcd.print(" ");  
        if(mode==1){lcd.write(2);}
        else{lcd.print(" ");}   
        lcd.print(" "); 
        lcd.write(1); 
        lcd.print(rtc.getTemp(),0);
        lcd.write(223); 
        lcd.print("C");
        lcd.print("  "); 

        lcd.setCursor(1,1);
        lcd.print(Day);
        lcd.print(" ");
        lcd.print((dd/10)%10);
        lcd.print(dd % 10); 
        lcd.print("/");
        lcd.print((bb/10)%10);
        lcd.print(bb % 10);
        lcd.print("/"); 
        lcd.print((yy/1000)%10);
        lcd.print((yy/100)%10);
        lcd.print((yy/10)%10);
        lcd.print(yy % 10);
    }

    setupClock();
    setTimer();
    delay (100);
    blinking();

    if (alarmMode==1 && mode==1 && hh==AlarmHH && mm==AlarmMM && ss>=AlarmSS) {
        digitalWrite(buzzer, HIGH);
        delay (300);
        digitalWrite(buzzer, LOW);
    }else{digitalWrite(buzzer, LOW);}

    delay (100);
}

void blinking (){
    //BLINKING SCREEN
    if (setAlarm <2 && setMode == 1){lcd.setCursor(0,0);  lcd.print("  ");}
    if (setAlarm <2 && setMode == 2){lcd.setCursor(3,0);  lcd.print("  ");}
    if (setAlarm <2 && setMode == 3){lcd.setCursor(6,0);  lcd.print("  ");}
    if (setAlarm <2 && setMode == 4){lcd.setCursor(1