Introduction: IoT Smart Alarm Clock [Open Source Project]

Welcome to the Smart Alarm Project!

***check out the latest adafruit 3D-Hangouts, where we just got featured!***

smart_alarm is an open-source project about building and programming a Internet of Things alarm clock. This instructable provides all information you need to build the smart alarm clock on your own. Even though we wanted to leave a lot of space for your ideas and improvements, the smart alarm clock is designed to have the following "starting features".

Features:

  • text to speech synthesizer
  • three ways of wake-up sound:
    • play local mp3 files
    • play internet radio station and
    • play latest news as podcast (independent to the alarm time)
  • set alarm via smartphone or any other computer
  • running apache2 server
  • automatic display brightness adjustment
  • audio amplifier volume control
  • 3D-printalbe case
  • case built-in tactile switch
  • alphanumeric display shows text
  • 3W speaker definitely wakes you up
  • ... whatever you want to add ...

Check the images above and this youtube link for more information.

Also checkout github repository for the code, as well as the github wiki and the provided installation guide.

If you are looking for the 3D printable case, you might want to check out

http://www.thingiverse.com/thing:2009740

Cloning the repository files to your Raspberry Pi Zero will enable you to check your soldering and finally run the main program easily. To complete this project you need basic knowledge in soldering and programming.

Consider this table of content as an overview of the steps you need to complete.

Table of Content

  1. Raspberry Pi Zero running Raspbian
  2. Display
  3. Clone Project Code

  4. Enable Audio

  5. Audio Amplifier

  6. Button

  7. Photocell

  8. Setup Apache Server

  9. Configure Setup

  10. WiFi Stick

  11. 3D-Printed Case

  12. Getting Started

Hardware Needed:

In order to complete the project you need the following (or similar) things:

  • Raspberry Pi Zero (with minor changes you might as well use a different Raspberry Pi)

  • Keyboard, Mouse and Screen (for initial setup)

  • Micro SD Card (8GB or more is recommended)

  • USB-WiFi-Stick (for example: EDIMAX EW-7811UN Wireless USB Adapter)

  • Audio Amplifier (PAM8403)

  • Hole Grid Board (70mm x 50mm x 1.2mm, 24x18 holes, plus one hole in each corner, can be found easily online)

  • Button (Tactile Switch)

  • Photocell (Photoresistor)

  • Speaker (3 Watt 4 Ohm 40mm diameter)

  • 14-Segment Alphanumeric Display

  • Screws: 4x M2 6mm, 4x M2.5 6mm, 4x M2.5 16mm

  • Resistors, Capacitors, Wires, ...


-> Let's start with Step 1

Step 1: Raspberry Pi Zero Running Raspbian

In order to complete this project you need to set up a Raspberry Pi running Raspbian (Lite), the Debian version of Raspberry Pi. Sure you might use different Raspberry Pis and a different OS, but therefore you might need to modify your system somewhat. For example if you want to use Raspberry Pi 3 you don't have to buy and use an additional WiFi-stick, might just use the on-board audio output, but might not be able to use the given 3D-printable case. So by changing some parts of this project you got to keep in mind that this instruction is based on using Raspberry Pi Zero.

1.1 Installing Raspbian

First visit the Raspberry Pi downloads page and download the latest Raspbian Lite image. We decided to work with the Lite version, since this project has no need for a graphical user interface. Now follow the instructions page of how to download and write the Raspbian image to your sd-card. Once your sd-card is set up, plug it into your Pi and connect mouse, keyboard and screen to the Pi.

1.2 Enabling SSH (Optional)

If you want to control your Pi via remote, navigate to the config menu of the Pi and enable ssh:

sudo raspi-config

select the Advanced Options menu and press enter. Now select the option SSH and press enable. After sudo rebooting your Pi the changes are applied. By typing:

ifconfig

the Raspberry Pi will tell you its ip-address. From your computer now, being in the same network, you are able to connect to the Pi via ssh like:

ssh pi@ip-address

enter the password and login to your Pi.

Step 2: Display

Picture of Display

This step contains the soldering and configuration of the "Alphanumeric Display". Again you might choose a different display. Doing so you have to apply small changes when it comes to coding as well as using the 3d-printable case. The display, we are using for this project, goes by the name "Adafruit 0.54" Quad Alphanumeric FeatherWing Display" and is provided by adafruit. This model comes together with the 14-Segment Alphanumeric LED FeatherWing containing the HT16K33 driver chip, which handles the multiplexing of the commands. Therefore we are able to control the display using the Raspberry Pi and I²C protocol. And of course adafruit also provide a ready-to-use library, which enables us of simply sending all kinds of strings to the display. But first lets care about the soldering.

2.1 Display Assembly

Follow this nice instructions given by adafruit for information about the assembly of the display and the FeatherWing. First you need to solder some pins to the FeatherWing.

(See Image 1)

Next you need to plug the display into the FeatherWing board and solder all the pins to the board. Again check the adafruit tutorial for details and orientation of the displays assembly.

(See Image 2)

In order to check the display you need to connect it to the Raspberry Pi. Therefore you might want to grab some wires, preferably multiple colors. But before connecting everything together, we recommend to first take the hole grid board and cut out a hole in the lower center. The hole grid board which we are using is 70mm times 50mm and fits perfectly into the provided case. Use the cordless mill to cut a hole into the board, like shown in the pictures above.

(See Image 3)

If you already have printed the case you might take the chance to see if it fits. Put the speaker on the provided cut-out and the hole grid board on top of it. Since those boards are not the highest quality, the position of the four holes at the edges of the board may vary a bit. Don't worry if two of the holes are not fitting exactly to the corresponding screw holes, everything will be squeezed together in the end, such that the use of two screws will be perfectly fine.

(See Image 4)

Once you are done preparing the hole grid board, soldering the display to the Pi is up next. Grab your colored wires and cut them to a length of about 10cm. Put the display centered into the top row of holes. Check the adafruit tutorials pinout page for details about the wiring. You need to connect four wires: 3.3V; GND and the two I²C pins: SDA and SCL. Consider the schematic diagram concerning the wiring of the display and the Raspberry Pi

(See Image 5)

Having the display and the raspberry pi successfully soldered and mounted on the hole grid board, your setup should look something like the last picture from above.

(See Image 6)

Now continue installing the corresponding Adafruit library.

2.2 Install Display Library

Once you are done assembling you need to install the Adafruit_LED_Backpack library. First prepare your system by typing:

sudo apt-get update
sudo apt-get install build-essential python-dev

also you'll need to install the python-smbus and python-imaging libraries:

sudo apt-get install python-smbus python-imaging

In your Raspberry Pis home folder type:

git clone https://github.com/adafruit/Adafruit_Python_LED_Backpack.git

in order to clone the Adafruit github repository to your Pi. Unzip the file, navigate inside the library's directory and execute the setup.py file:

sudo python setup.py install

2.3 Testing the Display

Once your installation is finished and your assembly is faultlessly you might go ahead and check if the display is working. First enable the I²C protocol by typing:

sudo raspi-config

navigate to the Advanced Options menu and enable the I²C protocol.

sudo reboot

your Pi to apply the changes. Now switch to the folder

cd /Adafruit_Python_LED_Backpack/examples/

and run the following test script:

python alphanum4_test.py

If you have done everything right, you should be able to see a text message running through the display. Having trouble lighting up all segments you might want to check all your soldering joints again.

Step 3: Clone Project Code

In order to test the hardware we are using in the following steps it might be handy to clone the project code of the smart_alarm github repository to your Raspberry Pi first. Make sure you are in the terminal of your Raspberry Pi, whether by using ssh or by simply connecting a screen and keyboard. Establish an internet connection and make sure you are in your home folder by typing cd. Run the following command to install git:

sudo apt-get install git

Next type:

git clone https://github.com/fgebhart/smart_alarm.git

to clone the repository files to your Pi. This might take some minutes. Once everything is downloaded to your Pi go to the folder /home/pi/smart_alarm/tests/ by typing:

cd /home/pi/smart_alarm/tests/

and run the following python script in order to display the time on your alphanumeric display:

python display_time.py

Also you might want to run

python scroll_text.py

and play around a little with the given python script. If you should encounter problems using the adafruit Python LED Backpack library try to recap the instructions in section 2. Display and follow the steps in the mentioned adafruit 14-Segment Alpha-numeric LED FeatherWing tutorial to check if you did not forget anything.

Step 4: Enable Audio

Picture of Enable Audio

4.1 Low-Pass-Filter Circuit

You might have noticed the Raspberry Pi Zeros lack of an audio output. Building an alarm clock without any chance of playing sounds might cause a bunch of oversleeps and angry bosses. But don't worry some skillful people already found a hack to cover the lacking audio output. All you need to do is following the adafruit tutorial of how to Add a Basic Audio Output to Raspberry Pi Zero. Stick to Option 2. Manually Assigning PWM pins for and detailed instruction of how to configure your Raspberry Pi Zero. Here is a short summary of what you need to do. First update your Pi to the latest version:

sudo apt-get update

Then install the GPIO library:

sudo apt-get install raspi-gpio

Clone the WiringPi repository to your Pi and install it like described in this tutorial by typing:

git clone git://git.drogon.net/wiringPi

Once it is successfully downloaded, change directory and build the files:

cd ~/wiringPi
./build

Run:

gpio -v

and

gpio readall

to check if your installation was successful. Like displayed in the readall output you see the function of all pins of your Raspberry Pi Zero:

(see Image 1)

Change directory to:

cd ~/smart_alarm/tests/

Now compile and install the file gpio_alt.c by typing:

gcc -o gpio_alt gpio_alt.c
sudo chown root:root gpio_alt
sudo chmod u+s gpio_alt
sudo mv gpio_alt /usr/local/bin/

Finally we are able to change the alternate functions of the Pis gpio pins. Like mentioned before we are looking to change the functions of pin 13 and 18 in order to enable PWM. Therefore you need to type:

gpio_alt -p 13 -f 0
gpio_alt -p 18 -f 5

Keep in mind, that once you are rebooting your Pi, these functions will be reset to their default function. But don't worry we will cover this concern later by providing a script which is being executed every time on bootup. If you now run the command gpio readall again, you will notice the new and desired functions of the pins 13 and 18.

Using the alternate function of pins 13 and 18 enables the usage of pulse-width-modulation. Together with a small low-pass-filter circuit we are able to generate a basic audio output. Consider the following schematic diagram for the wiring of the circuit.

(See Image 2)

You'll need some resistors and capacitors to build the mentioned low-pass-filter. Of course you might just start soldering the circuit to your hole grid board, but we recommend to first us a breadboard to make sure you connect everything right and test the filter. Note that there are two low-pass-filter, each for one audio output, namely right and left. There is only a need to have one audio output for this project, since there is just one speaker. On the next couple of pictures you will recognize two low-pass-filters, though. This is just because we had some earlier plans of adding two speakers. So don't worry about it and choose what you need for your project. If you are going to build the alarm clock with just one speaker, one filter (=one audio output) is enough. The resistors you need for the low-pass-filter are 150 Ohm and 270 Ohm. The capacitors need to have 10nF and 1µF. Try to find some space on your hole grid board where the resistors and capacitors don't contact the speaker, like shown in the next picture:

(See Image 3)

Solder the wires following the fritzing connection diagram above. Once you are done, your circuit should look something like the next picture. The green wires at the bottom are the one coming from Raspberry Pi Zero pins 13 and 18, the black wires at the top of the image are ground and coming from Pi as well. The green wires at the edge of the board are the audio output coming from the low-pass-filter and will be connected to the speaker and later on to the amplifier in order to increase the volume.

(See Image 4)

Again note, that there is no need for both low-pass-filter, controlling just one speaker requires only one filter.

4.2 Testing Sound

Once your circuit is soldered and your alternate pin function is configured via device tree overlay, like described in this tutorial you are ready to test your Raspberry Pi Zeros capability of playing sound. Therefore it might be handy to install the omxplayer, by typing: (note: if you did install the Raspbian OS rather than the Lite version, omxplayer is already installed by default)

sudo apt-get install omxplayer

now change folder and run omxplayer to play the example audio file:

cd ~/smart_alarm/tests/
omxplayer example.mp3

4.3 Install pygame

You also need to install the pygame python library in order to play audio files via your python script. Doing so you need to:

sudo apt-get install python-pygame

Once this is done you should be able to run the following command:

python smart_alarm/tests/play_sound.py The play_sound.py script reads the file in /home/pi/smart_alarm/smart_alarm/music/Festival.mp3 and uses pygame library to play the .mp3 file.

4.4 Install Python Text to Speech

As well as .mp3 files we want to get the alarm clock speaking. Therefore we need to install the python text to speech package (pyttsx). But first we have to install pip:

sudo apt-get install python-pip

Now install pyttsx and the necessary python-espeak library:

sudo pip install pyttsx
sudo apt-get install python-espeak

Again test your system by running:

python smart_alarm/tests/say_text.py

This script prompts you to enter a text and reads it by using pyttsx and espeak.

4.5 Install Music Player Client & Daemon

Because we don't just want to play mp3 files which we have locally on the Pis sd-card, we need to install the Music Player Client & Daemon. Using the music player client (mpc) we are able to listen to tons of different internet radio stations. Since this alarm clock is a Internet of Things alarm clock, we for sure want to enable listening to internet radio stations. So go ahead and install

sudo apt-get install mpd mpc

Now you can use your own client to play the internet radio station you like. Check the most important commands:

  • mpc add radio_station_name : Adds your station to the mpc playlist
  • mpc playlist : Displays the content of the mpc playlist
  • mpc clear : Clears the current playlist
  • mpc play : plays your playlist, with one radio station at random
  • mpc stop : stops the play of some station

In the end we are using those commands via our python scripts together with the python library os like this:

os.system('mpc play')

But before we are able to run your playlist of radio stations, we first need to add at least one station. Of course there are millions of stations out there and you will find the one you like, but I know you don't want to start searching the web, so I suggest using one of the following two:

Depending on your system or where you live you might have to listen to commercials each time you start those stations. So back to our system. Enter the following command to your Raspberry Pi Zeros command line to add the mentioned internet radio station:

mpc add  http://orange-01.live.sil.at:8000

Now start and stop your playlist in order to check if the music player client is working.

Step 5: Audio Amplifier

Picture of Audio Amplifier

This section cares about increasing the volume of the system. Again we don't want to cause oversleeping. So adding an amplifier will solve this problem and give your project enough power to even use it like a small jukebox. We choose to use the Stereo Audio Amplifier PAM8403 Chip (see datasheet) since it is cheap and easy to use.

5.1 Connecting the Amplifier

Consider the following fritzing schematic for wiring information:

(See Image 1)

As you can see we are using another Raspberry Pi pin for controlling the amplifier. The yellow wire coming from gpio 12 is connected to the amplifiers switch input pin. Therefore we need to add another line of code to all future python scripts (don't worry we've already done this!) which enables the amplifier by just sending a logical one for turn on and a zero for turn off vice versa. This appears to be handy since you might have noticed the noise produced by the Raspberry Pis pulse width modulation. Once you have connected everything your setup should look similar to the following one:

(See Image 2)

5.2 Testing the Amplifier

Again run one of the following command in order to test the volume of your system:

omxplayer ~/smart_alarm/test/example.mp3
python ~/smart_alarm/test/play_sound.py
python ~/smart_alarm/test/say_text.py

As the sound should be much louder now, you might also want to increase the Raspberry Pis system volume, type:

amixer set PCM -- 100%

which sets the system volume to 100%. If you are having trouble playing sounds, you might want to check if your gpio pins alternate functions are still activated. Once you reboot your system the default function will be activated and you will no longer be able to play sounds via pulse-width-modulation on your Pi Zero. Go back to section 4. Enable Audio. Most likely you just need to reenter the following commands:

gpio_alt -p 13 -f 0
gpio_alt -p 18 -f 5

which we will include in our autostart script later on. Looks like we are done playing sounds. What to do with playing sounds? Stop them!

Step 6: Button

Picture of Button

How to stop sounds? - Sure by pushing buttons! Once you woke up you need to stop the alarm. Therefore we need to add a button to our project.

6.1 Connecting the Button

All of you who have been working with buttons already might know about bouncing and debouncing. If you do not know about it, you might want to read this excellent tutorial by Raspi.TV. If you don't want to read too much, skip the tutorials, grab your button and start wiring. Consider the following fritzing for the wiring:

(See Image 1)

You might choose some space at the bottom of your hole grid board to solder the connections to. Make sure not to get too close to the speaker. You need two resistors: 1x 1k Ohm and 1x 10k Ohm, one capacitor with 100nF and some wires. Connect everything like shown in the image above. The 1k Ohm resistor is connected between the two red wires, the 10k Ohm resistor is connected between the yellow and black wires. Your soldering on the hole grid board should like the following picture. On the front:

(See Image 2)

And on the back:

(See Image 3)

If you got your case already printed you might want to check if the button fits into the provided slot like this:

(See Image 4)

6.2 Testing the Button

Like in the previous steps we are going to use a python testing script provided in our project repository. If your button is connected like described above and you already did clone our project repository run the provided python script:

python smart_alarm/tests/button_input.py

you should see the line button is: 0 printed to your terminal many times. Once you press your button the line changes to button is: 1. If this works, your soldering is correct! If not, check the fritzing diagram from above and recap the mentioned tutorial.

Step 7: Photocell

Picture of Photocell

Consider the following fritzing schematic for connecting the photocell to your setup. Note that this graphic is the complete and final wiring of the overall smart alarm project.

(See Image 1)

Since both photocell and button do not consume much power at all, connecting both to the same power supply pin and ground pin of the Raspberry Pi Zero is possible. You can do this by connecting the photocell wires to the soldering joint at the button on the lower edge of the hole grid board. Your connections should look similar to this one:

(See Image 2)

Make sure to use wires with a length of about 15cm in order to install the photocell in the top of the case. If the photocell does not fit into the provided hole you might use a sharp knife to slightly enlarge the holes. Take a pen (or some other thin tool) and press the photocell into the flat laying case. The wires can be arranged through the provided slit in the wall between top and body of the case. In the end your installation and wiring should look similar to the following picture:

(See Image 3)

7.2 Testing the Photocell

Once you are satisfied with the connection of your photocell you might want to check it. Therefore navigate to the /tests folder and run the following python script, by typing:

cd ~/smart_alarm/tests/
python reading_brightness.py

If you have done everything flawlessly this script should print you your surrounding brightness. Cover the sensor with your fingers and check the data output in your command line.

Step 8: Setup Apache Server

Picture of Setup Apache Server

One of our goals was to keep the design of the clock as simple as possible. As a result we had to find a way to configure the clock without the use of more than one button. Therefore we are using an apache webserver on the raspberry pi to set the alarm time, the type of content which is played and many more options.

8.1 Installation of Apache Server

To install the apache server on the raspberry pi zero please follow the steps in this tutorial. The plain installation command is:

sudo apt-get install apache2 -y

Due the fact that we are using python scripts on the server, it is necessary to install the wsgi module for apache:

sudo apt-get install libapache2-mod-wsgi

Usually the module gets automatically enabled if installed, if not please run the following line:

sudo a2enmod wsgi

Further Information about the wsgi module can be found here.

8.2 Configuration of the Apache server

The next step will be the configuration of the apache server. Since apache doesn’t have access to the environment variables of the system, we have to declare them separately. Therefore you can add the follwing lines at the end of the file /etc/apache2/envars:

# Set smart alarm path variables
export smart_alarm_path=/home/pi/smart_alarm/smart_alarm

An example how the file should look like can be found in the git repository under smart_alarm/misc/apache.

After that we can use the variable in the apache config files. The goal is, that our python_server.py script is getting executed, when the server is called in a web browser. The easiest way to achieve this is to replace /etc/apache2/sites-available/000-default.conf with our 000-default.conf under smart_alarm/misc/apache:

sudo cp smart_alarm/misc/apache/000-defaul.conf /etc/apache2/sites-available

Basically it links the root directory of the server "/" to the python script and it grants the apache server the reading permissions for this folder. The last thing we have to do is giving the apache server the right to change the data.xml file. Usually the apache server has its own user “www-data”. There are many different ways to give “www-data” writing permission for the file. The easiest way, but maybe not the securest one, would be to allow everybody to change the file. This can be done in the folder /smart_alarm/smart_alarm/with following lines:

sudo chmod o+w data.xml

8.2 Testing of the Apache server

After that you should see the following webpage if you call the ip address or hostname of the raspberry pi in a web browser.
On a PC:

(See Image 1)

On a mobile phone:

(See Image 2)

Step 9: Configure Setup

In this section we will explain you the final configurations you have to perform in order to get the system working. This includes system configurations, linking the autostart.sh script to the boot process, changing the Pis hostname in order to provide an easy user access and change your Pis user password for more safety.

9. 1 Autostart Script & Environment Variable

We need the path to the folder containing the python scripts in some places. Therefore we have to define the environment variable “smart_alarm_path”. The standard way is defining the variable in /etc/environment. To do this just add the following line at the end of the file:

smart_alarm_path=”/path/to/smart_alarm/smart_alarm”

The default path would be “/home/pi/smart_alarm/smart_alarm” Besides the apache web server, which should always be running, the smart_alarm script also should be active after booting. To achieve this, the autostart.sh script should be executed automatically after booting. This can be done by adding following two lines at the end of the file /etc/rc.local:

. /etc/environment
. $smart_home_path/autostart.sh

9.2 Change Hostname (Optional)

We want to establish a connection to our Raspberry Pi Zero as easy as possible. Therefore we need to change the Pis hostname. Doing so we are able to simply type the Pis hostname in our smartphones (or any other computers) browser. In order to change your Pis hostname we recommend following this tutorial. First you need to edit the following file by typing:

sudo nano /etc/hosts

Here you need to edit the last line which starts with 127.0.1.1. Remove the current hostname raspberrypi and add whatever name you want to give to your system. Now edit the file /etc/hostname by typing:

sudo nano /etc/hostname

Again replace raspberrypi with the name you want to name your Pi. In order to apply the changes type:

sudo /etc/init.d/hostname.sh

Since all scripts placed in /init.d/ are being started after each boot up, your hostname will be the name you chose from now on.

9.3 Change Password (Optional)

Changing your user password is easy. Even though this is optional, we recommend doing it. Just type:

sudo raspi-condig

Navigate to the option Change User Password and follow the instructions.

Step 10: WiFi Stick

Picture of WiFi Stick

In order to fit the Raspberry Pi Zero in the 3D-printable case and save a lot of space, we have to take apart the USB-WiFi-Stick and solder it to the Pis underneath test pads. But first make sure to configure your WiFi connection before soldering it to the board. Therefore you might use a USB hub to provide multiple USB connections.

10.1 Configure WiFi

Plug in your WiFi stick and establish a connection to your local network. Once this is done type

ifconfig

on your Pis command line to figure out your ip-address. It turns out ssh is no more activated by default since December 2016. To activate ssh type

sudo raspi-config

navigate to the Advanced Options menu and enable the ssh connection.

sudo reboot

your Pi in order to apply the changes. Now try to connect to your Raspberry Pi using your computer and ssh, like this:

ssh pi@ip-address

Replace 'ip-address' in this command by the Pis ip-address or its hostname. Once this connection is established reboot your Pi in order to see if it connects to the configured network automatically. Now shutdown your Pi, unplug all devices and prepare your solder iron.

CAUTION: After soldering a device to the Raspberry Pi Zeros test pads, you will not be able to plugin other USB devices via the micro USB connection anymore. This includes devices like mouse and keyboard, therefore it is important to be capable of using the ssh connection for all further steps in this instruction. If you prefer playing around with multiple USB devices first, you might just postpone this step to the end of this instruction.


10.2 Take Apart WiFi Stick

Like shown on intro of this instructable, this project uses the "EDIMAX EW-7811UN Wireless USB Adapter". Of course it should be possible to use just any kind of WiFi USB Stick in this project, but keep in mind that we just tested the one described.
Now take apart the WiFi-stick by slightly lifting the plastic case at the flat side of the usb plug. You should be able to remove everything, such that you have the bare wifi board laying in front of you, like shown in the picture:

(See Image 1)

10.3 Soldering to Pis Test Pads

After taking apart the WiFi-stick you'll need to cut four wires to a length of about 4cm. Solder the USB connections to the Raspberry Pi Zero test pads like shown in the picture:

(See Image 2)

UPDATE: also see Images 4 + 5 and consider this tutorial for more information of how to solder a wifi dongle to the pi zeros test pads.

Again, keep in mind, that it will not be possible to connect additional USB devices to the Pis micro USB connection after using the USB test pads. Once the soldering is done, plug in the Pis power supply and check if the connection is working. The WiFi-stick should start blinking a few seconds after plugging in the power supply. Wait until booting is done and establish a WiFi ssh connection. All further steps will be based on using a ssh connection like this. In order to check your internet connection and update your Pi to the latest Raspbian version, type:

sudo apt-get update<br>sudo apt-get upgrade

10.4 Configuring Multiple WiFi Connections (Optional)

If you plan to use your device in multiple networks you'll need to configure them first. By just using one WiFi connection you might just skip this step. Adding additional network connections you need to modify the file /etc/wpa_supplicant/wpa_supplicant.conf. Therefore type:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add additional network connections like this:

(See Iamge 3)

for more information check this tutorial.

Step 11: 3D-Printed Case

Picture of 3D-Printed Case

Once you are done building and configuring your setup you are ready to install it to the 3D printed case. The design of the case has been evaluated many times, such that you do not need to print support material at all and in the end all hardware parts fit into the body of the case perfectly.

11.1 Download and Print the 3D-Model

See the following link to the 3D model at thingiverse:

http://www.thingiverse.com/thing:2009740

I hope you like the design. We really would appreciate all kinds of improvement ideas, just comment or contact via thingiverse. For 3D-printing the model consider these Cura slicing options.

11.2 Assembling the Case

For the installation of the hardware parts in the case and the assembly of the case you need the following screws:

  • 4 x M2 screws length: 6mm (hole grid board)
  • 4 x M2.5 screws length: 6mm (Raspberry Pi Zero)
  • 4 x M2.5 screws length: 16mm (case itself)

After printing the case you might need to remove overlapping material in order to achieve a better fitting. First put the speaker on the provided circular hole. Then try to fit the hole grid board together with the display into the provided slot. You might need to move the display slightly to all sides until it will 'click' into the case. Now put the hole grid board on top of everything. Make sure to not bend any wires too much when tightening the screws for the hole grid board. Slightly insert the button and the photocell. Afterwards lay down the back part next to the front part and find the right position for the Raspberry Pi Zero. Use the M2.5 screws and mount the Pi Zero to the back of the case. Before closing the case make sure the WiFi board and amplifier are positioned on the side, so you are able to close the case. In the end use the long (16mm) M2.5 screws to tighten the back to the front. Finally you are done building the smart_alarm project and may start applying the program code to your needs.

Step 12: Getting Started

Congratulations! You're done building your own smart_alarm IoT alam clock.

Plug in your power supply and watch your alarm clock booting up. The autostart.sh script should be started automatically on each boot. Therefore the apache2 server and the smart_alarm.py (with the current version number in it) script should be started as well. Now you are able to set your alarm via your mobile phone, laptop or any other computer connected to your home wifi. Open your browser and type:

http://ip-address-of-your-pi

Once you completed step 9.2 Change Hostname you are as well able to simply type:

your-pis-hostname

in your browser. If your browser now starts your search-engine to search the web for your pis hostname you need to put http:// front of the hostname. If your apache server is set up and configured to point to the python_server.py script you should be able to see the graphical user interface of the smart alarm project. Start playing around a little to get familiar with all the options and possibilities.

Note: On smartphones you are able to create shortcuts pointing to the desired webpage for your home screen. It appears like a separate APP and might be handy for an easier configuration of your smart alarm.

Make sure to add some of your favorite wake-up-music to your Raspberry Pi at /home/pi/smart_alarm/music/ as well as adding your favorite radio station to the music player clients playlist, like described in step 4.5 Install Music Player Client & Daemon.

Finally you got everything set up! Feel free to adapt the coding and the hardware to your needs. We already had tons of ideas which features we also could add to the project. In order to leave space for your improvements we decided not to add too many features. But if you are looking for some inspiration check the following list of possible future features:

  • Speech Recognition
  • Wake with light (add ultra bright LED)
  • Add battery for mobile usage
  • Usage as Jukebox (add stereo, increase max volume)
  • ...

We hope you like our project and have fun building and coding it! We appreciate any kind of support. Let us know it you want to participate in this project and contribute to our repository.

Comments

fgebhart (author)2017-04-05

Here is the full list of resistors and capacitors, like shown in the fritzing schematic:

6x Resistors: 2x270Ω, 2x150Ω, 1x1kΩ, 1x10kΩ
4x Capacitors: 2x10nF, 1x1μF, 1x100nF

Additionally this project uses one Photocell, which I ordered here and should be similar to this one.

(Note, that you do not actually need both sound channels left and right, since there is just one speaker, like mentioned in the instruction. Therefore you could leave out one of 150Ω and 270Ω resistors and one 10nF and 1μF capacitor)

warhawk8080 (author)2017-03-10

Would you be able to use Lighttpd instead of Apache2, its footprint is much smaller than Apache.

https://redmine.lighttpd.net/projects/lighttpd/wiki/HowToPythonWSGI

mjf2708 made it! (author)2017-02-27

Just made one! Brilliant project, very well described, excellent step-by-step instructions, with test routines along the way. Now starting to explore the various features (some of which I've found in the code - e.g., shutdown).

fgebhart (author)mjf27082017-03-01

Awesome! Thanks for sharing! Let us know if you have any suggestions for improvement! We are currently planning to add some rgb leds for a colorful wake-up effect! ;)

mjf2708 (author)2017-02-16

In step 10.3 you don't show the pads to solder to - image 2 shows the topside of the Zero, not the underside.

fgebhart (author)mjf27082017-02-16

yea you're right, I'm sorry. I added two additional photos showing the used test pads + a link to another tutorial, which explains this step in detail.

mjf2708 (author)fgebhart2017-02-16

Thanks for adding this so quickly! and for the general excellent level of detail! (I'm about to build one)

Stephen LEE (author)2017-01-17

I need this at my home!!

jdonato (author)2017-01-02

What would you say is a ballpark guess as to total cost (understanding some is 3d printed and would not be costed in)?

fgebhart (author)jdonato2017-01-03

A rough guess about the total costs might look like this (assuming 1€ = 1$):

Raspberry Pi Zero 5.-
USB-WiFi-Stick 5.-
Audio Amplifier 2.-
Speaker 2.-
Alphanumeric Display 10.-
8GB SD Card 5.-
--> SUM = 29.-
plus low cost parts like: button, photocell, screws, resistors, capacitors and the hole grid board; which you should get all for less than 1.-

So let's say more or less 30 depending on where you buy your stuff!

Swansong (author)2017-01-02

Thanks for sharing :)

About This Instructable

5,735views

65favorites

License:

More by fgebhart:IoT Smart Alarm Clock [Open Source Project]
Add instructable to: