Introduction: Crack of Dawn Alarm Clock

If you're the kind of person that likes to wake up as soon as the sun comes out, or only when it is light enough outside, then this project is right up your alley. The premise is that it is an alarm that activates when a certain level of ambient light is present, i.e. a sunrise or high noon or whatever floats your goat.... or boat...

PS please vote for my Instructable using the button above :)

Step 1: Materials

Of course you are going to need a handful of materials to create this masterpiece of hardware and programming. There really aren't that many materials, but here they are

  • 1 Arduino Uno and USB cable
  • 1 photoresistor
  • 1 LED
  • Resistors (1 330k, 1 560k or equivalent)
  • 1 piezo element
  • Computer with Arduino IDE software
  • 9-volt battery with snap (optional)
  • WIRES!!!!!!!!!

Step 2: Assembling the Circuit

Here is a picture of the circuit and its schematic. In case it isn't clear, the photoresistor attaches to pin A0, the LED attaches to pin 13, and the piezo attaches to pin 11. The schematic uses a 560-ohm resistor, but I substituted 2 330-ohm resistors in the actual circuit. Depending on the resistors you choose, you may have to adjust the light value in the code.

Step 3: The Code

This is the code to upload to the Arduino to run this circuit. The piezo buzzer takes up most of the code. This version plays Mr. Roboto, but you can alter the code to make it play any song you want, just make sure that the frequencies in the first declaration correspond with the notes you want to play. The .ino file is also attached if you are feeling lazy. If you do not have the Arduino software, click here.

// Light Sensor Alarm Clock
// // Made by Corbin Newhard // License: Public Domain

// TONES ==========================================

// Start by defining the relationship between
// note, period, & frequency.

#define c 3830 // 261 Hz
#define d 6428 // 156 Hz
#define D 3219 // 311 Hz
#define e 3038 // 329 Hz
#define f 2864 // 349 Hz
#define g 2550 // 392 Hz
#define a 2272 // 440 Hz
#define b 2028 // 493 Hz
#define C 1912 // 523 Hz
// Define a special note, 'R', to represent a rest
#define R 0

// SETUP ============================================
// Set up speaker on a PWM pin (digital 9, 10 or 11)
int speakerOut = 11;

int led = 13;

void setup() {

pinMode(speakerOut, OUTPUT);
pinMode(led, OUTPUT);

Serial.begin (9600);


// MELODY and TIMING =======================================
// melody[] is an array of notes, accompanied by beats[],
// which sets each note's relative length (higher #, longer note)

int melody[] = { f, f, f, f, f, D, f, f, D, f, D, f, f, d, d, R, f, f, d, d, R };
int beats[] = { 8, 8, 8, 8, 16, 8, 16, 16, 8, 16, 24, 8, 8, 8, 8, 1, 8, 8, 8, 8, 1};
int MAX_COUNT = sizeof(melody) / 2; // Melody length, for looping.

// Set overall tempo long tempo = 15000;
// Set length of pause between notes int pause = 0;
// Loop variable to increase Rest length int rest_count = 15;

// Initialize core variables int tone_ = 0; int beat = 0; long duration = 0;

// PLAY TONE ==============================================
// Pulse the speaker to play a tone for a particular duration

void playTone() {

long elapsed_time = 0;
if (tone_ > 0) {
// if this isn't a Rest beat, while the tone has
// played less long than 'duration', pulse speaker HIGH and LOW
while (elapsed_time < duration) {

digitalWrite(speakerOut,HIGH); delayMicroseconds(tone_ / 2);// DOWN

digitalWrite(speakerOut, LOW); delayMicroseconds(tone_ / 2);

// Keep track of how long we pulsed
elapsed_time += (tone_);



else {

// Rest beat; loop times delay

for (int j = 0; j < rest_count; j++) {

// See NOTE on rest_count


} } }

void lightShow() {

digitalWrite(led, HIGH);
digitalWrite(led, LOW);


// LET THE WILD RUMPUS BEGIN =============================

void loop() {

int sensorValue = analogRead(A0);



// Set up a counter to pull from melody[] and beats[]

for (int i=0; i<MAX_COUNT; i++) {

tone_ = melody[i];
beat = beats[i];

duration = beat * tempo; // Set up timing


// A pause between notes...





Step 4: Upload and Test

Once you have the circuit built and the code in the Arduino software, you must upload it via USB cable. Once the code has been uploaded, the Arduino will retain it until a new sequence of code is uploaded. Use either the USB cable or a 9-volt battery to power your circuit, although a 9-volt battery may run down over time because it must be draining power all night to keep the sensor working. (I apologize, in the video, my LED is not hooked up to ground, but you can see the LED blinking on the Arduino board)

Enjoy the build and wake up to the sun!

Full Spectrum Laser Contest 2016

Participated in the
Full Spectrum Laser Contest 2016

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016

Digital Life 101 Challenge

Participated in the
Digital Life 101 Challenge

Hack Your Day Contest

Participated in the
Hack Your Day Contest