Introduction: Marble Desk Clock
"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"
The goal of this project was to make a novelty desk clock that would react to user input. An RTC module is used to keep track of the date and time, which is then displayed on an LCD. When the user touches a capacitive touch sensor on the front of the clock, the trench mounted on the top tilts back and forth three times. A row of six LEDs mounted in the lid light up to follow the movement of the trench.
NOTE: Before beginning this project, make sure you have a basic understanding of Arduino programming and assembling a circuit on a breadboard.
- 3D Printing
- 2 Props
- Arduino Uno (with USB connector)
- Capacitive Touch Sensor
- 6 LEDs
- 6 220 Ohm Resistors
- 2 2.2k Ohm Resistors
- DS1307 RTC
- HD44780 LCD (with I2C breakout board)
--> The LCD provided in my course kit came with an I2C breakout board, so that is the one I used for this project.
- Female-to-Female Jumper Wires
- Male-to-Male Jumper Wires
Step 1: 3D Modeling
The program used for the 3D modeling was Autodesk Inventor. The part files for the box and lid were provided by our Professor. The *.step files can be downloaded here. Import the STEP files into Inventor, then save the parts as Inventor Part Files (*.ipt). Once the files are imported, you can add the necessary cutouts and stands. The trench, props, and servo arm were created from scratch.
The trench part was designed to be 19 cm long and 3 cm wide. The edges of the trench were rounded using the Fillet tool. Two 1 mm radius holes were extruded into the sides of the trench to allow for the props. Another 1 mm radius hole was extruded slightly down and to the left to allow for the arm connecting to the servo.
The props were designed to be 6 cm tall and 8 mm thick. It starts at 6 cm wide and slopes down to circle of radius 1 cm. A 1 mm radius cylindrical peg was extruded from the center of the circular part of the top of the prop to attach to the trench. A 20 mm by 4 mm rectangular peg was extruded from the bottom of the peg to attach it to the lid. Also, the sides of the peg were cut down in thickness to allow for room for the servo arm.
A small 7 cm by 1 cm arm was modeled to connect the trench to the servo. This arm was not 3D printed in the final project, but was created purely for modeling purposes.
The box needs a cutout for the LCD and the USB port. Cutouts can be created by drawing the desired shape and then selecting the "cut" option when using the Extrude tool. The shapes of the LCD and USB were projected from pre-made models of the LCD screen and the Arduino (found here). Insert the part models into an Assembly with the box file. Then use the Project Geometry tool to project the outline of the LCD and USB port onto the box. These outlines can then be used to extrude cutouts.
The box also needs stands to hold up the Arduino and servo. Again, this can be done using the Project Geometry tool and the part files for the Arduino and Servo. Three cylindrical stands were extruded underneath the holes in the Arduino board, and a rectangular step was extruded for the servo to sit on.
The lid simply needs cut outs for the props and the arm connecting the trench to the servo. The size of these cutouts was determined using the Project Geometry tool. The outlines were then extruded using the "cut" option.
Step 2: 3D Printing
In order to turn these 3D models into physical plastic structures, you must first have access to a 3D Printer.
Save all of your part files as *.stl files using Inventor. Make sure to clarify what units are being used. (Most 3D printers expect units in Millimeters). These files are now ready to be sent to the 3D printer.
Step 3: Control System
The block diagram shown above describes the control system of the project.
The Arduino uses a Real Time Clock (RTC) module to update the date and time. This information is then displayed on the LCD screen. The Arduino also uses input from a touch sensor to trigger the servo movement as well as the LED display.
The system can be separated into two subsystems: the clock system and the marble subsystem.
- Clock Subsystem
The RTC Module communicates with the Arduino via the I2C bus. When the program is compiled, the RTC fetches the date and time information from the compiler and continues to keep time from that point. The battery backup ensures that the time data is not reset if the system loses power. The time and date information is then displayed on the LCD screen for the user to see.
- Marble Subsystem
The marble subsystem is designed to produce a physical reaction to user input. The sensor registers input using capacitive touch, and sends a signal to the arduino. When the arduino receives this input, it activates the routine for servo movement and LED activation. The servo is programmed to move back and forth three times across a range of 42 degrees. Every 14 degrees, the next LED is activated and the last one is turned off. Once the routine is completed, the LEDs turn off and the system waits for the next user input.
Step 4: Circuit Assembly: Clock System
The Clock System is made up of a DS1307 RTC module and an LCD screen with an I2C breakout board.
Both of these components communicate with the arduino via the I2C bus, each with a unique address. In order to connect them, they need only be wired to the I2C pins on the arduino (SDA and SCL) and the power rails (5V and GND). The I2C lines are shown by the green and orange wires. The I2C pins can be found by digital pin 13 on the arduino.
Step 5: Circuit Assembly: Marble System
The Marble System is comprised of three main components: the touch sensor, the servo, and the six LEDs.
The touch sensor requires connection to the power rails (5V and GND) and an input pin on the arduino to receive the signal from the sensor. For this project, I used digital pin 2.
The servo requires the same connection to the power rails (5V and GND) and an output pin on the arduino to control the position of the servo. For this project, I used digital pin 6.
Finally, each of the 6 LEDs require connection to ground and an output pin on the arduino. The short pin of each LED is connected to the GND rail, and the long pin is connected to the arduino. For this project, I used digital pins 3-5 and 7-9. In order to limit the current flowing through the LEDs when they are on, a 220 Ohm resistor is connected between the LED and the arduino.
Step 6: Arduino Sketch
The pictures above contain the code used to run the project.
The arduino sketch can be divided into four sections:
- Global Variable Definition (lines 1-133)
This section creates a defines all variables needed in the program.
First, the necessary libraries are included to give the program access to functions that have already been written. The DS1307 and Time libraries are used for the RTC. The Servo library is used to operate the servo. Lastly, the LiquidCrystal_I2C and Wire libraries are used to update the I2C LCD screen.
Next, objects are initialized to give these libraries the information they need to work. An LCD object is created in line 9 to define the I2C address and the size of the screen. A Servo object is created in line 12 to define a specific servo that can then be manipulated.
Lines 15-26 contain the pin assignments that define which pin on the arduino is used for. Pin 2 is used for the touch sensor, pins 3-5 and 7-9 are used for the LEDs, and pin 6 is used for the servo.
The remainder of the section (lines 28-133) contain variables for setting the RTC and converting time integers into characters that can then be printed on the LCD.
- Setup (lines 137-194)
This section runs only once when the program is first started.
First, the Input/Output pins are initialized and set as input or output (lines 141-148). The LED pins need to be output pins, while the touch pad and servo need to be input pins.
Next, the LCD screen is initialized and the backlight is turned on (lines 158-159).
In lines 166-192, the time and date information is fetched from the compiler to set the RTC module.
- Loop (lines 196-220)
This section of the sketch runs repeatedly as long as the system has power, and contains the main body of the program.
First, lines 199-212 reads the current time and date information from the RTC and displays it on the LCD.
Next, lines 216-219 trigger the routine for the servo movement and LED display. Line 216 checks the state of the touch sensor. The sensor produces a low input when it senses touch, and produces a high input at all other times. If pin 2 receives a low input, it calls the function "marbleRoll".
- Function Definition (lines 225-389)
This final section defines exactly what happens inside each function used.
Lines 226-360 contain the code for the MarbleRoll function, which moves the servo and updates the LEDs. Line 227 attaches the servo to pin 6, then line 228 repeats the routine 3 times.The servo movement code is split up into 12 sections. Each of these sections move the servo across a range of 7 degrees and turn on a different LED. The first six sections move the servo from one side to the other, and the next sections move it back to where it started. Each range of 7 degrees turns on a different LED, creating the effect of the LEDs following the servo motion. After the routine is executed 3 times, line 352 detaches the servo. Lastly, lines 354-359 turn off all the LEDs.
Lines 362-389 contain the code for the functions used to set the time on the RTC. GetTime saves the Time data, while GetDate saves the date information.
This concludes the code for the arduino sketch for this project.
Step 7: Final Assembly
The final step is to put all the pieces together. The trench and legs fit together as shown and are mounted in the lid. The LEDs are also mounted in holes drilled into the lid along the trench so that they line up with the movement of the trench.
The LCD screen fits into the designed hole in the 3D printed box. Finally, the touch sensor fits into the round hole drilled to the left of the LCD screen.
The clear arm fits through the lid to connect the servo to the trench.
The arduino, breadboard, and RTC are placed inside the box to protect the circuitry.
Once all the components have been placed, a USB cord fits through a hole designed into the side of the box to power the arduino.