Skip to main content
  1. Projects/

AlarmPi

The AlarmPi is a Raspberry Pi powered smart alarm clock, which I designed and created after getting thoroughly fed up of how inflexible and un-user-friendly most alarm clocks on the market are (you can read a bit more about the AlarmPi’s inception in this blog post). The heart of the device is a Raspberry Pi with the Raspbian OS, running a Python script which controls the hardware, and takes various inputs to control when it should play an alarm (an internet radio feed). I’ve put together this short video explaining some of the key features

Hardware #

As mentioned, the AlarmPi runs off a Raspberry Pi, which is connected up to the following:

The wiring is currently all done on a temporary prototyping breadboard, when I’ve finished playing with the wiring I may get round to soldering it all properly! The case is made from 5mm thick clear perspex, which I ordered cut to measure from PlasticSheets.com. I then drilled/cut holes in the side and top panels for the buttons/rotary encoder and speakers, and mounted the LCD and 7-segment displays using A2/M2 nuts and bolts. It’s held off the ground by 4 rubber feet, one in each corner, to ensure that screws don’t scratch whatever surface it is on. The case itself doesn’t give a great look, as I made it without access to the proper tools, and it was only supposed to be a temporary measure!

Features #

  • Google Calendar integration Alarms are set based on integration with my work Google Calendar, which contains my entire work schedule. Since I work shifts, it knows to wake me up with enough time to get ready and travel in the morning (see travel time below), and to let me lie in when I’m working in the afternoon/evening, all without me having to input the information manually. Any updates to my calendar are automatically taken into consideration up until the point of the alarm being set, at which point it is fixed and can only be manually edited.
  • Travel time calculation Using the Google Maps Distance Matrix API, travel time to my work locations are calculated and taken into consideration when planning alarms. When an alarm is automatically set based on an event on my Google Calendar, the location of that event is read, and a base travel time calculated from my home location. One hour before the alarm is due to go off, this is then re-calculated and adjusted accordingly - so in the event of traffic being better or worse than normal, you get the optimum time in bed!
  • Weather Using the OpenWeatherMap API, the AlarmPi fetches the latest weather information and displays this on the front LCD panel. This is also read out when the alarm is cancelled.
  • Text-to-speech I’ve integrated the Google TTS engine mentioned in one of my blog posts so that the AlarmPi will read information as necessary (such as the weather, as above), rather than struggling to focus on the display when you’ve first woken up!
  • Internet radio The FM signal in my bedroom is terrible, so the AlarmPi plays internet radio stations instead. A set of stations can be programmed in, and the alarm can set off any one in particular. In the event of the station being unplayable (such as the internet connection being down), the alarm will revert to a sound file based on the Pi, so the wakeup call isn’t missed!
  • Automatic backlight A lot of alarm clocks have a configurable backlight, which can be set for different brightness values. However, what may work at night is next to invisible in the light of day! The AlarmPi has a luminosity sensor on the top panel, which automatically reconfigures the backlight of the LCD and 7-segment display depending on the ambient lighting, so it’s nice and bright during the day, but dimmed at night.
  • Web interface In the past, I’ve gone away for a week and forgotten to disable my alarm clock, which means my neighbours get the joy of an alarm going off for a couple of hours every morning before timing out. The AlarmPi has a web interface that allows the changing of the most common settings (including “holiday mode” which disables all alarms) remotely.
  • Home lighting integration I use OpenHAB to control some MiLight bulbs around my house. While not strictly part of the AlarmPi, I’ve attached a NFC tag to the top of the box which tells my phone to send a signal to OpenHAB to switch off all lights when I go to bed. When the alarm goes off, another signal is sent from the AlarmPi to OpenHAB to say that I’m awake, and the lights will be switched back on if it’s still dark (very much needed at 4am, rather than groping in the dark for a light switch!).

Source Code #

The AlarmPi is obviously a bespoke piece of hardware, and a lot of the code I’ve written is irrelevant unless you’re copying me piece-for-piece - but I’ve released the code here: https://github.com/mattdy/alarmpi so you can have a look and a good laugh at my Python programming skills! There is a slightly outdated script called installer.sh included in the project, which will give you a clue to the majority of dependencies, however there may be some I’ve missed out! The entire program is designed to run as a Supervisor job to ensure it is always running, even after a crash or power outage.

Wiring #

I’ve included a diagram of how all these components are wired together (roughly), so you can get an idea of how it works! Please forgive the lack of proper components in some places, I’ve tried to label everything as clearly as possible, but there are quite a lot of elements to fit into a small space!

AlarmPi Wiring

Future ideas #

While AlarmPi does everything I need right now, there are a few things I’d like to add in future.

  • Wake-up Lighting A lot of alarms now come with ‘wake-up lighting’, which simulates a sunrise over a period before the alarm goes off, supposedly helping the body wake up naturally, rather than suddenly with the alarm.
  • API While the web interface does an adequate job of changing settings and alarms, I intend to make an API at some point to allow other systems to integrate with AlarmPi

Please get in touch if you have any comments or questions about the build!