Table of Contents

Smart Clock on the AVR Platform

Student: Ilie Lucian-Alexandru

Grupa: 331CB

Introduction

The smart clock described in this project is a stand-alone device built around an AVR micro-controller (an Arduino-compatible UNO board). It continuously shows the time and date on a 0.96″ OLED display; it beeps briefly at every full hour; after 19:00 it gradually lights two LEDs acting as the hour- and minute-hands; and it adapts LED brightness to the room light level using an LDR sensor. The purpose of the project is to demonstrate features taken from at least three PM laboratories—Timers & ISR (Lab 2), PWM (Lab 3) and the I²C bus (Lab 6)—inside a useful, easy-to-demonstrate gadget. It also gives hands-on experience with an I²C OLED/LCD, a DS3231 RTC module and simple peripherals (LED, buzzer, LDR). The idea came from the fact that most low-cost electronic clocks drift by several minutes per month and have fixed brightness. By integrating a precision RTC and PWM/ADC control logic we eliminate these drawbacks. The clock is useful at home as a real gadget, can be easily extended (multiple alarms, temperature display, Bluetooth connection) and helps consolidate embedded-systems skills.

General Description

Smart-clock implementation on the AVR platform

Schema bloc|

The project is organized around an Arduino UNO R3, which acts as the brain of the system and links all modules. On the I²C bus two devices are connected: a DS3231 real-time clock, from which the micro-controller reads highly accurate time and date, and a 0.96″ OLED display where this information is shown permanently. Two 5 mm LEDs, driven by PWM outputs, work as the clock “hands” and light up gradually after 19:00, indicating the passage of time without being intrusive during daytime. One more LED, a RGB one, is used with D9/D10/D11 pins with PWM for breathing effect and colour cycling. A passive buzzer, connected to a third PWM channel, emits a short beep at every full hour; the 1 kHz tone is generated by a hardware timer that starts and stops automatically. The ambient-light level is taken from a photo-resistor (LDR) on an analog pin; the ADC readings are used to dim the LEDs when the room is well lit.

Hardware Design

List of materials for the smart clock:

Current hardware implementation status:

  • All modules are wired on the breadboard and have been tested both individually and together
  • DS3231 RTC keeps accurate time (drift \< ± 1 s / day)
  • SSD1306 OLED shows the current time + ambient-light level (“Light level:”) once per second
  • LDR reacts correctly (0 – 1023) and is used to drive a PWM brightness control
  • LEDs:
    • Red – blinks at 1 Hz (handled by a Timer1 ISR)
    • Green – lights for 1 s whenever the minute changes
    • RGB – PWM “breathing” effect; switching colours on BTN press
  • Buzzer plays short beeps and a longer “gong” on each full hour
  • All three push-buttons operate with `INPUT_PULLUP` and falling-edge detection

Nr. Component Functional role in project Pin / Library
1 Arduino UNO R3 MCU + Timers/ISR + PWM + I²C master
2 RTC DS3231 (I²C) Keeps real-time clock, internal temperature, alarm RTClib
3 0.96″ OLED SSD1306 (I²C) Displays time, lux and LED mode Adafruit_SSD1306
4 Photo-resistor (LDR) + 10 kΩ divider Measures ambient light (auto-dimmer) A0
5 5 mm LED (red) Second indicator (Timer ISR) D5
6 5 mm LED (green) 1 s flash whenever the minute changes (PWM-ready) D6
7 RGB LED PWM “breathing” effect; 7-colour cycling via PWM D9/D10/D11 (PWM) + 3 × 220 Ω resistors
8 Passive buzzer Beep feedback & hourly gong D3 (tone)
9 BTN HOUR Increment hour D2
10 BTN MIN Increment minute + beep D4
11 BTN MODE Toggle blue-LED mode D7
12 Breadboard + Dupont leads Rapid prototyping
13 Resistors&nbsp;220 Ω / 10 kΩ LED current limiters / LDR voltage divider

Pin mapping:

  • I²C bus (RTC + OLED) — pins SDA / SCL (dedicated I²C lines, on-board pull-ups)
  • LDR (photo-resistor)A0 · 10-bit ADC input
  • Red LEDD5 · toggled by Timer1 ISR at 1 Hz (no PWM needed)
  • Green LEDD6 · digital OUT / PWM-ready – flashes for one second each minute change
  • RGB LEDD9/D10/D11 · hardware PWM used for smooth *breathing* effect and colours cycling
  • BuzzerD3 · `tone()` uses Timer2 for precise frequency generation
  • BTN HOURD2 · INT0-capable input (configured with `INPUT_PULLUP`)
  • BTN MIND4 · digital input (`INPUT_PULLUP`)
  • BTN MODED7 · digital input (`INPUT_PULLUP`)
  • PWM-capable pins (D3 / D5 / D6 / D9 / D10 / D11) were selected so they don’t clash with the I²C bus (A4/A5) or the UART lines (D0/D1)

Electric scheme

The following diagram shows all components connected on the breadboard, including the RTC, OLED, LDR, 3 LEDs (Red, Green, RGB), passive buzzer, and 3 buttons.

Wiring diagram|

Connected components & functionalities

Working Diagram|

Light diagram|

The following pictures show the physical assembly of all modules connected on a breadboard:

Software Design

Development environment: Arduino IDE 2.3.7

Libraries:

  • Wire.h – establishes I²C communication with the RTC and OLED display
  • RTClib.h – used to read and write time from the DS3231 real-time clock module
  • Adafruit_GFX.h – provides core graphics functions (fonts, shapes, text positioning) for the OLED
  • Adafruit_SSD1306.h – handles display control over I²C for the 128×64 OLED screen

Core functionalities implemented and tested:

Functions implemented

Program logic

How it works

New features introduced (vs. template)

  • Time-dependent LED behavior:
    • Classic blinking/flashing before 19:00
    • LED “hands” with proportional PWM after 19:00
  • Auto-dimming feature using LDR sensor and PWM reduction
  • Dynamic buzzer behavior (silent hours implemented in software)
  • Multi-mode RGB LED, including a white flashing effect on long-press
  • OLED updates every second: Time, light level, current RGB mode, dim status

Features implemented from labs

Lab 3 – PWM, LED breathing & analogRead

Lab 4 – millis(), timer-based updates & OLED/RTC integration

Lab 5 – tone() and auditory feedback

Lab 6 – I²C bus, debouncing, edge detection, and button logic

Testing & calibration

  • LDR threshold value (`ldrThreshold = 400`) chosen after testing under normal room lighting
  • RGB LED tested with dimming and full brightness in varying light conditions
  • Buttons debounced and tested for both short press and hold
  • Verified correct PWM values for hour (0–23) and minute (0–59) mapping
  • Buzzer output silenced reliably in “quiet hours” 19:00–23:59

Software optimizations

  • No `delay()` usage – entire loop is non-blocking using `millis()`
  • Only updates OLED once per second to avoid flicker
  • PWM outputs adjusted only when needed
  • All state variables and timing use unsigned types (overflow-safe)
  • `tick` flag separates logic from timing checks

Video explanation

  • Demo includes:
    • Full operation cycle (LED behavior before and after 19:00)
    • RGB LED mode change & white blink effect
    • LDR dimming effect with covered/uncovered sensor
    • Time update via buttons (HOUR, MINUTE)
    • Buzzer feedback with conditional silence
    • OLED display showing all real-time parameters

Rezultate Obţinute

The results after completing all the project:

https://streamable.com/nzzcwh

This video presents the base functionalities of the smart clock: * The OLED screen displays real-time data: current time, ambient light level (lux), and the active RGB color index. * The RGB LED changes color with each short press of BTN MODE, cycling through 7 predefined colors. * Holding BTN MODE triggers a visual feedback mode where the RGB LED blinks white at 4 Hz. * The Dim mode (based on LDR readings) reduces LED brightness in low light conditions. * The hour and minute buttons allow manual time adjustments.

https://streamable.com/ryv6rw

This clip shows the additional functionality activated after 19:00: * The red LED (D5) no longer blinks but gradually brightens depending on the current hour. * The green LED (D6) lights up with intensity proportional to the current minute. This simulates a simple hour-and-minute hand system using LED brightness. After 00:00, both LEDs return to their standard behavior (blinking and minute-flash). Additionally, the RGB LED adapts to ambient light using the LDR sensor. When you shine light onto the photoresistor, the RGB LED's brightness increases accordingly. In darker environments, the RGB LED automatically dims (enters dim mode) for smoother visual integration during nighttime. </note>

Conclusions

The development of this project provided valuable experience across both hardware and software domains, offering a practical understanding of embedded systems and real-time interaction.

Skills and competencies acquired:

Practical benefits and applications:

In conclusion, this project served as a comprehensive introduction to embedded system design—combining real-time programming, sensor integration, display systems, and human interaction into a cohesive and practical implementation.

Download

Link for the code: https://github.com/Ilie28/Proiect-PM

Journal

06.05.2025 – decided on the project, wrote the description and the hardware materials
11.05.2025 – materials bought, starting on the hardware design
13.05.2025 – tested RTC, OLED, LDR, buzzer and buttons independently
15.05.2025 – implemented LED functionality (blinking, PWM, mode switching)
16.05.2025 – finished integration: all modules tested together
17.05.2025 – added RGB LED support and 7-color switching logic
18.05.2025 – finalized code, added edge detection, PWM breathing, and buzzer feedback
19.05.2025 – created and uploaded schematic + wiring diagram
20.05.2025 – documented project structure and updated project page
22.05.2025 – finalized software logic and display integration; completed all wiki documentation

Bibliography/Resources

Hardware Resources

Software Resources:

Export to PDF