Code Monkey home page Code Monkey logo

pi_alarm's Introduction

Raspberry Pi Alarm Clock

This project takes a Raspberry Pi and, web-enabling it, turns it into an alarm clock. The Pi is attached to a PowerSwitch Tail and controls a light in place of an audio-based alarm to wake us up.

The alarm is configured through a web interface, and has been optimized for both desktop and mobile. Instructions for building it below!

Web Mobile

I made this for my wife for Christmas 2013, and it was super simple! After a month in the field, this alarm clock has received highest marks from the wife, who says it is a pleasant way of waking up.

Note that this project requires some "hardware hacking," but it's simple enough that any beginner should be able to follow along with this tutorial to make a light-up alarm clock.

Materials you will need:

  • Raspberry Pi (Model B) -- $35
    • Micro USB power supply (2.1 Amps) -- $10
    • 8GB SD Card (4GB will work, but you will need to delete extra distros from NOOBS when installing Raspbian, so save yourself the time and just spend the extra $1 on an 8GB SD card) -- $6
  • USB Wireless Adapter (I bought this one from my local Microcenter) -- $10
  • Powerswitch Tail (to control the light) -- $25
  • Tailed LED (I bought this one from my local microcenter). -- $3
  • Cheap clamp-on lamp and light bulb: ~$10

Total Cost: ~$99 USD

Note that some things, like MicroUSB power supplies, lamps, wireless adapters, and light bulbs (etc.) you might already have laying around. No need to purchase everything outlined above -- "hacking" it together is half the fun!

Step 1: Install Raspbian

There are already plenty of guides online for installing Raspbian on your Raspberry Pi. Covering this falls out of the scope of this guide, but I will at least link the NOOBS package I used.

Step 2: Get the Wifi interface up on your Raspberry Pi

I used this guide, substituting vi for nano because I'm a VIM guy.

Step 3: Install Prerequisites

Install git and screen so we can check out the code and run it in the background.

sudo apt-get update
sudo apt-get install git screen

Next, install virtualenv for python by following the Initial Setup section of this guide.

Step 4: Install Alarm Software

First, become root. Then, navigate to the directory in which the code will live, and create a virtual environment:

sudo su -
cd /opt
virtuanenv pi_alarm_env
cd pi_alarm_env

Next, check out the project from git, and install the python libraries:

git clone https://github.com/ajpierce/pi_alarm.git
./pi_alarm/script/setup.sh

Step 5: Hook up the LED

For testing purposes, we want to hook up the LED to make sure that the signal processing works before attempting to attach the Pi to the PowerSwitch Tail.

I plugged the LED into Pin 10 on the Raspberry Pi, like so: Pin 10 and LED

Step 6: Fire up the software!

As root,

cd /opt/pi_alarm_env/pi_alarm
./run.py

If all goes well, you the Flask webserver should let you know that the application is running on 0.0.0.0:80.

Navigate to the IP address of your Raspberry Pi from a browser on another computer (or your mobile phone). If all goes well, you should see a web site full of mushy happy things for my wife.

Press the "ON" button near the bottom of the page. Does the LED light up? If so, you're in business!

Step 7: Hook up the Pi to the PowerSwitch Tail

After confirming that the LED lights up, I simply cut off the LED and screwed the two wires into the PowerSwitch Tail, like so: RPi to PST Afterwards, I attached the Pi to the PST with a zip tie, and the hardware hacking was complete!

Step 8: Configure the server to run on boot

To ensure the alarm starts on boot, follow the guide here, but your script will be the simple one outlined below:

#!/bin/bash
screen -S alarm python /opt/pi_alarm_env/pi_alarm/run.py

This starts a new screen (with the name "alarm" and invokes python to start the alarm clock server.

Step 9: Enjoy!

Plug your light into the PowerSwitch Tail, and the PST and Alarm into a couple of outlets. You're done!

Changing the Appearance

Mushy love notes to a woman you don't know not your design aesthetic? No problem!

app/templates/index.html is where you can shorten the text to something practical.

app/static/css/alarm.less is the LESS file that compiles to app/static/css/alarm.css, in which you may adjust the color scheme to something less purple.

Finally, if you like the random messages that appear in the header, you can make your own by editing config.py. If you'd prefer not to have them, remove the tag from app/templates/footer.html.

pi_alarm's People

Contributors

ajpierce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pi_alarm's Issues

IOError: Please specify user or filename to write.

Hey,
The program works well until I try to set an alarm.
It said that I need specify user of filename to write, how do I fix this issue?
a BIG thanks!

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/pi_alarm_env/pi_alarm/app/controller.py", line 51, in set_alarm
    scheduler.schedule_alarm(weekday, hour, minute)
  File "/opt/pi_alarm_env/pi_alarm/app/scheduler.py", line 79, in schedule_alarm
    self.cron.write()
  File "/usr/local/lib/python2.7/dist-packages/crontab.py", line 311, in write
    raise IOError("Please specify user or filename to
``` write.")
IOError: Please specify user or filename to write.

Turn Light Off If GPIO Input equals High

I'm trying to figure out how to add a physical switch, and the simplest way I can figure based on my current setup is --->>> if GPIO 12 = High (switch is on) run the same function as /off to switch

This isn't an issue with your code at all, just trying to blend Raspberry Pi w/ an Arduino, Neopixels, Mosfet driven White pixel strip, and an on off switch... and this last little snippet of code is where I'm stuck before I can actually start using this thing.

Any chance you could help me out?

IO Error upon setting alarm

Unable to do anything. File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/opt/pi_alarm/app/controller.py", line 51, in set_alarm scheduler.schedule_alarm(weekday, hour, minute) File "/opt/pi_alarm/app/scheduler.py", line 79, in schedule_alarm self.cron.write() File "/usr/local/lib/python2.7/dist-packages/crontab.py", line 310, in write raise IOError("Please specify user or filename to write.") IOError: Please specify user or filename to write.

Typo in howto

Howdy,

Thanks for sharing your code!!!!!

While installing i found a small typo in step 4.

virtuanenv pi_alarm_env should of course be virtualenv pi_alarm_env

People how know how to code and are experienced will pick this up instantly. But newby's might be confused.

Adding Mplayer

Hey,
That's not an issue but I wanted to modify the code for my use.
I want to add a stream radio via mplayer, when the light is on it plays the stream, and when it off it pause it.
You have the time or the kindnass for helping me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.