DIY Raspberry Pi IoT Alarm Clock
This project the highlights the Raspberry Pi in embedded projects. This was a very fun and rewarding project to build a odd, but unique 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.
This project is a prototype. You should be comfortable working with tools and DC electronics before attempting this. Please wear safety glasses when soldering.
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.
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.
Settings vary among printers, however I had success using the following:
- 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.
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.
When using a desktop 3D printer, applying an even layer of quality glue stick will help the parts adhere to the bed. You can also try using blue painters tape if you do not have a heated bed.
Download SD Formatter 4.0 and then perform either a quick format or a full format (it doesn't really matter which).
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.
The RASPBIAN image is about a gigabyte in size. You might consider starting the download and then watching a movie or eating lunch. I cleaned the kitchen.
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.
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.
Now it's time to get the latest code.
The commands to enter into the Raspberry Pi terminal are in bold below.
- sudo apt-get update
- sudo raspi-config
- It may already be installed, but just in case, run the git install "sudo apt-get install git"
- sudo apt-get install python-feedparser mpg123 festival
- sudo mkdir -p /mnt/ram
- echo "ramfs /mnt/ram ramfs nodev,nosuid,noexec,nodiratime,size=64M 0 0" | sudo tee -a /etc/fstab
- git clone https://github.com/skiwithpete/alarmpi
- You must also create an empty file called init.py in the same directory as the files above
- 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
- crontab -e
- Finally to set your alarm for 733AM Mon-Fri (or any time you would like)
- 33 7 1-5 sudo python /home/pi/sound_the_alarm.pi
A solid and stable Internet connection is key to the alarm's success. I had difficulty tracking down one particular problem until I changed to my phone's hot spot for testing.
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.
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.
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.
30 7 1-5 sudo python /home/StepperForward.py
37 7 1-5 sudo python /home/StepperBackward.py
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.
myStepper.step(500, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)
myStepper.step(500, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE)
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.
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.
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.)
For the best results, pre-drill holes in your 3D printed parts. Pre-drilling ensures that the piece does not crack when installing screws.
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.
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.
If your spindle fits very tightly, you might need to slightly heat the shaft on the motor with a lighter to allow the spindle to fit into place. Remember, though: it needs to be snug. If it's too loose, it may slip off the motor and the alarm will fall.
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.
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.
- "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.
- "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.
- "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.
- "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.
- Add a way to shut off the PI or motor to make it a little "greener" on power usage.
- 3D print some of the parts like the motor mount and spindle with 100% infill.
- Put large googly eyes on it .
- Build a remote interface to play Internet radio though it.
- Use stronger fishing line, such as twenty pound test.
- Try swapping out the components for different ones or higher quality ones. For instance, a geared DC motor instead of a stepper.
- Wirelessly connect it to a outlet so it can also control a light.
- Add a vibration sensor so you can snooze the alarm in the morning for a set time.
- Cover the wires for a more aesthetic look.