Introduction: Raspberry Pi Rooster Clock

Picture of Raspberry Pi Rooster Clock

I already had a Raspberry Pi running OSMC media player and server. This is a Pi B version. After my initial robotic experiments , it was resting behind our TV serving the OSMC media. I thought of using it for a Rooster clock - an automated Rooster clock . The rooster should flap the wings , shiver the tail , stretch the neck and Cock-a-doodle-doo! ( I wished it does a dance performance too.. ;-) .Greedy eh ?)

The design was as shown in the first picture. The wooden clock with a rooster on top. But I did not have the patience to get the clock , wooden enclosure etc. I decided to make everything from card board. This was made completely from repurposed/recycled materials.

Let me clarify that my intention is NOT to make a clock ( clock with dial) . I want to make an automated rooster which fits on top of an existing clock and moves and makes sound on every hour.

Step 1: How Does It Work?

Picture of How Does It Work?

The Raspberry pi has no real time clock (RTC). How does it know the right time ? Pi is already configured as an NTP client using the Debian NTP servers. As long as you have an Internet connection you should get the correct time. You should set the correct time zone in /etc/timezone

A lot of resources are available in the internet for setting correct time on Raspberry pi.

https://www.raspberrypi.org/forums/viewtopic.php?f...

The Rooster automation is powered by a small DC motor , which is controlled by a Raspberry pi. Every hour ,the pi will run our roosterClock python script and switch one GPIO pin to high. This pin is connected to the base of an NPN transistor . This transistor acts like a switch . A base current triggers the motor and automates the Rooster.

At the same time , the pi plays a cock-a-doodle-doo .. sound - an MP3/wav file. Also it will play clock bell sound . It rings the bell once at 1 O'clock , twice at 2 O'clock and so on. The python script should take care that the Rooster or the clock is not annoying you or your family at night time. ( I learned this in the hard way.... :-( )

Step 2: Make Your Rooster

Picture of Make Your Rooster

Get some card board - a pizza box top . Draw 3 parts of a rooster as shown . Make two copies of the central part ( no. 2) . We are going to sandwich head and tail section between two identical central part. You can use rivets or threads to fix the tail and head to the body. But make sure that both tail and head should be movable after riveting.

I used a crude method, which I call plastic riveting , for connecting the body parts. Get a small plastic tube - a plastic pen refill or coffee stirrer will do . Cut it to size to fit as a rivet axis. Make holes on the card board cut parts and connect them using the plastic tube. Melt the both ends of the tube and flatten them so that the riveting is secure.

Now let us rig the head and tail . Use a smooth thread ( I used a fishing line) to connect both tail and head and leave another thread down . This threads will be between the two centre body parts , and should be long enough.

If you pull this string the Rooster head and tail should move like a puppet.

Now we will make the wings. Cut two wing shapes from the same card board. We fix them on both sides of the central body using cello tapes. Connect these wings using a rubber band, so that the wings will be in flying position - away from the body. Thread both the wings through holes on either side of the central body part and get the string down along with the head and tail string. ( See the pics )

We have now 3 string lying down. One from head and tail and two from two wings. Pull down these strings together the Rooster should flap the wings and move head and the tail.

I fixed the body of the Rooster on a flat foam board piece ( white in the picture), using two screws.

Step 3: The Base Box and Motor

Picture of The Base Box and Motor

Now the rooster is fixed on a pole - a flat white pice of foam board ( or ply wood). I used a card board box as a base and to conceal other mechanism.

Tie down all the control thread into one ( I used a soda pop top for rigging this). We are using a pencil as the main axis to connect the motor to the rooster automata. Let us make a shaft lever using a piece of wood. Connect the shaft lever to the thread using a washer and a screw. ( See the pics)

Here comes a real problem. The motor rotates very fast and it does not have enough power to move the Rooster automata. We need to do gear reduction to get more power and lower RPM. In short , we are going to use a lot of rotations of the motor to make a single but more powerful rotation of the main shaft.

The tape recorder motor already had a belt wheel attached to its axis. I got another bigger wheel from the same broken tape recorder and attached it to the pencil. We can use the same belt which was there in the tape recorder.

Tricky part is to fix the motor and the pencil axis at the right places so that the motor is connected to the axis by the belt and the belt has enough tension. It may take some trial and errors to get it right.

Attach the motor to the box using tapes. Make holes in the box for the pencil and place the pencil , belt wheels and belt in right places.

Test the setup, by connecting the motor to a battery. When the motor runs at high speed , the pencil will rotate at a slower speed. Make sure that the pencil rotation is powerful enough to move the Rooster automata.

If the system is not powerful enough , you can try a bigger belt wheel for the pencil, resulting more leverage.

You may use wax to lubricate the cardboard holes and the pencil.

Step 4: Make It Work - the Python Script and the Cron Job on Linux.

Picture of Make It Work - the Python Script and  the Cron Job on Linux.

Connect the motor terminals through the PN2222 transistor as shown in the first diagram .

The GPIO 7 ( or whichever GPIO you chose) is connected to the base of the transistor.

When the GPIO is high the transistor base goes high and the transistor lets the current pass from

collector to emitter. In short it acts like a switch, a digital switch.

Below given is the python script I used:

======================kozhi.py==========================

import RPi.GPIO as GPIO ## Import GPIO library
import time

from subprocess import call

motorControlGpio=7

GPIO.setmode(GPIO.BOARD) ## Use board pin numbering

GPIO.setup(motorControlGpio, GPIO.OUT) ## Setup GPIO Pin 7 to OUT

def runMotor(dutyCycle,durationInSec):

levelZeroWaitS=(100-dutyCycle)*.0001

levelHighWaitS=dutyCycle*.0001

t_end = time.time() + durationInSec

while time.time() < t_end :

GPIO.output(motorControlGpio,True)

time.sleep(levelHighWaitS)

if levelZeroWaitS > 0:

GPIO.output(motorControlGpio,False)

time.sleep(levelZeroWaitS)

GPIO.output(motorControlGpio,False)

runMotor(100,0.5) ## Let the rooster flap and move for .5 seconds at full power

runMotor(80,.5)## Now another 5 seconds , a bit slower

call(["mpg321", "/home/pi/ajplay/RoosterSoundBible.mp3"]) ## play the RoosterSoundBible.mp3 file using the program mgp321

runMotor(100,1)## After the Cock-a-doodle-doo, animate the rooster once again.

GPIO.cleanup()

exit()

===============================================

This script will animate the rooster and play the Cock-a-doodle-doo...

Create a cron job , so that the rooster script will trigger every hour.

A cron job is a task which periodically runs in a Linux system .

First of all "cron" should be running on your Raspberry pi. If it is not running use:

/sbin/service crond start

You can edit the crontab file and schdule the script to run every 1 hour.

crontab -e will open this file for editing.

I have created a shell script for ringing a clock bell sound. Once at ! O'clock and twice at 2 O'clock and so on.

Also a single bell every half an hour.

Please ask permission from your family / room mate

Here is the script :

==========ringbell.sh============

echo $(date)
numOfBells=1

if [ $1 = "1" ]; then

numOfBells=1

else

timeHrs=$(date +%I)

numOfBells=$timeHrs

fi

echo $numOfBells

mpg321 -l $numOfBells /home/pi/ajplay/Clock_Strikes_One.mp3

sudo python /home/pi/ajplay/kozhi.py

=================

At the end of the script it calls our first python script kozhi.py

My crontab entries looks like this:

30 * * * * /home/pi/ajplay/ringbell.sh 1 >/home/pi/ajplay/ringbell.log

0 * * * * /home/pi/ajplay/ringbell.sh 2> /home/pi/ajplay/ringbell.log

The first line rings a single bell every half an hour.

There is a very nice article here:

https://www.raspberrypi.org/documentation/linux/us...

Where did I get the audio files Clock_Strikes_One.mp3 and RoosterSoundBible.mp3 from?

There are many websites which you can search for downloading audio files. Please make sure that you are not using any copy righted media.

http://soundbible.com/tags-cock-a-doodle-do.html

Step 5: Fine Tuning and Decoration.

Picture of Fine Tuning and Decoration.

You can decorate the rooster with real feathers , or just beautiful paints.

Or as my kids did, a collage of magazine pages. They cut long pieces like feathers

and pasted on the rooster.

It came out very realistic. ;-)

I placed a round clock between the Rooster and the card board box ( base. ) . It appeared something like as shown my first picture.

I realized that it is annoying to hear the bells every half an hour. Also the bells are going to be a problem at night while you are sleeping. You need to fine tune the script to customize the bells and the cocka doodle doo according to your needs.

I hope you will enjoy this project.

Comments

yezsocrafty (author)2015-10-14

Very cool idea. Great job!

tomatoskins (author)2015-10-13

Really cool! I'd love to see more pictures of your finished clock!

Ajann (author)tomatoskins2015-10-13

I will make a video of it and post :-) . Thanks for the comment.

About This Instructable

949views

4favorites

License:

More by Ajann:TruckFoodies - A Food truck  project using Intel EdisonRaspberry Pi Rooster Clock
Add instructable to: