Position Based Multifunction Cube Clock

by sunyecz06 in Circuits > Clocks

7681 Views, 94 Favorites, 0 Comments

Position Based Multifunction Cube Clock

Cube Clock
2.jpeg
6.jpeg
3.jpeg
4.jpeg
5.jpeg

This is an Arduino based clock featuring an OLED display that functions as a clock with the date, as a nap timer, and as a nightlight. The different "functions" are controlled by an accelerometer and are selected by rotating the cube clock.

I wanted a new nightstand clock but I didn't want to spend money on a fancy clock that had tons of functions that I wouldn't use. Additionally, I had been collecting components and sensors that were just laying around so I decided to use them to make my own clock!

I had a few goals for this project:

  1. Display that time with an option to be turned off
  2. Include a nightlight function
  3. Include a 15 minute nap timer with alarm
  4. Be able to display the date

Supplies

Prototype and Test the Circuit

Cube Clock Breadboard.jpg
Cube Clock Schematic.jpg
Arduino Library.png

Connect components to the Arduino. The breadboard layout or schematic are shown above.
The RTC and OLED use I2C protocol to interface with the Arduino and utilize the A4 and A5 pins.
The Accelerometer uses 3 analog pins. I used A0, A1, A2.
The LEDs and Piezo can use any of the digital pins, I used 4 and 8 respectively.

Interface with each component. I had to install some Arduino libraries to interface with each component. They are shown in the image above.

Code using the Arduino IDE. I sifted through some example sketches provided by each library to figure out the proper syntax for each component based on what I wanted them to do. I came up with a sketch for each component to test them individually. They are provided below.
I started with the piezo speaker because it was the easiest. It actually didn't need a special library, just a specific function that sets the frequency and sound.
Getting the LEDs to work just required pulling one of the digital pins high and low.
Next, I moved onto the OLED and this was pretty simple to setup as well. The sketch below is an Adafruit demo that goes through all of the animations/texts that can be displayed.
Then, I tried to get the RTC to work. The sketch I provided was part of an example in the library that gets the current time and prints it to the serial monitor.
Finally, I used the provided example to test the accelerometer. The outputs of each axis are printed on the serial monitor.

Now time to put everything together!

Main Program

Screen Shot 2020-03-25 at 6.35.35 PM.png
Boundries.jpg

Now that I know everything works individually, I can start coming up with a program that brings everything together. I will discuss my process for writing the program below but feel free to just download the full code below to use for your own project. I tried to leave specific comments so that you can walk through the code yourself.

I needed to display the time and date on the OLED which was fairly simple. I just had to print the the current time to the display instead of the serial monitor. There were a few formatting things I had to account for to make it display a 12 hour format instead of 24 and add/remove 0's where they were appropriate. The date was similar with the addition of displaying the month and day within rectangles drawn on the screen. I used a nested FOR loop to create the timer and set off the piezo after the end of the loop. I decided to make the screen flash as the buzzer was going off which was a basic animation taken from the Adafruit demo. I made turning the cube back to the clock position the only way turn off the buzzer. Finally, I wanted a way to turn the screen off which was accomplished by just clearing the display. Now, I needed all these functions to work based on the accelerometer outputs. I used the Accel_Test script to determine the axis coordinates of each position I wanted each function to run. I manually moved the accelerometer chip around and recorded the readouts on the serial monitor. The diagram above gives the output coordinates of each position in GREY. The coordinates in RED are the boundaries between each position and I used those numbers for my program. In the 4 display positions, only the X and Y axis coordinates are needed. The fifth position for the nightlight utilizes the Z axis. I used simple IF statements for the accelerometer positions before each function block. If you use a different accelerometer, these coordinates may vary and will need to be adjusted in the program.

3D Printing the Cube

CAD3.png
CAD1.png
CAD2.png

I figured a cube would be the best design to accommodate how I wanted the clock to function. I used fusion360 to make the model. I needed a cutout for the OLED and the barrel jack. I also wanted easy access to replace the cell battery in the RTC after everything was wired. I needed a slot to keep the Arduino in an orientation that would be easy to reprogram if necessary. Additionally the enclosure needed to be easily removable so that I can access the Arduino. You can see the CAD model above and the STL files is below.

I printed the body in black PLA with 20% infill, 0.2mm resolution.

The enclosure or sleeve was printed in Solutech flexible filament with 100% infill, 0.3 mm resolution. I used this material because it has some flexibility which made it easy to stretch over the body. It also has a softer feel to it when rotating the clock around. Lastly, I chose a clear filament so that the LEDs for the nightlights would shine through.

Downloads

Assembly

7.jpg
11.jpg
8.jpg
9.jpg
10.jpg

I wired everything together using the schematic from Step 1. I used a small piece of perfboard to connect all of the common wires so that I didn't have to solder multiple wires to one pin on the Arduino. Hot glue was used to secure everything in its respective place except for the Arduino. It was just pushed into its designated slot. I made sure that the accelerometer board was perpendicular and level on the bottom of the body so that the coordinates in the code wouldn't need to be changed.

Upload and You're Done!

15.jpg
14.jpg
12.jpg
13.jpg

Now the final program can be uploaded to the clock to set the correct time. The cell battery should keep the time even when the power is unplugged. Slide the 3D printed sleeve over the body to hide all of the components and you have a complete cube clock!

I hope you enjoy making this project and find it as useful as I do. The nice part about this project is that it's very customizable. Feel free to add your own different functions like an alarm function, use different components like a larger OLED, FM radio receiver, etc. Happy making!