Sunday, April 22, 2012

$5 Flashing LED Light Alarm Clock


Don't mind the crying kid in the background

I had two basic problems that led me to this project:
1. I needed something to wake me up without waking up my wife.  (Headphones fall out of my ears overnight.  I thought of that.)
2.  I hate the sound of alarm clocks.

My answer: the LED light alarm clock! LEDs are problematic for normal lighting because the light is only bright within a narrow range.  For us, this is perfect as it lets us focus the light on just one person, letting the co-sleeper snooze on.

Parts and Cost:
1 Cheap Alarm Clock ($1.99, eBay)
5 White LEDs ($0.35, 50 for $3.29, eBay)
1 2N3904 (or other NPN) Transistor ($0.20, 15 for $2.99, RadioShack)
1 8 ohm Resistor ($0.01, 1000 for $7.50, eBay)
1 2 x AA Battery Holder ($1.99, RadioShack.  abt. $0.50 on eBay)
2 AA Batteries (You probably have some around)
–––––––––––––––––––––
Total = About 4 or 5 bucks

Warning:  Some of this goes against good electronics practice.  Just so you know (see step 3).

The basic concept here is that somewhere in your average alarm clock is something that makes sound.  For it to make sound, it needs pulses of current.  Using a transistor, you can use that current to switch on current for whatever you want!
The left circuit is the part built into the clock.  The right circuit is the new part.
The question marks stand for whatever is going on inside the clock.  We don't need
 to know how the left part works, just that when the alarm goes off we get current. 

Step-By-Step:
Step 1: Open your alarm clock, find something that looks it makes sound.  Use your multimeter to figure out which side is giving it positive current and which side is negative.  Cut out the sound part

Step 2: Connect the positive side to the base of the transistor.  Connect the negative side to the emitter.

Step 3: Connect the LED circuit as shown in the diagram.  The positive end goes to the collector, and the negative to the emitter.  I use old CDs to set the LEDs because they're rigid, easy to put holes in, and I have a stack of 50 CD-Rs that I'll probably never use in the thumb drive/MP3 age.
 
(Note: Using just one current-limiting resistor for the whole LED array isn’t really a great idea.  Here, the 8 ohm resistor limits the current to (3 V – 2.2 V) / 8 ohms = 100 milliamps.  We just assume that the current will divide evenly giving us 20 milliamps per LED.  With variation among LEDs, it might not be evenly split.  Also, a bigger problem is that if one of the LEDs goes out we still have 100 milliamps, but only divided 4 ways. This gives us 25 milliamps each, which is more than the LEDs are rated for.  It would be better to use a resistor in series with every single LED.  I just didn’t feel like it at the time.)

Step 4: Enjoy!

Just a normal everyday alarm clock

The LEDs.  Get some use out of that stack of CD-Rs you'll never use!

Don't try to take this on a plane, it might look awfully suspicious.

Saturday, February 25, 2012

Scumbag News


Tutorial: Make your desktop picture match the current weather

It changes with the weather!
I've had a problem recently.  I go to campus at 8am and sometimes don't leave until late afternoon or night.  And there are no windows.  Going in when it's sunny and coming out to find snow somehow makes life a little more depressing than it has to be, not because I don't like snow, but because I don't like the idea of being 100% cut off from the world.

Solution: By throwing together a little Unix code, AppleScript, and a free program called GeekTool, I make my desktop picture change to reflect the weather outside.  I use GeekTool to automate running the script at hourly intervals.  You could do this a lot of different ways with plists or other programs, but since I use GeekTool anyway it was the easiest.

What happens is that once an hour, GeekTool executes a Unix shell command that opens an AppleScript script.  The script (using a shell command) gets your current weather from an NOAA website, and sets a JPEG on your computer with a name that matches the weather as the desktop.

End result: your desktop picture matches the weather outside.

The How-To Part:

1. Make a folder in your Pictures folder called "Weather"

2. Open the "AppleScript Editor" application, make a new script, and copy and paste the code below into it:


--
--  DesktopWeatherman.scpt
--  2011.2.25
--  Mark Sawyer
--  bioquizzical.blogspot.com
--

#Find your weather region by going to www.weather.gov and clicking where you live.  The 3 letter code at the end of the new URL should be your region (ex: FOO)
#Change all instances of "CLE" to the weather region you're in (ex: /data/FOO/RWRFOO)
#Change "HOPKINS" to the city you're in (look at www.srh.noaa.gov/data/FOO/RWRFOO to find out what it calls your city)
#For example, if your region is FOO and you live in YUBA, the URL in the code should say "http://www.srh.noaa.gov/data/CLE/RWRCLE | grep YUBA"

#NOTE! Your region might not have a RWR file.  If so... good luck!
# Also, your region might use slightly different weather codes. Look at www.srh.noaa.gov/data/FOO/RWRFOO to find out what codes it uses. 


set current_weather to do shell script "curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2 }'"

if current_weather is equal to "LGT" then set current_weather to do shell script "curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2,$3 }'"

set localFile to "~/Pictures/Weather/" & current_weather & ".jpg"

tell application "System Events"
tell desktop 1
set picture rotation to 1
set picture rotation to "never"
set picture to POSIX file localFile
end tell
end tell
It should look like this by the end.

3. Save the script in your "Weather" folder as "DesktopWeatherman.scpt".  You'll need to edit it to match your region and city.  Everything in the code immediately after a "#" is a comment. Follow the instructions in the comments.

4. Download and install GeekTool.  Make sure to click the "Enable" box when you install it!

5. Make a new Geeklet by dragging the "Shell" icon onto your desktop.  It doesn't matter where you put it.

6. In the "Properties" window in GeekTool, in the "Command" box type
osascript ~/Pictures/Weather/DesktopWeatherman.scpt
7. Still in the "Properties" window, in the "Refresh every" box, type 1800 (the weather site only updates every hour, so checking more frequently doesn't really make a difference).



8. Fill your Weather folder with pictures to match each possible weather status.  The name of each picture should be the weather status followed by ".jpg".  The status names might vary by region.  Follow the comments in the code to see what your region uses.  In most regions, the possible weather codes (I've seen) are:
SUNNY, FAIR, MOSUNNY, PTSUNNY, MOCLDY, PTCLDY, CLEAR, DRIZZLE, LGT RAIN, RAIN, FLURRIES, LGT SNOW, SNOW, FOG, MIX PCPN.
I'm not clear on exactly what some of these mean either, but this might help.

The directory should now look something like this:

I don't have files for every weather condition quite yet...

If it loads some default Mac picture instead of one of your weather pictures, it means you don't have a picture to match the current weather status.

9. To make it show the weather status in words on your desktop, make another Shell geeklet and in the "Command" box type:
curl -s http://www.srh.noaa.gov/data/CLE/RWRCLE | grep HOPKINS | awk '{ print $2 }'
Of course, you need to change "CLE" and "HOPKINS" just like you did in the AppleScript.  The font I use is called "Trade Winds" and from Google Webfonts.

And that's it!  For obvious reasons this will only work in the USA, and you might have to tweak things to get it to work in your weather region. I guess outside of the USA you could still have it match the weather for a US city, I just have no idea who you would do that.

Anyway, enjoy your window to the world!

Attribution: The picture I used for my backgroup in the title was on so many scores of websites that I could not find the original owner.  Please let me know if you can!