Wednesday, October 1, 2014

Sunrise Alarm Clock

I usually get pretty aggravated when I get asked if I'm bored by someone who sees me yawn, especially at work. There's a major difference between being bored and being tired! To that end, I decided I'd make a sunrise alarm clock to help improve my sleeping habits. The idea here is that a gradual increase in light helps one's body wake up more naturally, instead of being jarred awake by an audio cue.

The first step was to take an old Wal-Mart alarm clock I had lying around and cut all up into it! As Tim "The Tool Man" Taylor says, before there can be CONstruction there must be DEstruction. He was very wise.


There is clearly one pair of wires going to the speaker, so to keep from reinventing the wheel I used the alarm and timekeeping functionality of the clock and simply cut the speaker out of the circuit, and attached the speaker wires to some input pins on an ATtiny microcontroller. (The Arduino in the picture below is only being used to program the ATtiny.) I didn't want to program a whole clock from scratch if I didn't have to.


I really like this picture because it looks like that one scene in Contact when Ellie Arroway is about to drop through the extremely energetic center of the second machine:


Anyway! The theory seemed to work. When the buzzer sounds, the microcontroller in the clock would send a six volt square wave with a range of +12V to +6V. The ATtiny microcontroller I'm programming sees this signal instead and starts a PWM signal which drives an array of eight high-intensity LEDs. (The speaker is now disconnected.) The PWM increases a little less than half a percentage (1/256th to be exact) every eight seconds, which means that when the alarm starts, the LEDs gradually increase in brightness from off to full brightness over the course of about fifteen minutes. The time can be adjusted in the program if I find that this interval is too long or too short.


The clock had a 16VAC transformer in it, which I tapped off of (green wires) to get power for the ATtiny microcontroller. I built a full-wave bridge rectifier from scratch and regulated the output voltage down to +5VDC. The picture above is the rectifier part of the circuit before I soldered it all together. The red and black wires are from the speaker.


I used 8 LEDs. They draw a little over 100 mA when they're all on at full brightness. I wasn't sure if this extra current draw would overload the clock's transformer but so far everything seems to be OK.


I like the industrial look of exposed electrical components. My personal rule is anything over 40V is dangerous and anything under that is totally OK. (In my job I routinely work with 500 kV so this seems very reasonable!) Your mileage may vary however. Don't be an idiot. The picture above was taken with an extremely short shutter period, while the picture below I think more accurately represents how bright the LEDs are.


One problem I was having at first was that the LEDs would pulse very slightly. It seemed like they pulsed along with the square wave for the alarm which had about a 1 second duty cycle. It turned out that this was entirely coincidental, and they were pulsing because the rectifier I built didn't have a capacitor big enough to keep the voltage across the LEDs high enough. The LEDs would draw current, the voltage would drop, the LEDs would dim as a result, and then when the current dropped the voltage would increase again, and this cycle would repeat about every 1 second. Totally coincidence that this is how often the alarm would buzz, which had me pretty confused for a while. Once I realized they only pulsed when they got brighter (which means a higher current draw) I just threw a huge capacitor in the circuit, which is clearly visible in the picture. For the non-electrical engineers out there, it's that big cylinder on the top left. For the electrical engineers out there, this has the effect of increasing the RC time constant of the circuit. Remember college? Fun times.


This thing is crazy bright although it doesn't do a good job of uniformly illuminating the whole room. Mostly it just blinds me when I go to hit the snooze button. But it does work and it has succesfully woken me every time I've used it. I did wire the LEDs on the board in such a way that I could easily cut into the power wire for them and splice in more lights, though, which I could theoretically put anywhere. That'll be a project for the future though.