Smart Clock
A smart clock with an alarm, display, temperature/humidity monitoring and a web interface.
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
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.
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).
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.
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).
Schematics
KiCAD schematic
Bill of Materials
Device | Usage | Price |
---|---|---|
Raspberry Pi Pico 2W | The microcontroller | 40 RON |
DHT22 Sensor | Temp & humidity monitoring | 23 RON |
ST7735 LCD | Color display 160x128 1.8' | 29 RON |
Passive Buzzer | Alarm feedback | 2 RON |
Kit Breadboard + wires + HW131 power supply | Prototyping setup and 3.3/5V PSU | 22 RON |
SSD1306 OLED | Secondary text display for clock and alarms | 24 RON |
Software
Library | Description | Usage |
---|---|---|
ssd1306 | Crate to interface with SSD1306 OLED display | Control the display |
st7735 | Display driver for ST7735 LCD | Control the display |
embedded_graphics | 2D graphics library that is minimal in used resources | Used for writing and drawing to the display |
embedded_hal | Abstraction layer for MCU drivers | Interfaces for all peripherals |
embedded_dht_rs | Temperature/humidity sensor crate | For controlling and reading data from the DHT22 sensor |
pwm | PWM module | For controlling the active buzzer on a precise tone in HZ |
cyw43 | Driver for the CYW43 Wi-Fi chip on the Pico W | Support for wi-fi station mode and AP mode as well as bluetooth support |
heapless | Fixed-capacity collections for no_std | Used for String buffers and messaging, can be instantiated in a static variable |
chrono | Timezone-aware date and time handling | Used for the clock and the alarm in order to keep track of time accurately |
embassy_net | Async embedded TCP/IP network stack | Used to serve a web interface over Wi-Fi |
embassy_rp | Access to the pheripherals | Initializing and talking to peripherals |
embassy_executor | Provides an executor for running asynchronous tasks concurrently | Execute asynchronous tasks concurrently |
embassy_time | Timekeeping, delays and timeouts | Schedule tasks to run at specific times |
embassy-sync | Async synchronization primitives | Used for Mutex in screens and sharing data through TCP |
display-interface-spi | SPI display abstraction | Facilitates SPI communication between spi screens and device |
static-cell | Safe static memory allocator | Used to initialize and store static data |
defmt | A highly efficient logging framework that targets resource-constrained devices, like microcontrollers | Prints out messages in the terminal(debugging) |