Imagine yourself in a world where you can brew your coffee, open the curtains, turn on the bathroom light, and play your favorite music every morning without having to move your finger.
Well, you’re in luck because this scenario is no longer a dream. It could be your next DIY project! In this tutorial, we’ll build a simple smart IoT alarm clock using Particle Photon. We’ll start with simple functionality like setting your alarm from your own smartphone and we’ll add more functions in following articles.
Particle is a small microcontroller that enables you to connect your device to the internet and exchange data through web and mobile apps easily. Particle is one of my favorite microcontrollers (along with Arduino) in the market right now for the following reasons (credit: Particle):
Beginning last year, users can start using Microsoft Azure in conjunction with Particle. You can now send data directly from Particle to Azure and display results.
I strongly recommend you read through Particle Setup Guide here before you move on. It’s essential to review the guide to better understand how the device works and to connects to the internet.
The device has several modes that can be identified by the color of the embedded RGB LED. For example, the device blinks in green when it tries to connect to the internet. It will blink in white if the WiFi module is off. So just by looking at the LED you can tell which mode the Particle is in.
There are several ways to program your Photon, whether through the cloud (Tinker app) or through an IDE either online or offline.
To simplify the process, I have chosen offline IDE (Particle Dev). Particle is very much like Arduino’s IDE. You can easily create a folder and add all the files needed for your code, such as libraries used inside that folder.
I’m going to break the project into several steps. Please follow the steps at your own pace. I’ll start by connecting Photon to an app called Blynk, then I’m going to do a simple test by blinking Photon’s embedded LED (on digital pin 7) from Blynk.
Next, I will get the screen to work properly with Particle. I will explain the wiring of the LCD with Particle Photon and will provide you with the sketch that should be flashed along with the libraries required for this step. This LCD will be used later to display date and time .
Last sketch will let you test if the buzzer is working properly. This buzzer will be used as the alarm buzz, so we have to make sure it’s loud enough to be heard .
1. Building a simple app with Blynk
I will start with a simple functionality from Blynk to control the embedded LED on the Particle Photon board. Photon has an embedded LED on pin D7 unlike Arduino UNO, which has an LED embedded on D13.
Follow the steps below to build your first app to control Particle Photon:
Create your project
Choose your main microcontroller
Get the auth token for linking the app with the hardware project
Add widgets and function to your workspace
*If you’re unfamiliar with Blynk and you’re not sure how to use the app, please refer back to my previous A Smart Mailbox article(under section Blynk Mobile App).
First, let’s start by creating a new project.
Enter your project title and choose Particle Photon as your hardware model. You should press “Email” to get the right auth token that will be used later in the final code flashed to Particle. It will be sent to your email directly after pressing the button.
Now you have a basic platform for your app. You’ll need to add buttons and widgets for your app to serve your own functionality.
Press on the “+” icon on the top right to choose between the available buttons and widgets provided by the Blynk.
For the sake of simplicity, I’m going to choose a simple button to test the blinking functionality from the app.
Tap on the button after you dragged it to your workspace. It will open up a window where you can choose your button settings from pin numbers and button names to button state (switch/push).
I have chosen D7 as the input for the photon and set its function as a push button.
Now the button is set and you can see that the button reads D7.
You have to flash this codeto your Particle before running your app.
How do you flash the code? It’s simple! Download the code and open in Particle IDE.
Verify button in the upper left compiles the code before flashing it to the device. (If there is any) you’ll be able to see any errors in the code.
Flash button actually flashes the code to the device.
2.Connecting LCD Screen
Figure 2: 2×16 LCD screen
It consists of 16 columns and 2 rows, which is more than enough.
Follow the sample sketch and wiring diagram to get it working.
Figure 3: Wire diagram of LCD & Photon
After connecting and wiring your LCD screen as described above, upload this sketch to your Particle Photon.
You will be able to see “Hello Sparky” with a timer that starts to count from the moment you turn the LCD on.
If you’re getting different results, please go back and check the wiring again.
We need a buzzer so it buzzes when the alarm goes off. This small buzzer will do all the work with only 2 pins: One is grounded and the other is an input pin for your Photon. I chose digital pin 6 for the input signal .
Figure 6: Wire diagram of LCD, Photon and Buzzer
This sketch is responsible for getting the alarm tone out of the buzzer.
4.Set the alarm from Blynk app
We’re going to go back to Blynk and add 3 additional buttons. The steps are exactly the same as we did earlier. The buttons corresponds to analog pins A0, 1, 2 and 3.
Alarm is a switch button: It switches the LCD to the alarm mode where you can see your alarm time when it’s switched on .
Reset is a push button: You reset the preset alarm to the default value ”0:0” .
Hours and Minutes are two push buttons: They’re used to control the digits of the alarm time.
It’s important to set your alarm button’s functionality as a switch as shown below in the mode section.
Unlike the Alarm button, all the other buttons will be set as push button as seen in the mode section.
The folder consist of all the libraries used in the main code, such as Blynk library and RTC “real time clock,” which provide us with accurate time using internet without any external supply. With RTC and LCD library we can have LCD display accurate date and time.
Quick guide to run the main code in Particle Dev:
Select the main folder which includes all the files (Main code + Libraries)
Before flashing the code, make sure that the device is online as indicated in the yellow box below!
Please note that we’re flashing only SparkTimeExample.cpp
The smart home industry has been developing very quickly in recent years. More innovators and developers are investing in this field and more devices are being produced every day.
This IoT alarm clock project was inspired by Ian Sterling who came up with an amazing project using Microsoft HoloLens. The concept, which he calls “IoTxMR,” allows the user to simply look at a gadget and command it with gestures.