0% found this document useful (0 votes)
14 views15 pages

Project Report Aa

Uploaded by

hexazenpai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

Project Report Aa

Uploaded by

hexazenpai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DIGITAL CLOCK

PROJECT REPORT

Submitted
by

AADIL MUHAMMED

Reg No : MBC22EC001

ECT206 : COMPUTER ARCHITECTURE &


MICROCONTROLLER
ABSTRACT

ARDUINO DIGITAL CLOCK


In this project, I made a simple Digital Clock using Arduino without using RTC
Module With two push buttons to control hour , minute and seconds selection and
controlling each.

Components Required -
1. Arduino UNO-1
2. OLED Display(128X64 I2C) -1
3. Push button -2
4. Breadboard -1
5. Jumber Wires
6. DC Power Supply
Circuit Diagram

2
CONTENTS

CHAPTER 1

• Introduction

CHAPTER 2

• Proposed Work
• Design and Modelling

CHAPTER 3

• Results

CHAPTER 4

• Conclusion

3
INTRODUCTION

In an era dominated by digital technology, the humble clock remains an essential


part of everyday life, providing us with a sense of time and structure. While
traditional analog clocks have their charm, digital clocks offer a precise and
easily readable alternative. This project aims to harness the power of modern
electronics to create a versatile and customizable digital clock using an Arduino-
based digital clock by integrating the Arduino Uno with an OLED display. Instead
of using the RTC (Real Time Clock) module, I utilize the Arduino’s built-in clock,
making it cost-effective and lightweight.

4
PROPOSED DESIGN

In this chapter, we will delve into the proposed design and implementation of the digital
clock system. This section will provide a comprehensive overview of the hardware and
software components involved, as well as the overall architecture of the system.

The main components used on the project are

• ARDUINO UNO
• OLED DISPLAY
• PUSH BUTTONS

ARDUINO UNO

The Arduino Uno is an open-source microcontroller board based on the Microchip


ATmega328P microcontroller (MCU) and developed by Arduino.cc and initially released
in 2010. The microcontroller board is equipped with sets of digital and analog
input/output (I/O) pins that may be interfaced to various expansion boards (shields) and
other circuits.[1] The board has 14 digital I/O pins (six capable of PWM output), 6 analog
I/O pins, and is programmable with the Arduino IDE (Integrated Development
Environment), via a type B USB cable. It can be powered by a USB cable or a barrel
connector that accepts voltages between 7 and 20 volts, such as a rectangular 9-volt
battery. It has the same microcontroller as the Arduino Nano board, and the same
headers as the Leonardo board. The hardware reference design is distributed under a
Creative Commons Attribution Share-Alike 2.5 license and is available on the Arduino
website. Layout and production files for some versions of the hardware are also available.

The word "uno" means "one" in Italian and was chosen to mark a major redesign of the
Arduino hardware and software. The Uno board was the successor of the Duemilanove
release and was the 9th version in a series of USB-based Arduino boards. Version 1.0 of
the Arduino IDE for the Arduino Uno board has now evolved to newer releases. The
ATmega328 on the board comes preprogrammed with a bootloader that allows uploading
new code to it without the use of an external hardware programmer.

5
While the Uno communicates using the original STK500 protocol, it differs from all
preceding boards in that it does not use a FTDI USB-to-UART serial chip. Instead, it uses
the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial
converter.

SPECIFICATIONS

Microcontroller (MCU)
IC: Microchip ATmega328P (8-bit AVR core)
Clock Speed: 16 MHz on Uno board, though IC is capable of 20 MHz maximum at 5
Volts
Flash Memory: 32 KB, of which 0.5 KB used by the bootloader
SRAM: 2 KB
EEPROM: 1 KB
USART peripherals: 1 (Arduino software default configures USART as a 8N1 UART)
SPI peripherals: 1
I²C peripherals: 1
Operating Voltage: 5 Volts
Digital I/O Pins: 14
PWM Pins: 6 (Pin # 3, 5, 6, 9, 10 and 11)
Analog Input Pins: 6
DC Current per I/O Pin: 20 mA
DC Current for 3.3V Pin: 50 mA
Size: 68.6 mm x 53.4 mm
Weight: 25 g
ICSP Header: Yes
Power Sources:
USB connector. USB bus specification has a voltage range of 4.75 to 5.25 volts. The
official Uno boards have a USB-B connector, but 3rd party boards may have a
miniUSB / microUSB / USB-C connector.
5.5mm/2.1mm barrel jack connector. Official Uno boards support 6 to 20 volts,
though 7 to 12 volts is recommended. The maximum voltage for 3rd party Uno boards
varies between board manufactures because various voltage regulators are used, each
having a different maximum input rating. Power into this connector is routed
through a series diode before connecting to VIN to protect against accidental reverse
voltage situations.
VIN pin on shield header. It has a similar voltage range of the barrel jack. Since this
pin doesn't have reverse voltage protection, power can be injected or pulled from this
pin. When supplying power into VIN pin, an external series diode is required in case
barrel jack is used. When board is powered by barrel jack, power can be pulled out of
this pin.

6
OLED DISPLAY

OLED is an organic light-emitting diode, also known as organic dot laser display.
Composed of a very thin coating of organic materials that emit light and a glass
substrate, it has self-luminous properties, a large viewing angle and low power
consumption.
It doesn’t need a backlight ( it will light up when the driver and wiring up are correct).
It has high contrast and fast response speed, applied for flexible surface. In addition, it is
easy to build.
The module comes with 4 positioning holes, which is convenient for you to fix it on other
devices.

This OLED display module is small, only 0.96” diagonal, it is made of 128x64 individual
blue OLED pixels, each one is turn on or off by the controller chip.

It works without backlight, that is, in a dark environment, OLED display is higher
compared to that of LCD display, you will like the miniature for its crispness

7
SPECIFICATIONS

Working voltage: DC 3.3V-5V


Working current: 30mA
Interface: pin header interface with a pitch of 2.54mm
Communication method: I2C communication
Internal driver chip: SSD1306
Resolution: 128*64
Viewing angle: more than 150°
Size: 33*35*3mm
Hole spacing: 30.5mm (length) 29mm (width)
Weight: 7.1g

PUSH BUTTON

A push-button (also spelled pushbutton) or simply button is a simple switch mechanism


to control some aspect of a machine or a process. Buttons are typically made out of hard
material, usually plastic or metal. The surface is usually flat or shaped to accommodate
the human finger or hand, so as to be easily depressed or pushed. Buttons are most
often biased switches, although many un-biased buttons (due to their physical nature)
still require a spring to return to their un-pushed state.

8
CIRCUIT DIAGRAM

U1_5V

U1
VIN RX
5V TX
3.3V D2
D3
D4
AREF
U2 IOREF
D5
D6
VCC RES
D7
S1 S2
Arduino D8
D9
A0
SDA A1 UNO D10
OLED SCL A2
A3
D11
D12
A4 D13
A5 SDA
GND SCL

GND

U1_GND

9
WORKING

The main connections are the OLED Display is connected to Arduino UNO by
connecting the VCC to the 5v pin of the Arduino and the GND of OLED Display to the
GND of the Arduino and the pin SDA of Display to the A5 of Arduino and the SCL of the
Display to the A4 of the Arduino.

And Push buttons enable the time set and reset is connected by grounding the one pin of
button and other to pin 2 and 3.

After the successful flashing of the code we can set and select which one is to be set can
be done by pressing the push buttons

Due to the Utilisation of the internal clock of Arduino we can minimize the size of
circuit and also save money for extra RTC(Real Time Clock) Module.

One Disadvantage of the project is onces the circuit gets powered off we have to set the
time again.
We can resolve this by using an RTC module.

10
RESULT

1. Digital Clock Display: The OLED display will show the current time in hours,
minutes, and seconds format. The time will be continuously updated, and you'll see the
seconds counting up in real-time.

2. Button Functionality:
- Mode Button (PIN_BUTTON_MODE): Pressing this button will cycle through
different modes, such as showing the current time and setting the seconds, minutes, or
hours.
- Set Button (PIN_BUTTON_SET): Depending on the current mode, pressing this
button will allow you to adjust the time parameters. For example, in set mode, pressing
the set button will increment the selected time parameter (seconds, minutes, or hours).

3. Time Adjustment:
- When in set mode, you can use the set button to adjust the seconds, minutes, or
hours. Each press of the set button will increment the selected time parameter by one.
- The time adjustment is implemented with debouncing to ensure accurate and
reliable button presses.

4. Visual Animation:
- There's a visual animation implemented to show the passing seconds. You'll see a
progress bar on the OLED display that represents the percentage of the current second
elapsed.

5. Automatic Timekeeping:
- The code automatically keeps track of time, incrementing the seconds, minutes, and
hours accordingly. It ensures that the time values stay within their valid ranges (e.g.,
seconds range from 0 to 59, minutes and hours range from 0 to 59 and 1 to 12
respectively).

6. User-Friendly Interface:
- The OLED display provides a clear and easy-to-read interface for viewing the time
and interacting with the clock settings.
- The button controls allow for intuitive navigation and adjustment of time
parameters.
11
CODE

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

byte hours = 0;
byte minutes = 0;
byte seconds = 0;

const int PIN_BUTTON_MODE = 3;


const int PIN_BUTTON_SET = 2;

const int BUTTON_MODE_DEBOUNCE_TIME = 250;


const int BUTTON_SET_DEBOUNCE_TIME = 10;

const int MODE_SHOW_TIME = 0;


const int MODE_SET_SECONDS = 3;
const int MODE_SET_MINUTES = 2;
const int MODE_SET_HOURS = 1;

unsigned long elapsedButtonModeMillis = 0;


unsigned long previousButtonModeMillis = 0;

unsigned long elapsedButtonSetMillis = 0;


unsigned long previousButtonSetMillis = 0;

char timeString[9];

unsigned long currentMillis = 0;


int elapsedTimeUpdateMillis = 0;
unsigned long previousTimeUpdateMillis = 0;
float percentageOfSecondElapsed = 0;
byte currentMode = MODE_SHOW_TIME;
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {

u8g2.setFont(u8g2_font_logisoso28_tf);
u8g2.begin();
pinMode(PIN_BUTTON_MODE, INPUT_PULLUP);
pinMode(PIN_BUTTON_SET, INPUT_PULLUP);

void loop(void) {

currentMillis = millis();
12
if (digitalRead(PIN_BUTTON_MODE) == LOW) {
buttonModeHandler();
}

if (digitalRead(PIN_BUTTON_SET) == LOW) {
buttonSetHandler();
}
checkTime();

if (currentMode == MODE_SHOW_TIME) {
increaseSeconds();
} else {
previousTimeUpdateMillis = currentMillis;
}

drawScreen();
}
void checkTime() {

if (seconds > 59) {


seconds = 0;
minutes++;
}
if (minutes > 59) {
minutes = 0;
hours++;
}
if (hours > 12) {
hours = 1;
}
}

void buttonModeHandler() {
elapsedButtonModeMillis = currentMillis - previousButtonModeMillis;
if (elapsedButtonModeMillis > BUTTON_MODE_DEBOUNCE_TIME) {
Serial.println("Mode Handler");
previousButtonModeMillis = currentMillis;
currentMode++;

if (currentMode > 3) {
currentMode = 0;
}

}
}

void buttonSetHandler() {
elapsedButtonSetMillis = currentMillis - previousButtonSetMillis;
Serial.println(elapsedButtonSetMillis);
if (elapsedButtonSetMillis > BUTTON_SET_DEBOUNCE_TIME) {
Serial.println("Set Handler");
previousButtonSetMillis = currentMillis;

13
if (currentMode == MODE_SET_SECONDS) {
seconds = 0;
}
if (currentMode == MODE_SET_MINUTES) {
minutes++;
}
if (currentMode == MODE_SET_HOURS) {
hours++;
}
}
}

void increaseSeconds() {
elapsedTimeUpdateMillis = currentMillis - previousTimeUpdateMillis;

if (elapsedTimeUpdateMillis > 1000) {


seconds++;
previousTimeUpdateMillis = currentMillis - (elapsedTimeUpdateMillis - 1000);
}
}

void drawScreen() {
u8g2.firstPage();

do {

if (currentMode != MODE_SHOW_TIME) {
u8g2.drawTriangle((currentMode - 1) * 43 + 5, 0, currentMode * 43 - 5, 0, (currentMode - 1) * 43 + 21, 5);
}

drawAnimation();
drawTime();

} while (u8g2.nextPage());
}

void drawTime() {

sprintf_P(timeString, PSTR("%2d:%02d:%02d"), hours, minutes, seconds);


u8g2.drawStr(0, 45, timeString);

void drawAnimation() {
percentageOfSecondElapsed = elapsedTimeUpdateMillis / 1000.0;

if (currentMode == MODE_SHOW_TIME) {
u8g2.drawBox(0, 0, 127 - (127 * percentageOfSecondElapsed), 2);
u8g2.drawBox(0, 3, (127 * percentageOfSecondElapsed), 2);
}
}

14
CONCLUSION

In conclusion, the development and implementation of the Arduino UNO-based digital


clock project have been a success, resulting in a functional and versatile timekeeping
system. Through the integration of Arduino UNO, OLED display, and push buttons, we
have created a user-friendly and reliable device capable of accurately displaying and
adjusting time parameters.

Achievements and Findings

1. Accurate Timekeeping: The digital clock system demonstrates precise timekeeping


functionality, ensuring that the displayed time remains accurate and reliable.
2. User Interaction: The incorporation of push buttons allows for intuitive user
interaction, facilitating the setting and adjustment of time parameters with ease.
3. Visual Representation: The visual animation implemented on the OLED display
provides a dynamic representation of the passing seconds, enhancing the user
experience and readability of the clock display.
4. Robustness and Stability: The code includes debounce mechanisms to mitigate the
effects of mechanical bouncing, ensuring stable and consistent button inputs.

15

You might also like