Thursday, March 31, 2011

Arduino Servo Shield

I bought a piece of breadboard and was able to solder up a shield for the Arduino to power the 5 servos. I'm taking the direct supply power from the 'Vin' pin and the ground to a bus connecting all 5 servos, and pins 2, 3, 5, 6, and 7 to each signal pin of the servo. Each servo gets its own 3-pin header. It looks really nice and give a solid connection to everything. If I ever need to add other small components it'll be really easy because I left plenty of space.

Here's a small video of all 5 servos cycling back and forth for a little while.

Monday, March 28, 2011

Power Options

I discovered earlier, that I would need an external power supply to drive the servos and that it would need to power the Arduino as well so that the grounds are common. This is no problem as I don't plan on having my clock plugged into the USB port on the computer all the time. I bought some stuff to build my own "Servo shield" to plug in the servos. It's a piece of breadboard and some header pins to connect it all. I was thinking that I would need to split the 5V power leads to provide separate (but equal) power to the servo board and to the Arduino, but I was wrong.

On the Arduino boards, there's a pin marked "Vin" on the Arduino UNO (or 9V on older models) that provides pass-through power when using external power. This is not the limited 5V regulated power to the Arduino, this is the unmodified power from the external supply. (The same pin can be used to power the board, if desired.)

My servo board just got really simple. I bring the power and ground from the external supply and provide them as a bus for the 5 servos. I plan on connecting servos to digital pins 2, 3, 5, 6 & 7. Pin 4 is used to switch on the SD card slot on the Ethernet Shield, and pins 10-13 are used to control the Ethernet port. If I need to add other stuff later (perhaps a chime) I still have all my analog pins and a couple digital pins leftover.

Arduino Data Parsing

Tonight I started looking at having the Arduino parse the location output stored on the server. With the Ethernet shield on the Arduino I call a PHP script that fetches the last locations of each of the family members. That's great and all, but I need to get it down to a person and a location.

The Arduino is not Perl and has no regular expression capability or split functions, but it does have some string functions that might be useful. After poking around for the best solution, I found this forum where a guy was using an Arduino to parse NOAA XML weather data. His code worked like a champ, so I'm using it with some modification. I had to go back and alter my PHP script to output some XML formatted data, but that's a piece of cake.

Now I have two arrays in the Arduino. One for people, and one for locations that have been parsed from the data off the webserver.

Next up: how to translate that location data into physical servo locations.

Sunday, March 27, 2011


I decided recently that I would design my mechanism similar to the guy over at, so I ordered 5 of the GWS S125 1T 2BB servos online. They arrived on Friday so I hooked one up to my Arduino with an external power supply, loaded the sample servo sweep sketch, and watched in horror as the servo spinned continuously clockwise.

I browsed all over the web looking for the source of the problem. I read that some people had servos where the pinion gear that drives the potentiometer inside the servo was not firmly attached to the drive shaft and a little lock-tite was the solution. I tried that, but had no luck. I think it actually stripped out the little plastic gear attached to the potentiometer. Metal pinion gear vs. plastic potentiometer gear is not a good recipe for success.

I tried using different pins on the Arduino. No good. I tried running the servo off the Arduino power. It made the Arduino croak due to the load. I tried manually setting the PWM frequency of the servo output, but without an oscilloscope I couldn't see what it was actually doing. Same as before.

After nearly pulling my hair out and abandoning servos for steppers (not sure how I was going to do that since most Arduino projects are limited to 2 or 3 steppers, not 5), it struck me this morning that I was powering the servo off an external 5V supply, and powering the Arduino off the USB port on my Mac. There was nothing tying the ground of the power supply to the ground of the Arduino, and this might be the cause of my problems.

It was! After connecting the power supply to the external power pins on the Arduino, my server happily returned to center. I did have to take apart one of the other servos to get it off the end of the potentiometer travel that was stripped out, but it's functional.

Also, using a frequency range from 0.9 ms to 2.1 ms gave me about 400+ degrees travel from end to end. I only need one full turn, so this is great. I suspect that this servo is capable of more total travel, but I don't want to push it any more in case I hit the ends where the gear is stripped out.

I've modeled the servo in Sketchup, so I should be able to plan out pretty accurately how to mount these things. I don't have any extremely precise cutting tools, but my scroll saw and bench press should be up to the task.

Thursday, March 24, 2011

Ethernet Shield Added

I've been working on my own Whereabouts clock for a while now. For the most part I've just been thinking through some things, but now I'm actually trying to make it a reality.

I got my Arduino Ethernet Shield in the mail today. I revamped the fetch locations script on the web server to update a MySQL database instead of a flat file. Now I have a table for each family member instead of a group of flat files. I also created a fetch script that's used by the Arduino to fetch the latest entry in the database. I plan to parse the results to have the Arduino move the servo motors to the correct location.

My servo motors should be on their way here, but I've still got plenty to work on until they arrive. I'll have to fill in more on this project as I have time.

Wednesday, March 23, 2011

The Location Data

So after looking at a couple examples of a working "Whereabouts Clock" I decided that I wanted to try to make my own. After all, it's really cool! Before I spent any money buying parts and diving into the mechanics of it all, I really wanted to nail down the location data. Other examples use a Twitter feed and keyword searching to grab the locations, but I wanted mine to be fully automatic requiring nothing from me.

My wife and I both have iPhones, so I figured "how hard could it be?"

I started thinking about this project over 5 months ago, and wanted to start with the location data. I browsed around the App Store looking for some way to grab the location data off my phone periodically and upload it to my home server. I found a couple examples that I purchased and found that the folks over at had a really cool product. I downloaded the App and configured it on my phone along with their server. Ta Da! I now had a way to get the location data from my phone periodically.

I messed around with the device-locater app for a while. I hooked it into my Google Latitude account, and with their API was able to collect my location data pretty reliably. Then, Google released their own Latitude App for free that did the same thing as the device-locater App. I tried Latitude for a while, and it was nice, but periodically it would say I was a good 5 miles from where I actually was, so I gave up on it.

The device-locater app actually has a way to call out to your own server to push the data to, so with a little PHP script I was able to get data from my phone, through the device-locater site, into my server. Great!

There was only one little problem. I have an iPhone 4, which has some semblance of multi-tasking. My wife has my old iPhone 3G (not 3Gs), so she has NO multi-tasking. The Latitude and device-locater apps worked fine, as long as she clicked on the app and manually had it update with her location. This was not going to work.

Then, with the release of iOS4, Apple made the "Find My iPhone" feature of MobileMe free to everyone with an iPhone and an iTunes account. Hurrah! I quickly downloaded the app onto our phones and added them to my account. Now I could see my phone and my wife's just by going to the MobileMe site. to get that data to my server??

It turns out that this is not a unique problem, and for the time being has been solved by Tyler Hall. Essentially he's created a PHP object that is an API for the MobileMe find my iphone. With a little PHP scripting I was able to pull the data from MobileMe onto my home server. I setup my script as a cronjob to run every 1/2 hour and grab our locations. I could do it more frequently, but the more often you check the worse the battery life on the phones are.

Hooray! I've been collecting our locations every 1/2 hour for almost 4 months now without a problem. Here's hoping that Apple doesn't shutdown the sosumi project.

The Whereabouts Clock -- Background

I've been a fan of the Harry Potter series since the movies first hit the big screen in 2001. Since then I've read all the books, and I can't wait until the final movie is out. In a couple of the booksand in the movies there are a few references to a magical clock at the Weasley's house:

The first specific description of the family clock is from Goblet of Fire (pages. 151-153):
Mrs. Weasley glanced at the grandfather clock in the corner. Harry liked this clock. It was completely useless if you wanted to know the time, but otherwise very informative. It had nine golden hands, and each of them was engraved with one of the Weasley family’s names. There were no numerals around the face, but descriptions of where each family member might be. “Home,” “school,” and “work” were there, but there was also “traveling,” “lost,” “hospital,” “prison,” and, in the position where the number twelve would be on a normal clock, “mortal peril.”

Eight of the hands were currently pointing to the “home” position, but Mr. Weasley’s, which was the longest, was still pointing to “work.”
. . .

“Oh your father’s coming!” she said suddenly, looking up at the clock again.

Mr. Weasley’s hand had suddenly spun from “work” to “traveling”; a second later it had shuddered to a halt on “home” with the others, and they heard him calling from the kitchen.
It appears again in Order of the Phoenix (pages 471-472):
”And Dumbledore – what about Molly?” said Professor McGonagall, pausing at the door.

“That will be a job for Fawkes when he has finished keeping a lookout for anybody approaching,” said Dumbledore. “But she may already know . . . that excellent clock of hers . . .”

Harry knew Dumbledore was referring to the clock that told, not the time, but the whereabouts and conditions of the various Weasley family members, and with a pang he thought that Mr. Weasley’s hand must, even now, be pointing at “mortal peril.”
And in the Half-Blood Prince (pages. 85-88):
She turned to look at a large clock that was perched awkwardly on top of a pile of sheets in the washing basket at the end of the table. Harry recognized it at once: It had nine hands, each inscribed with the name of a family member, and usually hung on the Weasley’s sitting room wall, though its current position suggested that Mrs. Weasley had taken to carrying it around the house with her. Every single one of the nine hands was now pointing at “mortal peril.”

“It’s been like that for a while now,” said Mrs. Weasley, in an unconvincingly casual voice, “ever since You-Know-Who came back into the open. I suppose everybody’s in mortal danger now . . . . I don’t think it can be just our family . . . but I don’t know anyone else who’s got a clock like this, so I can’t check. Oh!”

With a sudden exclamation she pointed at the clock’s face. Mr. Weasley’s hand had switched to “traveling.”
. . .
Harry saw Mrs. Weasley glance at the clock in the washing basket as they left the kitchen. All the hands were once again at “mortal peril.”
I've seen a few attempts to recreate this clock in a real and physical sense. This person created a very good looking clock that updates the locations via keywords in Twitter feeds. Microsoft apparently is making an attempt as well, but theirs doesn't look much like a clock.

I wanted a nice looking clock that would automatically track my family without having to update locations manually. My wife and I both have iPhones, so this should be easy, right? It turns out that what I thought was hard (the location data) is actually pretty easy.