24 January 2008

The Turing Alarm Clock

This is an old invention of mine. I had trouble waking up for work, and traditional alarm clocks didn't seem to help. I learned to hit the snooze or off buttons in my sleep. The problem was that alarms are too easy to turn off, and so I set forth to create an alarm clock that challenges me to prove that I am awake.

How should it challenge me? Well, I'm from a math background, so the natural choice is with arithmatic. A problem like 23*17 + 6 will keep me thinking for at least 20 seconds; if the alarm clock makes me solve five in a row, then it can be sure I'm awake. There's no way I can learn to do this in my sleep.

The design is powered by a PIC16 microcontroller, which manages the user interface and keeps time. It displays the current time and the arithmetic challenge via a cheap lcd from all electronics.


The design is free and open source; do whatever you want with it.
If you wanted to make advancements to the design, may I suggest:
  • A battery backup. As it stands, you must have enough will power to leave it plugged in.
  • A radio? I suggest the Si4701 single-chip radio.
I will be demoing this thing at the next meeting of Make:NYC. Come check it out!

Update:

46 comments:

Matt said...

Very cool indeed I would love to see where to get the parts from so I can try to make this also. I would have to say I would probably have to make it with simpler math problems.

Anonymous said...

It would be nice you could change the name when it says "Good Morning Nick!"

My name isn't nick.

Nick Johnson said...

@matt:
I bought most of the parts from mouser.com.
I bought the enclosure from radioshack.
I bought the speaker and lcd (lcd-107) from allelectronics.com
I got the board at expresspcb.com

@anonymous:
I'm not sure if a name like "anonymous" would fit on the lcd.

Temo said...

Can I have the part list. Just to make it easy on when I buy them.

bw said...

@anon: So change it to Nick! I did, I'm a cool kid now :)

Anonymous said...

I noticed you had some complex problems(so to say). My 7 & 9 yr olds would not be up to that speed. Does your source code allow for simpler math. Like say 1, 2 or 3 digit Mulitplication or Division

Plasmagrid

Nick Johnson said...

@temo:

I never assembled the parts list, but the schematic program from expresspcb will generate one for you. Drop a line if there's a particular part you can't find.

@anonymous2:

In the source code, at line 1677, the function "ChooseFactor" is responsible for selecting each of the three numbers. It, in turn, calls "Rand5" which is a 5-bit random number. That's why each of the numbers is from 0--31.

If you wanted to make it easier, you might modify it to select 4-bit random number (0--15) or 3-bit random number (0--7).

Rasmus said...

Do you think you could post the schematics in PDF format as well?

Baseer Shah said...

I LOVE THIS IDEA... i have been wanting to invent something like this.. first get a patent and then sell them. (for people like ME who dont know anything about source code...if you sell one please email me at

baseershah@gmail.com

thanks

0xADF said...

I like this. I've always done things like leave the alarm clock across the room (switched it off, fell back into bed...) or on important days hidden the damned thing.

I like your code - I'm more of a fan of relocatable assembler but, for a project of this size, defining registers manually reduces build complexity. It's clear and understandable.

To create exact baud rates and real-time clocks a 19.6608MHz crystal does the trick, without compromising execution speed anywhere near as much as using, say 3.2736MHz.

BUT - as your assembly comments note - crystals are not very stable. I once built a gizmo for my car, which included a clock, and I was surprised at the drift (when the simulator suggested it should be spot on).

Wristwatches' crystals maintain stability because they are held at a fixed temperature by the wearer's body. If you leave a digital watch unworn for several days, it will drift noticeably.

I would recommend powering your clock using an AC-to-AC adaptor to provide, say, 6VAC. As well as smoothing and linear-regulating this to provide your 5VDC for the PIC + LCD, you can condition this with a resistor and zener diode to provide an approximate square wave at mains frequency and feed this to the PIC.

Mains electricity is very strictly timed and so would remove clock drift altogether. This is how the majority of mains-powered clocks keep time.

Anyhow, cool project - keep up the good work!

0xADF said...

Ahem, I of course meant 3.2768MHz.

Should have previewed ;)

Kacela said...

@rasmus - if you don't want to download ExpressPCB to open the files (ExpressPCB is free), I generated a PDF of the schematic and PCB layouts. You'd be better off installing ExpressPCB in my opinion:

http://www.scribd.com/doc/2085434
/Turing-Alarm-Clock-Schematics

Blogger breaks the URL, so paste it back together.

Cameron said...

Have you ever checked out
Instructables?
I think that you need to join and post this there, for those of us with little/no microcontroller experience.

I'd probably hook this up to an amplifier, though. I just don't see myself waking up from that little speaker.

Anonymous said...

source says 'goodmorning eric' 8|

Anonymous said...

Awwww...I've never shopped through ExpressPCB before so it was a real letdown when I found out the price: $58 to ship a board to Georgia. Looks like I'll be trying out the "laser printer transfer" hack at home...

Clay said...

Any chance you could make one for me to buy?

Nick Johnson said...

@baseer shah, clay --
I'm not interested in building any for sale. I've done that a little bit in the past. But, in small quantities, it's only worth my time if I charge about $150/ea, which is more than it's worth.

@anonymous "source says erik" -
Yeah, Erik purchased one from me; I suppose I posted that version of the source.

@kasela
Thanks for doing the conversion for me.

@cameron
I've seen instructables, and I read it often. However, I generally think it's a pain to write step-by-step instructions for this type of a project.

I mean, who wants to read (Step 1) Get board (Step 2) burn firmware onto PIC (Step 3) Populate board (Step 4) put into enclosure.

Dethe Elza said...

This looks cool, it would be a great way to seriously annoy my wife, or to teach my kids to do math in their sleep. But the real challenge, of course, would be to program Lego Mindstorms to convince the alarm clock that I'm awake. Then the alarm clock would have to get smarter to get past the Mindstorms gatekeeper. Let the battle of the smart alarms clocks begin!

Or, as my friend Mike put it, "all hail our new alarm clock overloards."

Nick Johnson said...

This project was mentioned in passing in the washington post: http://www.washingtonpost.com/wp-dyn/content/article/2008/02/19/AR2008021901843.html

Nick Johnson said...

Try that again:

This was briefly mentioned in the washington post: http://tinyurl.com/2pbhs8

Bob said...

You know I'd love to put this next to my wife's side of the bed...She'd kill me in my sleep though.

Anonymous said...

Just watch out - you *will* learn to do this in your sleep if you keep it up, and you will become a terrible monster that we all fear.

Norm said...

came here through the best website in the whole wide world.. hack-a-day..
great stuff.. i will go for this project.. i'll try to implement the radio IC you suggested, along with the mute button suggested by an hackaday member..
a question, did you call it a turing clock for homage to a turing machine? or is there some resemblance to a turing machine that i fail to see?

p.s.
go ahead and compliment daya on her beauty, for she deserves a compliment.. and hey, it might make her day.. :)

Nick Johnson said...

@norm

I'm glad you caught that. It's a homage to the Turing Test, which was posed by the same Alan Turing as a general intelligence test. I like to think of the alarm clock as administering an intelligence test to make a distinctionion between awake and not awake.

If you get it working with the Si4701 or any other radio, please let me know! My problems were that (1) you run out of i/o lines on the PIC, and (2) you have to do level conversion, which I thought was a pain (radio must run at 3v3, lcd must run at 5v, pic could run at either).

Anonymous said...

@Anon on feb 18:

WriteGoodMorning:
MOVLW 'G'
CALL PutChar
CALL WriteO
CALL WriteO
MOVLW 'd'
CALL PutChar
CALL WriteSpace
MOVLW 'm'
CALL PutChar
CALL WriteO
MOVLW 'r'
CALL PutChar
MOVLW 'n'
CALL PutChar
MOVLW 'i'
CALL PutChar
MOVLW 'n'
CALL PutChar
MOVLW 'g'
CALL PutChar
CALL WriteBang

...LOL wut?

Nick Johnson said...

@anonymous, quoting my code:

Yeah, this is how one writes assembly. Why would I have both a putchar function and a "writeo" method? Because:

MOVLW 'O'
CALL PutChar

Takes two words. If, however, I use some letter (such as 'o' or space) enough, I can save space by doing it like this:

CALL WriteO

...

WriteO:
MOVLW 'O'
GOTO PutChar

This is important on the pic, since I have 2048 words for program space. I only use 918 of those words, so I have room for expansion.

A better question might be: why don't I just have a function WriteString, and then store the string "Good morning" in memory somewhere? Because the PIC16 architecture doesn't include any instruction to read data from the program memory.

matt said...

hey, i was just wondering how much this would cost for me to make and if i could get some detailed instructions. this will be the first electronic thing make and im sure it will be tough. thanks (btw, i sent you an email)

Nathan said...

@0xadf

The problem with running such a thing off AC only is you will quickly learn to sleepily pull the plug when it goes off.

I have made a similar system but I only did software - I run it on an old laptop that is plugged in but has a battery. I was afraid I might pull the battery out so I superglued it to the laptop chassis.

Anonymous said...

@ matt
True, happen to remember how much your clock cost when you made it, since I don't have a big budget to work with.

Nick Johnson said...

@matt, anon -

Assuming you have all the tools already--even weird ones like pic programmers--it cost me about $40-50 to build.

Let's see:
- lcd @ all electronics = $4
- enclosure @ radioshack =~ $5
- speaker @ all electronics < $3
- wall wart @ all electronics = $6
- pic16f716 @ mouser = $1
- resistors @ mouser < $1
- capacitors @ mouser < $1
- xtal @ mouser < $1
- 7805 @ mouser < $1
- pcb manufacture @ expresspcb = $59/3

I am undoubtedly forgetting something; if so, it is a minor cost. Also, I've neglected s/h charges in the above list, worst case add $5/merchant.

Most of that cost was in PCB manufacture (about $20/board). You can save money by etching your own boards at home. Instructables has many tutorials for at-home etching.

adrogersam said...

fuck yeah, dude, just linked to this from make. somehow missed it the first time around but recognized your voice in the rss video. concongrats on getting into school, by the way.

Joel said...

As I may have some wake up issues, I like this alarm clock. Could it be extended to assist in identifying those (few) days when you shouldn't work with C programming. So I can stay in bed instead of making more bugs ..

0xADF said...

@nathan

I hadn't thought of that! I guess a backup battery would help but the ultimate solution would perhaps be to use some other form of time synchonisation like adding a radio clock module. Here in the UK, MSF modules are quite cheap.

With regards to:

CALL PutChar
MOVLW 'n'
CALL PutChar
MOVLW 'g'
etc.

This was one bit of the code I wasn't thrilled by. It could be made clearer using suitable macro definitions, at the very least:

CHAR Macro Character
MOVLW Character
CALL PutChar
ENDM
...
CHAR 'H'
CHAR 'e'
CHAR 'l'
...

And there's no doubt some way to pass a complete string to a macro and have the assembler expand it into the appropriate MOVLW/CALL instructions.

Recently I've used MPASM's 14-bit ASCII packing ("DA SomeString"), suitably coded macros and the PIC16F87x's self-read support to great (and memory-efficient) effect, allowing me to use single line like 'Draw_String "Hello, World!"'.

As was pointed out, the PIC16F716 cannot read its own program memory. A suitable upgrade path for added features might be the PIC16F87, a pin- and code- compatible chip with double the program memory and lots of extra features, including self-read/write. It is just over double the price, however.

Jason said...

hey would u happen to have a design for a single layer board, i make my own boards from scratch but am limited to single layer ones. I tried moving some traces and components but space is really limited any ideas would be great.

Thanks Jason

Anonymous said...

Why not just put your alarm clock far from your bed, so you have to get up to turn it off?

daisy said...

i would love to make it but i'm not sure i can, if I have the slightest trouble could i contact you for help ?

Anonymous said...

this absolutely rocks.

documomente said...

How about software programmers write a program like this as software for the iphone or symbian phones?

philips poy said...
This comment has been removed by a blog administrator.
philips poy said...
This comment has been removed by a blog administrator.
Broken Heart said...

Is there any commercial production of this product. Can I purchase it from somewhere?

koko said...

Thank you!

Barry Bowen said...

This is very nice post thanks for share with us.I found some good info about Printed Circuit Board(PCB)

Anonymous said...

Very nice clock! I would like to create a similar clock as a school project however I dont know If I have the stuff to create it. Could you please reply or ad my MSN: msebbe@live.se


//Sebastian

VSC-Rod Mark said...

A nice day for you Mr. Nick Johnson...I just want to ask if what software do you use to open your schematic diagram which has a file extension of .sch. Hope you answer me ASAP. thank you sir...

Thomas Titherington said...

I really like this idea for a project! I'm not sure how to open your schematic files. Can you recommend a software for me?