Arduino UNO Digital Clock with Alarm and Temperature Display
View and Edit Project In Cirkit Designer
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
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
DS3231 RTC
- Description: Real-Time Clock module.
- Pins: 32K, SQW, SCL, SDA, VCC, GND
16x2 I2C LCD
- Description: 16x2 character LCD with I2C interface.
- Pins: GND, VCC, SDA, SCL
Pushbutton
- Description: Momentary pushbutton switch.
- Pins: Pin 2, Pin 1, Pin 3, Pin 4
Buzzer
- Description: Piezoelectric buzzer.
- Pins: PIN, GND
KY-015 DHT11 Temperature-Humidity Sensor Module
- Description: Temperature and humidity sensor.
- Pins: VCC, GND, DOUT
Wiring Details
Arduino UNO
- 5V to VCC of DS3231 RTC, 16x2 I2C LCD, and KY-015 DHT11 Temperature-Humidity Sensor Module
- GND to GND of DS3231 RTC, 16x2 I2C LCD, KY-015 DHT11 Temperature-Humidity Sensor Module, Buzzer, and all Pushbuttons
- SCL to SCL of DS3231 RTC and 16x2 I2C LCD
- SDA to SDA of DS3231 RTC and 16x2 I2C LCD
- D7 to Pin 4 of Pushbutton 1
- D6 to Pin 4 of Pushbutton 2
- D5 to Pin 4 of Pushbutton 3
- D9 to DOUT of KY-015 DHT11 Temperature-Humidity Sensor Module
- D8 to PIN of Buzzer
DS3231 RTC
- VCC to 5V of Arduino UNO
- GND to GND of Arduino UNO
- SCL to SCL of Arduino UNO
- SDA to SDA of Arduino UNO
16x2 I2C LCD
- VCC to 5V of Arduino UNO
- GND to GND of Arduino UNO
- SCL to SCL of Arduino UNO
- SDA to SDA of Arduino UNO
Pushbutton 1
- Pin 2 to GND of Arduino UNO
- Pin 4 to D7 of Arduino UNO
Pushbutton 2
- Pin 2 to GND of Arduino UNO
- Pin 4 to D6 of Arduino UNO
Pushbutton 3
- Pin 2 to GND of Arduino UNO
- Pin 4 to D5 of Arduino UNO
Buzzer
- PIN to D8 of Arduino UNO
- GND to GND of Arduino UNO
KY-015 DHT11 Temperature-Humidity Sensor Module
- VCC to 5V of Arduino UNO
- GND to GND of Arduino UNO
- DOUT to D9 of Arduino UNO
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