Skip to main content
Version: FILS English

Smart Clock

A smart clock with an alarm, display, temperature/humidity monitoring and a web interface.

info

Author: Dumitrescu Andrei-Bogdan
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-Andreid04

Description

This project is built using the Raspberry Pi Pico 2W, capable of displaying the current time and date on a small OLED display, and live temperature/humidity data on another small LCD display that also shows a real-time graph of both temperature and humidity. The current temperature and humidity also change color depending on their value. The device fetches accurate time from the internet every 2 hours, and offers the possibility to set alarms. Alarms can be heard through a passive buzzer placed on the breadboard.

Motivation

I always wanted a machine that sits on my desk and keeps track of time and schedule related stuff while also offering information about what is happening in the air of my room(humidity and temperature). I wanted a fully customizable clock that is also "smart" but i could not find anything that i like in a store. So i decided to take this opportunity and create the smart clock that i wanted with full customizability and pleasent looking OLED and LCD displays for a fraction of the price of a similar clock bought from the internet.

Architecture

General Schematic

schema

Components overview

  • Microcontroller
    • The Raspberry Pi Pico 2W microcontroller handles the data from the sensor and the web interface in order to active an alarm, show and update information on the screens;
  • Sensor service
    • polls DHT22 for temperature & humidity every 2 seconds and writes the data to the LCD display, updating the graphs in real time;
  • Clock Service
    • fetches the exact time from the internet every 2h and keeps local RTC synced;
  • Alarm Handler
    • creates and triggers the alarm created by the user;
  • Display units
    • The OLED display shows the clock, alarms and the date;
    • The LCD display is used for temperature and humidity monitoring and their respective graphs.

Log

Week 5 - 11 May

  • Set up ST7735 lcd and SSD1306 oled displays with embedded-graphics.
  • Drew dynamic temperature/humidity graphs and live colored changes if values are between a known good range.

progress1

Week 12 - 18 May

  • Got the second display (ssd1306 OLED) to display the correct date and time in hours:minutes:seconds in real time.
  • Added 2 buttons through which you can set alarms and view them on the screen. The first button is used to enter/exit alarm modes:
    • default: nothing alarm related appears on the screen
    • set hour: sets the alarm hour
    • set minute: sets the alarm minute at which it will trigger
    • toggle alarm on/off: if off the alarm will not be triggered at the specified time
  • The second button increments the alarm hour/ minute /toggle functionality.
  • When the alarm triggers, a buzzer will pulse for 3 seconds with 3 audible beeps on different pitched tones (50-200hz).

progress2

Week 19 - 25 May

  • 3D Printed a support with feet for the project and tied up the wires for a cleaner look.
  • Moved the set alarm functionality on an asynchronous task for efficiency and faster response although it may create some noise on the screens if they do not get clean, stable power.
  • Finally got the Wi-Fi part working and sending the sensor data to a python web server that uses Flask. Time is sent from the server to the pico every 2h, mainly before initializing the screen and the main loop in order to have an accurate date and time displayed.
  • At the PM Fair the project will look even better, i am thinking of putting a plexiglass sheet raised on some supports but i don't currently have the cutting tools.

progress3

graph

Hardware

  • 2x Raspberry Pi Pico 2W (one acts as a debugger): The brains of the smart clock. It supports the wi-fi interface for sending and receiving data from an external device;
  • Breadboard + jumper wires: for connecting the peripherals to the pico and to power;
  • ST7735 TFT LCD display (SPI): acts as a colored screen for displaying the temperature and humidity info, their graphs and color mapping if the paramters are healthy or not(green, yellow and red);
  • SSD1306 OLED (secondary SPI display): used for displaying the clock, the date and the alarms;
  • DHT22 (temperature + humidity sensor): used for monitoring the temperature and humidity of the air with the help;
  • Passive buzzer + resistor (GPIO controlled): a buzzer that is controlled through PWM on a PWM capable GPIO pin(20);
  • 12V power supply terminated to a barrel jack feeding the HW131 power supply that outputs regulated 3.3V and 5V DC. (I only use 3.3V for this project).

hw1

hw2

Schematics

KiCAD schematic

kicad

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico 2WThe microcontroller40 RON
DHT22 SensorTemp & humidity monitoring23 RON
ST7735 LCDColor display 160x128 1.8'29 RON
Passive BuzzerAlarm feedback2 RON
Kit Breadboard + wires + HW131 power supplyPrototyping setup and 3.3/5V PSU22 RON
SSD1306 OLEDSecondary text display for clock and alarms24 RON

Software

LibraryDescriptionUsage
ssd1306Crate to interface with SSD1306 OLED displayControl the display
st7735Display driver for ST7735 LCDControl the display
embedded_graphics2D graphics library that is minimal in used resourcesUsed for writing and drawing to the display
embedded_halAbstraction layer for MCU driversInterfaces for all peripherals
embedded_dht_rsTemperature/humidity sensor crateFor controlling and reading data from the DHT22 sensor
pwmPWM moduleFor controlling the active buzzer on a precise tone in HZ
cyw43Driver for the CYW43 Wi-Fi chip on the Pico WSupport for wi-fi station mode and AP mode as well as bluetooth support
heaplessFixed-capacity collections for no_stdUsed for String buffers and messaging, can be instantiated in a static variable
chronoTimezone-aware date and time handlingUsed for the clock and the alarm in order to keep track of time accurately
embassy_netAsync embedded TCP/IP network stackUsed to serve a web interface over Wi-Fi
embassy_rpAccess to the pheripheralsInitializing and talking to peripherals
embassy_executorProvides an executor for running asynchronous tasks concurrentlyExecute asynchronous tasks concurrently
embassy_timeTimekeeping, delays and timeoutsSchedule tasks to run at specific times
embassy-syncAsync synchronization primitivesUsed for Mutex in screens and sharing data through TCP
display-interface-spiSPI display abstractionFacilitates SPI communication between spi screens and device
static-cellSafe static memory allocatorUsed to initialize and store static data
defmtA highly efficient logging framework that targets resource-constrained devices, like microcontrollersPrints out messages in the terminal(debugging)
  1. SSD 1306 setup with SPI
  2. Pico 2W in kicad
  3. DHT22 data sheet and crate usage
  4. Embedded-graphics examples
  5. Simple rust examples with pico
  6. Demo of working project on youtube