DIY Raspberry Pi IoT Alarm Clock

Why settle for a standard alarm clock when you can make one that's unique (and charmingly odd) using the Raspberry Pi Model A+? Here is a version has a built-in battery and descends majestically from the ceiling. Like any clock, it can tell the time, but it also reports the weather, news, and even current stock activity -- all by using speech. Then it ascends back up to the ceiling until the next morning.

Hanging Alarm
credit: myself
Raspberry Pi alarm clock concept illustration
credit: Apollo

Step

Before you start, get organized. Gather all the necessary tools and materials. There's a full list of everything you'll need for this project in this article.

Step

Load the STL file (a common 3D file format) into a slicing program such as Cura and export the gcode (it's a file type used in automated machines) to a memory card. Then insert the memory card into your 3D printer, or sync the file with your printer if it's connected directly to your PC.

Step

Settings vary among printers, however I had success using the following:

Step

  • print in PLA
  • layer height of .18
  • shell thickness .8
  • fill density 20%
  • print speed 45mm/s
  • printing temp 210 Celsius
  • honeycomb infill pattern,
  • bed temp of 70 Celsius.

Step

The motor mount should be printed at 100 percent infill or out of ABS plastic, while the spindle can be printed at about a 40 percent infill. You can see one of the larger pieces that I printed on a Lulzbot TAZ 3D printer below.

The enclosure speaker holder
credit: Me
The long print of the housing
credit: Me

Step

Download SD Formatter 4.0 and then perform either a quick format or a full format (it doesn't really matter which).

Step

Install RASPBIAN (which is the OS that we'll will be running on the PI) on the memory card. (If you need some help, be sure to follow this guide.) Come back when you're all done; I promise this guide will still be here.

Step

It's a really good idea to your project everything in stages in case it stops working somewhere along the way. By testing in stages, you can troubleshoot more easily. Connect a monitor and USB hub to the Pi. Plug in the WiFi adapter, as well as a keyboard and mouse to the hub. Next, expand the file system and make sure the Pi is working with the Internet nicely.

Step

You will need to solder the wires to the amp and the speaker, the 4-8 ohm speaker connection is connected to the speaker and the A+ and A- will be the ground and one channel for the 3.5 mm jack cable. You can cut off one end of a 3.5 mm audio cable and use the striped wire ends to solder to the inputs. A- will be the ground and A+ will be the audio channel. (It doesn't matter if it's the right or left.) The 5-volt input labeled VIN (voltage in) and GND (ground) needs to be connected to the output of the DC-to-DC converter. At this time, you should also wire up around 50 cm of wire to the input of the DC-to-DC converter and the battery pack you are using.

Audio amp with heak shrink
credit: myself

Step

Now it's time to get the latest code.

Step

The commands to enter into the Raspberry Pi terminal are in bold below.

Step

  1. sudo apt-get update
  2. sudo raspi-config
  3. It may already be installed, but just in case, run the git install "sudo apt-get install git"
  4. sudo apt-get install python-feedparser mpg123 festival
  5. sudo mkdir -p /mnt/ram
  6. echo "ramfs /mnt/ram ramfs nodev,nosuid,noexec,nodiratime,size=64M 0 0" | sudo tee -a /etc/fstab
  7. git clone https://github.com/skiwithpete/alarmpi
  8. You must also create an empty file called init.py in the same directory as the files above
  9. Open crontab in the text editor and add the following line. Use Esc or cltrl+x and make sure to save the file by pressing Y for yes
  10. crontab -e
  11. Finally to set your alarm for 733AM Mon-Fri (or any time you would like)
  12. 33 7 1-5 sudo python /home/pi/sound_the_alarm.pi
Testing the hardware and software
credit: Raspberry pi

Step

It's time to personalize the alarm! Open the settings and edit the name and the greetings. We also need to update the location for the weather at this time. The weather is based off of a Yahoo! weather location code. Go to Yahoo Weather and type in your city or zip code. There will be an eight digit number in the task bar that you copy into the settings.

Step

Ideally, this project would run on battery power alone, and that was my original intention. But to make it a bit more reliable, and keep from needing to replace the batteries every week or so, we need to supply 12 volts to the motor with a wall adapter. If the power goes out and you happen to use the WIFI connection on your phone, the alarm should still go off. It will just not lower the alarm, as it will not have sufficient motor power.

Battery pack below speaker
credit: myself

Step

It's time to get the stepper motor turning. Please follow the guide on Adafruit website to install the motor shield and connect the stepper. You will need to solder the headers to the Hat as well during this step. Make sure to hook up the 12 volts to the input of the motor shield so the motor has plenty of juice to run. Make sure the motor is running before moving on. You will need to add a few lines to the crontab -e file we edited earlier with links to the motor code. Two python files will need to be made for the motors: one forward and one backward.

Step

30 7 1-5 sudo python /home/StepperForward.py

Step

37 7 1-5 sudo python /home/StepperBackward.py

Step

The lines below may need to be modified; you will probably need to adjust the number of steps as well, depending how high the alarm needs to climb/lower.

Step

myStepper.step(500, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)

Step

myStepper.step(500, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE)

Stepper motor driver Hat
credit: myself

Step

Here is is a diagram of the connections for power that you will need to make. The batteries will need a diode to protect them from the 12 volt wall adapter power; this diode goes on the positive line from the battery pack, with the diode allowing current to flow out of the pack but keeping the 12 volts from damaging the batteries. There are six connections to be made on the DC-DC converter. Connect the wall adapter (positive and negative) and the battery packs (positive and negative) to the positive in and ground of the converter. Connect the output of the DC to DC converter to the SPST power switch and wire the ground to the PI and the speaker amp to supply them both with 5 volt power.

Power flow chart
credit: myself

Step

Heat a small piece of heat shrink around the speaker amp and have the wires feed through the opening. To screw down the speaker, I used screws normally found in assembling PCs. Solder a long piece of wire to the DC-DC converter and feed it out the same way as the audio cable and run it up to the PI. Heat shrink cover the DC-DC converter as well.

Speaker in speaker housing
credit: myself

Step

Epoxy the small magnets into the speaker housing and cover, and let it cure completely. If you attach them properly, the bottom cover will make a very satisfying click when all the magnets engaged. (The reason for the magnets is to help when we occasionally need to replace the back-up batteries.)

Cover with magnets
credit: myself
Magnets epoxied to housing
credit: myself

Step

Here you can see some pictures of the upper chassis support. The support is just a piece of scrap white acrylic plastic I had laying around. Create a semicircle that's the same size as the flat part of your bowl. I mounted it with 8-32 bolts and nuts though plastic spacers that were high enough to fit the Raspberry Pi under the support level. Next, attach the motor mount with 4 bolts to the chassis. Make sure the shaft of the motor is inline with the center of the bowl. To ensure this, I needed to cut the bolts with a Dremel, as they were a bit too long.

Drilling the upper chassis support
credit: myself
Side view of the upper chassis support
credit: myself
Upper frame
credit: myself

Step

The motor spindle was designed to fit snugly to the motor shaft. While the part I designed actually worked, I found that it was a bit too tight. You might need to file yours out a little, depending on the 3D printer you use and the tolerances of the various parts.

Motor spindle on shaft
credit: myself

Step

Measure out four approximately 100mm lengths of fishing line and attach them to the screws that hold the speaker to the housing. Then drill four evenly spaced holes in the plastic bowl's rim. Proceed to tie the fishing line from the speaker housing to the holes. Try and tie them where they hang the speaker in the middle but slightly below the rim.

Underside shot of speaker housing
credit: myself
Speaker housing with fishing line
credit: myself
Alarm hanging above bed
credit: myself

Step

Enjoy testing your new odd alarm clock and keep a lookout for more interesting projects that use the versatile Raspberry Pi. Below are some troubleshooting tips and suggestions for ways you might improve the prototype.

Some Troubleshooting

  1. "My motor is not turning." Make sure you have at least 9-12 volts going to the motor and that the coils are wired correctly.
  2. "There is no sound coming out of the speaker." Try testing with a different device like a computer or cell phone. Also, recheck the connections. If you supplied more than 5 volts to the board, you might need to try again with another board.
  3. "The alarm is not alarming." Try a different wireless Internet connection. This project requires a strong and stable connection. Download the code again and ensure you have entered all the commands correctly.
  4. "I can't seem to connect the Pi to the Internet." Try restarting the Pi. If that does not work, try unplugging and re-connecting the WiFi adapter while the Pi is on.

Things to Try or Improvements

I'm quite happy with the way the alarm worked out, however, it is very much still a rough prototype. It can be refined in many ways and I have made a list below of some things I may have done differently or that you could try as well.

  1. Add a way to shut off the PI or motor to make it a little "greener" on power usage.
  2. 3D print some of the parts like the motor mount and spindle with 100% infill.
  3. Put large googly eyes on it .
  4. Build a remote interface to play Internet radio though it.
  5. Use stronger fishing line, such as twenty pound test.
  6. Try swapping out the components for different ones or higher quality ones. For instance, a geared DC motor instead of a stepper.
  7. Wirelessly connect it to a outlet so it can also control a light.
  8. Add a vibration sensor so you can snooze the alarm in the morning for a set time.
  9. Cover the wires for a more aesthetic look.