Aaron's Class Projects

Final Project - Arduino Alarm

Online Links

This lab is available on my personal website at: http://aaronnelson95.com/IT441Final.php

The code is also available on my GitHub repository at https://github.com/AaronNelson95/IT441



The purpose of this project is to learn how to combine Arduino devices to create an alarm clock supplement. Three Arduino devices will be subscribed to an Adafruit IO MQTT feed. This feed will be turned on by an alarm set in IFTTT (through a Date & Time service). Once activated and a value is sent through the feed, a device connected to a light strip will turn on to provide light in a room. A second device will perform an HTTP Get request to a weather API. The JSON returned will then be parsed and displayed on an OLED display screen. The alarm can then be turned off through Google Assistant or any other IFTTT connected service, or by opening the bedroom door when a magnetic reed switch becomes disconnected. This lab will help one learn:

·        How to use IFTTT to design applets that publish data to an Adafruit IO feed

·        How to use the FastLED library to activate LED lights on a light strip

·        How to connect to an API and receive its JSON information

·        How to parse through JSON in Arduno

·        How to display text on an OLED screen

·        How to develop a practical product that can meet your needs by using Arduino devices



To complete this lab, you will need the following materials:

·        A computer with the Arduino IDE

·        Three Wemos D1 mini microcontrollers

·        Three Micro USB power cords

·        Three breadboards

·        7 Male-Male Jumper Wires

·        A WS2812B LED Light Strip
Image result for ws2812b led light strip"

·        A SSD1306 Wemos OLED Shield (screen size 64x48)
Image result for ssd1306 oled shield"

·        A Magnetic Reed Switch (such as the Aleph DC-1561)



The following links may be helpful throughout this project:

·        https://www.norwegiancreations.com/2018/01/programming-digital-rgb-led-strips-with-arduino-and-the-fastled-library/ - How to set up a LED light strip with Arduino

·        https://www.youtube.com/watch?v=9KI36GTgwuQ – A more advanced tutorial on using a LED light strip with MQTT and Home Assistant

·        https://create.arduino.cc/projecthub/officine/getting-weather-data-655720 - A tutorial on obtaining weather data from an online API and how to parse JSON data

·        https://techtutorialsx.com/2016/07/17/esp8266-http-get-requests/ - A tutorial on using HTTP Get requests

·        https://openweathermap.org/current#format – An online weather API that works across HTTP

·        https://arduinojson.org/v6/example/http-client/ - An example on how to read and parse JSON data

·        https://arduinojson.org/v6/assistant/ - An essential tool for allocating memory and understanding how JSON is read with Arduino

·        The Adafruit IO Feed Example at File -> Examples -> Adafruit MQTT Library -> mqtt_esp8266_callback

·        The OLED screen example at File -> Examples -> Adafruit SSD1306 Wemos Mini OLED -> ssd1306_64x48_i2c

·        https://ifttt.com/ - Used to combine services that will post a value to the Adafruit feed to trigger the alarm

·        https://io.adafruit.com/ - An online MQTT Broker that can work with IFTTT and Arduino devices



1.      Design documents to help you understand the logical flow of the system.

a.      A system diagram will help you to understand how each device communicates with each other. Basically, when a Date & Time based applet runs in IFTTT, a value of “1” is posted to an Adafruit IO MQTT feed. The three Arduino devices are subscribed to this feed and will turn “on” when it receives this value. The LED light strip will turn on its lights. The weather screen device will make an HTTP Get request from an online API and will display its results on an OLED screen. The magnetic reed switch will now check for a door being opened. If the switch’s door is opened, Google Assistant is spoken to, or a different IFTTT applet is activated, a value of “0” is posted to the feed and all devices will turn “off”. You can view an example system diagram in the appendix of this report.

b.      Develop system flowcharts for each of the three Arduino devices. This should show an idea of how to program the microcontrollers, as they step through the startup() and loop() functions. You should also plan out how you would like to publish or subscribe to MQTT information. This will start out basic, but as you are working through the code you will have a better understanding of how the Arduino script should handle data. You can view example flow charts in the appendix.

2.      Setup the three Arduino devices. The circuit diagrams for these three devices are shown in the appendix.

a.      Connect one Wemos board to the LED Light Strip. Wire colors depend on your model, but generally, one of these wires is meant to handle the power, and should be connected to 5V. Another should be connected to Ground, and a third wire works as data, and should be hooked up to a random pin, such as D6. It may be tempting to line these up and use pin D4, but be aware that this pin also controls the onboard built-in LED light, which will always be on if you use this pin for data.

b.      Connect another Wemos board to the OLED Shield. If soldering allows, you can just place the shield directly on top of the board. If it doesn’t, however, you need to connect the 3V, Ground, D1 (which is SCL), D2 (which is SDA) pins.

c.       Connect a third board to the magnetic reed switch. One wire will be connected to a random pin, such as D6, and the other will be connected to GND. It does not matter which wire is connected to which pin.

3.      Setup a connection between IFTTT and Adafruit IO on your computer or phone

a.      Create an account (if you haven’t done so already) at https://io.adafruit.com. Once signed in, click the “IO” tab on the top of the page, then select the “Feeds” tab and click “view all”

b.       Click “Actions” and “Create a new Feed”. This is the “topic” that the relay will subscribe to. Once created (name is “Alarm”), view that feed. Notice how the URL to this topic goes “<your username>/feeds/<topic name>”. Later in the Arduino code, you will need to specify both of these parameters to access your information.

c.       Click the AIO Key tab on the top right of the page. Copy the “Active Key” and save it for later. This will be used to give permission for your Arduino device to access the Adafruit IO feed.

d.      Sign into IFTTT and go to https://ifttt.com/adafruit. Connect your Adafruit service to your IFTTT account. Now you can create and experiment with various IFTTT triggers to post a value to your Adafruit IO feed. For increased security, you can come up with a specific value that would cause the relay to be activated (and all others will be ignored). The “That” portion of your applet will work with Adafruit IO and send data to the feed name (given in step 4b), and the activating value you would like to send (such as a simple “1” to turn the alarm on).

                                                         i.      To simulate an alarm, create multiple “Date & Time” events. Pick “Every day of the week at” and specify the time and days for that alarm to run.

e.      You should also setup triggers to turn the alarm off by posting another value (such as “0”) into the feed.

                                                         i.      You can trigger this same action with multiple, separate triggers, for example, you can use an IFTTT button (which is activated by a phone widget) to do this action.

                                                       ii.      You can also link IFTTT with Google Assistant and specify phrases you would like to say to trigger the action such as “Turn off my Arduino alarm” or “Turn off my light strip”.

f.        Test that your triggers work. When they are activated, you should see the table populate with the value in your Adafruit IO Feed page.

4.      In the Arduino IDE, install the libraries you will need to work with this project. All three devices will use the “Adafruit MQTT Library” by Adafruit. The light strip will also need the “FastLED” library by Daniel Garcia. The weather screen will use “Adafruit GFX Library” by Adafruit, “Adafruit SSD1306 Wemos Mini OLED” library by Adafruit + mcauser, and “ArduinoJson” library by Benoit Blanchon.

5.      Program the LED light strip device. It may be helpful to first verify that you can connect to the Adafruit IO MQTT feed to receive data. Then you can work with the FastLED library to turn on lights. Although you may have many lights on the strip, use caution when powering the strip through your board! Trying to power all of the LEDs with bright lights may wear down your device. Instead, using 15-30 lights is generally safer unless your strip can connect to an external power source.

6.      Program the weather screen device. Once again, ensure you can establish a connection to Adafruit IO. It may be helpful to split the program further and develop 3 separate functions for the device’s function.

a.      First, see if you can use the ESP8266HTTPClient library to connect to an API and store the JSON into a variable. Generally, if you are using an online API service, you will need to obtain a key (available for free typically, but they work to limit the calls you make in a period of time). If using OpenWeather, create a free account and record your key value. Explore their documentation (https://openweathermap.org/current) to see examples of API calls, which simply look like typical URLs with additional parameters attached (such as “?zip=55555”), build the URL that returns the data you want, and test it in the web browser to see if you can view all of your information.

b.      Converting JSON data in Arduino is a little tricky and will require help from the ArduinoJson library. Examples of how to use this is in the above References section. You will likely need to go to https://arduinojson.org/v6/assistant/ to calculate your program’s script. Here, you paste in the JSON code from your API (copied from the web browser). Lower in the code, there is a “Parsing program” section. Use the information here to build your Arduino program. You will need to find the size of the JSON (which it calculates for you), build an object with it, deserialize the data, and access the values you want to obtain. It may be tricky at first, but this site will help you a lot.

c.       Finally, display this information to the screen. It may help to play around with the example at File -> Examples -> Adafruit SSD1306 Wemos Mini OLED -> ssd1306_64x48_i2c to understand how this library works. Don’t forget to run “display.display();” to actually commit the text and changes to the board.

7.      Feel free to program any other devices you would like. For example, you can use the magnetic reed switch to act as another method to turn your alarm off (rather than Google Assistant and IFTTT). If you sleep with your door shut, you can know you’re awake when the door becomes opened, which this switch can easily test. Try to program the logic of these devices to only activate when the alarm is already running. When it should be activated, simply publish the off value (“0”) to the Adafruit feed. You can also use the echo distance sensor to detect when you are moving or walking around. Have fun exploring new and creative ways to confirm that you are awake.

8.      Verify that the entire system works by manually submitting your “on” value to Adafruit. The light strip should turn on and the OLED screen should now display your weather data. Tweak your programs as you see fit. Ultimately, they should work like the system diagram designed earlier (provided in the appendix). Enjoy this practical and useful way to use Arduino devices to enhance your daily life!



Thought Questions

1.      How well did the project solve your initial problem?

A challenge I have always faced is with waking up on time. It is a problem I share with many other college students. I am often up too late in the night working on homework, and then I only have a few hours to sleep before I need to make it to my early class. In such a tired state, and combined with the darkness of my room, I have a hard time waking up, even to an alarm clock buzzing off! By the time I finally get moving (snoozing as many times as I can), I am too much in a rush to get out the door. Without having time to properly prepare, I am not aware of the day’s current weather forecast, and I may be poorly dressed, unprepared for the elements. I wanted to build a device that could help me with both waking up because of dark conditions, and for knowing what I should wear for the rest of the day. Using Arduino devices, I was able to accomplish both of these challenges! When the alarm goes off, LED strip lights activate, providing me with enough illumination to see around my room. My other device works extremely fast, and provides me with a quick look at the weather conditions and the temperature at a glance. I also built this system independent of my audible alarm clock, so it can remain on and help discourage me from snoozing my clock. Testing this system out has worked pretty well. It has gone off in the mornings, within less than a minute of the time I had scheduled. I have found it very nice and convenient to have more light in my room, and the various methods I have incorporated to turn off the alarm require me to either move out of my bed or be cognitive enough to speak to my phone. I am proud of the way my project turned out, and I am thrilled that I was able to build something practical that can help me with my everyday needs.


2.      What new technologies did you incorporate?

I used many new technologies in this project. I had to borrow the devices and look around at quite a bit of examples to gain an understanding of how they work. One of these technologies is an LED light strip. It was interesting to me to learn how you can control and manage individual lights on a strand or use functions and math to make cool and creative patterns appear throughout the strip. I also learned about using Arduino to show text on a screen. It was quite a bit simpler than I imagined, but the screen also has so many additional graphical capabilities as well. I learned about API web requests and gathering data from them and storing it. I also learned about parsing JSON information with an Arduino board, which was actually more complicated than I anticipated. It was confusing to calculate how much space you needed to allocate for the object, but luckily there are great resources on the internet that can figure this out for you and how you can find the find the information you want.


3.      What challenge did you face with this project?

The biggest challenge I faced was in trying to obtain JSON data from an online API. I was able to use a HTTP Get request, which worked great, but I could never figure out how to properly do a HTTPS request. The main API I wanted to incorporate, which displayed all of the information I wanted accurately, only worked across HTTPS. I spent a couple of hours trying to figure out these requests. I followed online tutorials and examples, which suggested using certain libraries, or even directly copying a certificate directly to be used. However, I was unsuccessful. I ultimately decided to use a different weather API, which was more basic, but it worked across HTTP. When making a request to this type of page, I had no problems whatsoever. A future goal is to learn how to obtain the HTTPS information from the API I originally wanted to use.

I also had a problem with the LED Light Strip and the used Arduino board attached to it. I noticed, when plugging it in, that it put off a burning smell. Afraid of any potential problems, I disconnected the board from power. As I did more research online, I discovered that even though the 5V is supposed to directly pass into the light strip, it is not enough power depending on the number of lights available, and it can cause overheating with the Arduino board. Using less lights on the strip (such as 15-30) and incorporating lower LED brightness can make your device much safer to use. It is recommended to use an external source to provide power to your LED lights, rather than through the Arduino board.


4.      What are future goals with the project?

I was able to get my project to a state that worked for my needs. However, there are other things that I would like to incorporate someday. As mentioned, I would like to incorporate a Get request with a HTTPS secured page. I just really liked the weather information from another API better, and it was much more accurate as well. However, I simply could not figure it out, but I will spend more time in trying to. I also would love to control more of the LED light strip lights. This will require attaching them to an external power source (which I will need to learn more about), but the FastLED library has so many fun, colorful possibilities I would like to play and experiment with. Eventually purchasing a larger OLED display screen (48x64 is just too small) can also open up a world of possibilities. With this device, you can perform all sorts of functions and calculations because of unlimited number of things that can be shown on a screen. It seems like it could be the most practical Arduino device I have used yet! I really enjoyed working with these new technologies, and I believe I can implement them in many more helpful ways in my life.


5.      Estimate the time you spent on this lab and report.

I spent around 10 ½ hours designing and building the Arduino devices for this lab. I stretched myself with learning new technologies and libraries in fun, creative ways. It took some time, but I was eventually able to solve or find alternative solutions to my problems. I spent around 6 hours working on the lab report, and additional time in preparing my final PowerPoint presentation. Overall, I invested around 18 hours in this project.



Certification of Work

I certify that this lab represents my own work. Any code that I used was basic public knowledge and the examples and resources I utilized are provided in the code comments.


Aaron Nelson




Images of Final Product

When the alarm is not set on, the screen display is blank and the light strip is off, appearing to be disconnected from power


Once the feed receives a value of “1”, turning the alarm on, the strip lights up and the screen shows weather information

The OLED Screen shows information such as the temperature, the minimum temperature, the maximum, and the weather conditions

On a different day, it shows different values, verifying that the API request is working. This is the screen displayed in the morning

Even with only 15 LED lights turned on in the strip, powered at a lower brightness as well, sufficient light can be seen to illuminate a room

The Adafruit IO MQTT Feed. As can be seen with some of our precise time stamps, the IFTTT alarm trigger is working

Google Assistant can be used to demo the light strip (value = “Lights”), show the weather temporarily (value = “Weather”), or can be used to turn off the alarm (value = “0”). The first two functions are extra features I implemented just for fun




Circuit Diagrams

The LED Light Strip


The OLED Shield Display


The Magnetic Reed Switch



System Diagram


System Flowchart

NOTE: A larger version of my flowcharts are available on my website.




Code (available at https://github.com/AaronNelson95/IT441)