How to Build Your own IoT Alarm Clock using Blynk

How to Build Your own IoT Alarm Clock using Blynk

iot alarm clock

iot alarm clock

Here is a demo video of the project:

Overview

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.

Hardware:

  1. 1 x Particle Photon
  2. 1x 2×16 LCD screen
  3. 1 x Buzzer

Software:

  1. Online particle IDE or particle Dev
  2. Blynk app

Particle Photon

iot alarm clock

Figure 1: Photon / © Particle

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):

 

iot alarm clock

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.

Particle Dev

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. 

Getting Started

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

iot alarm clock

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:

  1. Create your project
  2. Choose your main microcontroller
  3. Get the auth token for linking the app with the hardware project
  4. 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.

iot alarm clock

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.

iot alarm clock

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.

iot alarm clock

Press on the “+” icon on the top right to choose between the available buttons and widgets provided by the Blynk.

iot alarm clock

For the sake of simplicity, I’m going to choose a simple button to test the blinking functionality from the app.

iot alarm clock

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.

iot alarm clock

Now the button is set and you can see that the button reads D7.

iot alarm clock

Sketch :

You have to flash this code to your Particle before running your app.

How do you flash the code? It’s simple! Download the code and open in Particle IDE.

iot alarm clock

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.

iot alarm clock

Flash button actually flashes the code to the device.

2. Connecting LCD Screen

iot alarm clock

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.

Wiring :

iot alarm clock

 

iot alarm clock

Figure 3: Wire diagram of LCD & Photon

Sketch :

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.

iot alarm clock

Figure 4: LCD Pin Diagram / ©allaboutcircuits

3. Get the Buzzer working

iot alarm clock

Figure 5 : Buzzer / ©linksprite

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 .

 

iot alarm clock

iot alarm clock

Figure 6: Wire diagram of LCD, Photon and Buzzer

 

Sketch :

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.

iot alarm clock

It’s important to set your alarm button’s functionality as a switch as shown below in the mode section.

iot alarm clock

Unlike the Alarm button, all the other buttons will be set as push button as seen in the mode section.

iot alarm clock

The Main Sketch

Running the main code is very simple on Particle Dev. Just open the main folder from the IDE and flash the main file SparkTimeExample.cpp.

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)

iot alarm clock

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

iot alarm clock

Summary

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.