Argh! So close! Last night was the first night I tried to test the new wakeup system (it feels weird to call it an alarm, but wakeup system is too long..?) and it went pretty well - until morning, that is. Then, as planned, there were birds twittering nicely, but the room remained sadly dark. And, totally ruining the intended effect, I was thinking about it all night and kept waking up to see what time it was and when it was supposed to go off!

So, clearly not working yet. Let’s back up… I ended up with a Sony ICF-CD815 Dream Machine CD / radio alarm clock, a nice looking unit with dual alarms. I can imagine a scenario where one of us has to get up at some terrible hour, and can use one built-in alarm, leaving the second one to trigger the system later for a gentle wakeup.

Speaking of "trigger the system", that’s where my troubles began: I needed a way to tell the Arduino that the alarm was going off. I had toyed with the idea of watching voltage across the CD motor, etc, but ruled this out because we’d never be able to play CDs in the room without starting up the light dimmer! After pulling apart and testing everything I could think to test with just

a multimeter (if I keep doing this I’m getting an oscilloscope), I decided to tie into the LED for Alarm A. By attaching my own light here, I could create a signal outside the clock that I hoped I could detect with the Arduino.
It wasn’t that easy. The light can be either solid on or solid off depending on if the alarm is set or not, and it goes to a "flashing" state when the alarm is actually going off. Hmm. I wrote and tested numerous versions of code to watch for resistance changes in a light-sensitive resistor, and went to bed believing I had it nailed.
The complication lies in the poor sampling ability of the resistor (that pulse line above is actually pretty wavy) and the timing issue of the blinks: no matter what I tried, the code would sometimes miss a blink, and decide the alarm was over. What I ended up doing was keeping track of the last 8 samples and counting state changes. If I could say that the light "changed" (beyond a certain threshold) at least 3 times out of 8, it was "blinking". This leads to a little bit of lag - 8 samples takes about 5 seconds - but it seems to be working.

… of course, I didn’t get that sample size right until too late. This morning some combination of being in the dark and possibly a loose connector left the whole thing inoperable. Dag. Always tomorrow morning, I guess!
At right: the little guy making it all happen. (The Arduino board is actually under the piece you can see.) The three clear LEDs are for temporary lighting, the red one represents the furnace until I run that wire, and the buzzer is for the backup alarm. That blue-tape-wrapped thingy on the top is the Alarm A LED glued to a photoresistor for sample the alarm light. Once I get it finalized I’ll put it all on a new circuit board and in a nice box. Also still waiting for the final dimmer kit to arrive… Fun!
(oh, and there’s an output pin standing by to fire the coffee pot in version 2… :)
Leave a Reply