Saturday, November 29, 2014

Big Ben Clock - Raspberry Pi


We mounted a large clock on the wall of our vaulted ceiling and wanted to give it a little more pizzazz. I wanted to give it a Big Ben feel, so I added some speakers, a Raspberry Pi, a little code, and voilĂ ! We now have a mini Big Ben of our own.

With a Wifi connector I am also able to remotely push other audio sounds to the speakers. Think speaker front end for a makeshift security system, or other audio states of your home automation. The possibilities are endless.


Demonstration




Code

The following is the code I wrote for the cronjob schedule and bash script to determine which audio file to play.

cronjob schedule:
# hourly from 7am to 10pm
0 7-22 * * *  /opt/big_ben/big_ben.sh > /dev/null

big_ben.sh:
#!/bin/bash

# Author: Kenneth Burgener  2014
# Purpose: Determine hour and play appropriate Big Ben MP3

# crontab: (from 7am and 10pm)
# 0 7-22 * * *  /opt/big_ben/big_ben.sh > /dev/null

# Get hour (1-12) for mp3 file
HOUR=`date +%l`
HOUR=$(( $HOUR ))

# Get military hour (1-24) for math below
MILHOUR=`date +%k`
MILHOUR=$(( $MILHOUR ))

# Set audio volume depending on time of day
if [ $MILHOUR -le 8 -o $MILHOUR -ge 20 ] ; then
    # 8am and earlier, 8pm and later
    #/usr/bin/amixer set PCM 80% > /dev/null
    /usr/bin/amixer set PCM 90% > /dev/null
else
    # 9am to 7pm
    #/usr/bin/amixer set PCM 95% > /dev/null
    /usr/bin/amixer set PCM 91% > /dev/null
fi

/usr/bin/mpg123 /opt/big_ben/audio/big_ben_$HOUR.mp3 2> /dev/null


Big Ben Audio

I found a good quality mp3 file that had the full 12 chimes. I then used Audacity to chop the file into smaller versions for the appropriate hour chimes.
  • big_ben.zip
    • big_ben_1.mp3
    • big_ben_2.mp3
    • big_ben_3.mp3
    • big_ben_4.mp3
    • big_ben_5.mp3
    • big_ben_6.mp3
    • big_ben_7.mp3
    • big_ben_8.mp3
    • big_ben_9.mp3
    • big_ben_10.mp3
    • big_ben_11.mp3
    • big_ben_12.mp3
  • big_ben_12.mp3




2 comments:

Anonymous said...

Works great! Got this working on my LinuxMint 17.3 desktop, now for putting it into my long case clock with a Raspberry Pi. Thanks.

best thesis writing services said...

I love your idea of this clock. If I get some free time, I'm going to be trying this out for sure, although I would need some time to learn how to code.