These two weeks, I worked with my group of four to design a cuckoo clock. I designed the electronic system of the clock and the bird motion.
These two weeks, I worked with my group of four to design a cuckoo clock. I designed the electronic system of the clock and the bird motion.
As a group, our main plan was to build a lion clock, where a lion head opens its jaw every hour to reveal a chicken and then closes. However, the group members responsible of design did not have enough time to print their lion head design by the time they finished it. So we had to come up with a last minute solution, and I suggested going back to the idea that inspired the lion clock which was a cuckoo clock. As we'd already had the chicken printed, we only needed the house, which does not take a long time to deign as it is quite geometric with very simple details compared to a lion head, and it can be laser-cut in pieces and assmbled, which is way faster than 3d printing it. It did not make a difference for the electronics part, though, as the mechanism and program were the same. Group documentation can be found here.
Each RGB LED consists of 3 LEDs enclosed in one bulb, so it has four different pins: one for ground and one for each LED. This results in 12*4=48 different pins, 36 of which need to go to the Arduino. But the Arduino has only 13 digital I/O pins, making it impossible to connect the LEDs directly to the Arduino. The solution to this problem was to use shift registers.
Q0-Q7 | Parallel Data Outputs |
GND | Ground |
Q7S | Serial Data Output |
MR | Master Reset Input |
SHCP | Shift Register CLock Input |
STCP | Storage Register CLock Input |
OE | Output Enable Pin |
DS | Serial Data Input |
Vcc | Supply Voltage |
Image and Information Source: Manufacturer's Datasheet
A shift register is a type of digital cicuit using a cascade of flip-flops where the output of one flip-flop is connected to the next. They share a single clock signal allowing the data stored in the system to shift from one location to the next and leave the system once it passes though all locations. There are different types of shift registers used for different purposes. In this case, I needed to increase the number of outputs, so I used Serial-In-Parallel-Out(SIPO) type shift register called 74HC595. As its type suggests, this shift register receives input in series and outputs it in parallel, inreasing the number of outputs. The shift register has 16 pins defined in the table.
I used KiCad to draw the circuit diagram as the large number of connections can make things confusing without a diagram. First, I need 36 outputs for the 12 RGB LEDs I have, so I used 5 shift registers as each shift register has 8 output pins, resulting in last 4 pins unused. The fist step was to connect the first shift register to the Arduino pins as follows:
I then used a breadboard to connect all the 5 shift registers together. So I:
To connect the LEDs to the output pins, I needed more breadboard space, so I used a second breadboard. I used 36 220 Ohm resistors, one for each LED pin as the LEDs I used cannot stand the current provided directly from the Arduino. And finally, I connected all ground pins to the GND pin on the Arduino using hook-up wires.
The servo needs to rotate 90 degrees every hour to move the chicken out and then go back to its original position. We used Servo Motor SG90 1PC, whic was light and small enough to fit into our clock yet strong enough to move the bird. First, I connected the GND and Vcc pins on the servo to GND and 5V on the Arduino, respectively, to establish power connection. Next, I connected the position pin on the servo to the I/O pin 6 on the Arduino to control the angular position of the servo.
The first part of the program was to include the servo library and create a servo object to control the servo, define the rgister's pin numbers in variables, and define the numbers of pins, shift registers, and RGB LEDs. I also created a boolean array to store the states of the output pins. I needed 3 more arrays to store the numbers of pins that correspond to each color and two more variable to store the pins that correspond to minutes and hours LEDs.
Before the setup and loop functions, I needed the following two functions:
In the setup function, I used the attach() function to attach the servo to pin 6 and set all pins that go to the shift registers to outputs using the pinMode() function. Then, I set all the OE pins to HIGH to make sure all shift registers are receiving voltage and wrote a for loop to fill the registers array with LOW states. Finally, using the ledOff(0) function, I turned all LEDs off to make sure things start from scratch.
In the loop function, I used three for loops as follows:
The if statements in the loop make sure the hours and minutes LEDs move back to the first LED once they go over all LEDs.
Here is a video of the RGB clock. Notice that the red LED is supposed to represent 5 seconds, but in order to demonstrate the function faster in the video, I changed the delay time to 1 millisecond.
To change the clock to one blue LED, I had to use only 2 shift registers as I needed only 12 outputs. The circuit and connections were exactly the same but with much less wiring and components. For the code, I only needed to change the loop function as I needed only one for loop now that updates the LED every hour. This significantly simplified my previous code.
THe video on the left shows the clock working. I was trying to change the code so that the blinking LED represents minutes and the always-on LED represents hours. However, I did not get this working yet. In this video the minutes LED works, but the hours LED does not. Again, to make the video faster. I changed a minute to 100 milliseconds.