Introduction: Clockwork

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com).

Step 1: Concept

As I try to brainstorm for an idea for this project, I decided to make something that is usable and be useful for my daily life. Not many things like that can have a two degree of freedom requirement so I decided to make a simple clock to meet the requirement as well as have it display on my desk to show the time. Originally the idea was to make a wristwatch, but the 3D printed part would be too small and the motors that drive the watch would still be too big for a wristwatch.

Hence this project, I found spare parts around my apartment and decided to work on this.

Step 2: Parts

- 3D Printed parts

- 2 28BYJ-48 5V DC Stepper Motor

- 2 ULN2003 Stepper Motor Driver Board

- Arduino Uno

- HC-05 Bluetooth Module

All of these parts are made by me except the clock's hands. I am not very creative. Below is the link to its creator.

https://www.thingiverse.com/thing:1441809

Step 3: Assembly of Parts

(1)- You need to put Gear_1 and 2 to the stepper motors. They will be a tight fit so a little bit of force is needed for them to stay in place.

(2)- Base_0 will stay at the bottom of the assembly.

(3)- Base_1 will be placed on top of SpurGear_1, this is the main component for the minute hand. You can glue these two components together, make sure the base is on top of the gear.

(4)- Base_2 will be placed on top of SpurGears_2, this is the main component for the hour hand. The same apply to this part as step (3)

(5)- The hands of the clocks can be glue on top of Base_1 and Base_2, or you can drill a small hole to have them fit in place.

(6)- To have the gear of the minute hand match up with the spur gear, you need a 1cm platform to put the whole assembly on top with one of the stepper motors.

The reason for this is because the main base cannot be any high since the other stepper motor would not be able to reach the high gear. Either way, a platform is needed for one of the stepper motors.

Step 4: Library for Arduino IDE

The code for this project is based on a library by tyhenry called CheapStepper.h

https://github.com/tyhenry/CheapStepper

To install this library for your arduino. Click clone or download on the link above and download it as a zip file.

In the Arduino IDE. Sketch -> Include Library -> Add .ZIP Library

Out of all the library that works, this one utilized the stepper motor the best and extremely easy to use.

Step 5: Breadboard Setup

I used an Arduino shield to go with my Arduino UNO. It look more clean but you can get a small breadboard and placed it on top of the Arduino UNO instead. Follow the color on the schematic as some wires are on top of each other. Pins 4-7 are for one stepper and pins 8-11 are for the second stepper.

The Bluetooth module must be wired RX -> TX and TX -> RX to the Arduino board.

Blue wires are connections from the Drivers to the Arduino UNO

Green wires are the RX and TX connections

Black wires are ground.

Red wires are 5V.

Step 6: Code

Below is the code for this project.

The explanation of the code will be on here.

----------------------------------------

CheapStepper stepper(8,9,10,11); CheapStepper stepper_2(4,5,6,7);

boolean moveClockwise = true;

//37.5 min = 4096;

//1 min = 106.7;

//5 min = 533.3;

//15 min = 1603;

//30 min = 3206;

//60 min = 6412;

int full = 4096;

int half = full/2; //2048

float full_time = 6412; // 1 hours

float half_time = full_time/2; // 30 min 3026

float fif_time = half_time/2; // 15 min 1603

float one_time = full_time/60; // 1 min 106

float five_time = one_time*5; // 5 min 534.3

float one_sec = one_time/60; // 1 sec 1.78

//we can do 30 min each by rotate the motor 3206 and reset

This is the main calculation for this project. The stepper would take 4096 steps to rotate a full 360 degree, but because the spur gears are bigger than the gears attached to the stepper so it takes more steps for a full rotation. As the spur gear is the main component that spin the hands. I have to do various testing to make sure the values are correct.

full_time is the variable that I assigned for a full rotation of the hand. This is quite consistent but as the steps get divided by 2 to get specific movement, the float value gets smaller, which made it harder for the driver to do its job.

The moveClockwise = true; is to make the stepper motor move clockwise, but because it is spinning the spur gear counterclockwise, we need to make the boolean false in the setup. You can also declare it false at the start but this is to explain how it works.

---------------------------------

void setup() {
Serial.begin(9600);

Serial.println("Ready to start moving!");

pos = one_time; del = 900; ratio = 60;

moveClockwise = false; }

Here is where I declare the moveClockwise boolean false. pos will be the number of steps, del will be the delay, and the ratio is either for minute/sec = 60 or hour/min = 12

We control the hands with the Bluetooth module. First, you need a serial Bluetooth terminal from your Android device. Connect to the Hc-05 with the PIN 0000 or 1234. You can use some example code from Arduino IDE to see if it is working correctly. When it is connected it should blink very slowly instead of rapidly when it is not connected.

---------------------------------

void loop() {
state = 0;

if(Serial.available() > 0) {

state = Serial.read(); }

for (float s=0; s<(pos); s++){

stepper.step(moveClockwise); }

for (float s=0; s<(pos/ratio); s++){

stepper_2.step(moveClockwise); }

delay(del);

Serial.available() > 0 is important as it is how your Bluetooth module going to work. This if statement will be true when there are communications between the Arduino and your device. The state variable will determine the 3 others variables I declared top of setup(), it will also print what operation the code is running. The two for loop is the main function that drives how the step motor will move.

---------------------------

if (state == '1') {

pos = one_time; del = 0; ratio = 12;

Serial.println("Operation 1: No Delay"); }

This is one example of using the input from your Bluetooth device to change how the system works. You can edit these variables however you like to control the hands.

Step 7: Demo and Conclusion

This is a demo of the system, showing how it work. For the enclosure you can use anything that would fit all of the components inside. This project was simple and fun to make as it is the first time I 3D printed. The Bluetooth module was fun to figure out and use. There are a few mistakes I made that was too late to change but the final product is fine.