Building an Arduino Powered Sunrise Alarm Clock

Robert Moe
7 min readNov 6, 2018

--

As the days get colder and sunlight gets rarer, it can be a chore to wake up in the morning. After seeing a few articles saying just how awesome using a sunrise alarm clock is, I decided to make one myself. With some simple code uploaded to an Arduino, we can control a LED strip to try to simulate the sunrise and hopefully boost your mood in the morning. You could buy one — but why not make your own that can be used in a variety of different ways, like a party light?

The Materials:

Adafruit NeoPixel 16 LED Ring Link

SparkFun RedBoard Link

Wires

Soldering Iron/Solder

Globe shade Link

USB Cable

The Board

To power the lights and put the code across to simulate a sunrise, a RedBoard Arduino kit from Sparkfun will be used. The RedBoard is an easy to use Arduino that interfaces well with the official Arduino IDE. To get started with this board, we first need to download the Arduino IDE. It is available for download here.

Follow the instructions for your operating system to get started with this IDE. Once that is downloaded and you connect the RedBoard to your laptop, you are well on your way to sending code to the RedBoard! I won’t get into too much detail about how the RedBoard works, and you can read more about the basics here.

The Lights

To simulate the sunrise, we are going to be using an Adafruit Neopixel ring. Adafruit has a very robust and easy to use Arduino library — and they’re fairly cheap as well. For this tutorial we will be using a 16 LED ring, but for any other projects there are a multitude of Neopixel sizes that are all extremely easy to use. You’ll need to download the Neopixel Arduino library into the IDE to use it. Thankfully, the IDE has a handy built-in library manager. All you need to do is click Sketch -> Include Library -> Manage Libraries. From here, you can search through all the available libraries. We’ll want to search for “Adafruit Neopixel”. Select the Adafruit Neopixel by Adafruit library as shown here.

AdaFruit NeoPixel library

Now we’re good to go! All the downloads are done, and we can work on hooking up the RedBoard to the NeoPixel ring.

Connecting the Two

Get your soldering iron ready! In this step, we will first solder the necessary wires to the LED ring. The back of your NeoPixel ring should look like the left picture:

Before and after soldering

The connections we need to make are to the Data Input, Power, and Ground ports. Find three wires — a red, black, and green one. Solder the green wire to the Data Input port. Solder the red wire to the Power port. Solder the black wire to the Ground port. You can make these connections in any order, as long as you’re not connected to the RedBoard yet. At this point, your LED ring should look like the second picture shown above (maybe even with a better solder job!)

Now we can make the connections to the RedBoard. Without the RedBoard being attached to power, attach the wires in this way:

  • Red: Insert in the “5V” opening.
  • Black: Insert in the “Gnd” opening.
  • Green: Insert in pin #6.

The red wire is inserted here as it’s connected to the power opening in the LED ring. Likewise, the black wire is connected to the ground on the LED ring. The green wire is inserted into the #6 opening, as this is the pin we’re going to use to send data across to the NeoPixel. Now, with this setup being done, we can hook up the RedBoard to our computer and send across some code.

Coding a Sunrise Light

Since we’re going to be using the NeoPixel library in Arduino, you should take a second to familiarize yourself with it. An easy way to do this is by looking at an example sketch. Navigate to the Arduino NeoPixel examples, and select ‘strandtest’.

Selecting the strandtest example

The code here just runs through a few examples of how you can send code across to the LED ring. If your Arduino is hooked up to both your laptop and the NeoPixel, feel free to send the code across by clicking the Upload arrow in the top right. This should set off a light show! If you want to get more acquainted with the NeoPixel library, look here.

Now, we’re going to narrow the code down a bit to function as a sunrise alarm. I’ll paste the code here, then walk through it step by step.

#include <Adafruit_NeoPixel.h>#define N_Pixels 16 //number of pixels in strand is 8
#define LED_PIN 6 //NeoPixel strand is connected to this pin
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_Pixels, LED_PIN, NEO_GRB + NEO_KHZ800);int wait = 40;//balance this number with faderate to regulate speed of fade
int faderate = 400;//higher number here for smoother fades
void setup()
{
strip.begin();
strip.setBrightness(200);//change how bright here
strip.show();

}
void loop()
{
// specify how long you'd like to sleep here
int hours = 0;
int minutes = 2;
int seconds = 20;

sleeping(hours, minutes, seconds);

//start out off, fade up to first color orange (255, 80, 0)
for (int i = 0; i < faderate; i++)
{
int r = map(i, 0, faderate, 0, 255);//fade up the value of red
int g = map(i, 0, faderate, 0, 80); //fade up the value of green
colorWipe (strip.Color(r, g, 0),0);
strip.show();
delay (wait);
}
delay (10000);
colorWipe(strip.Color(0, 0, 0), 0);
}void sleeping(int hours, int minutes, int seconds) {
int delayTime = (seconds * 1000) + (minutes * 60000) + (hours * 3600000);
delay(delayTime);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

This code isn’t the most elegant solution, but it should work to wake you up! In the first 3 lines of the loop function, you can set how long you’re going to sleep for. This should be done before plugging in the light. The sleeping function tells the Arduino to wait for a specified amount of time before doing anything. Once that time has passed by, we slowly start to light up the LED ring. You can experiment with different fade rates to see how slowly you want the sunrise to occur. After that, we let the strip stay on for 10 minutes. Hopefully you’re awake by then! You can now unplug the light, and plug it in again when you’re ready to go to bed.

Improvements and Adjustments

Some improvements and changes can be made to this code, so feel free to tinker! For example, the way to specify sleeping is inelegant. You could add more components to hook up the Arduino to a real time clock, which would allow you to specify the wake-up time each morning. Another addition that could be made is adding a sunset to the light. This way, you are getting both a sunrise and a sunset, and can bust your mood out of the winter blues.

The great thing about creating your own light like this rather than buying one is that you can repurpose the LED ring to whatever you’d like. In this case, the globe has many purposes! You can use it as a party light that changes colors (that’s not hard — just use the rainbow function given in the ‘strandtest’ example). You could use it to light up at certain times to remind you of tasks you have to do. There are almost limitless possibilities, so I hope you continue to tinker and this tutorial has provided you with some confidence in using the Adafruit NeoPixels!

A simulated sunrise

--

--