Since my toaster has been on the Internet Twittering my toasting habits, I have been flooded with email asking what I was going to do next. To be fair, most of the email suggested that I had too much time on my hands. My mom got me an iPod Touch for Christmas (she gave it to me a few days early). I have not had the thing out of my sight since she surprised me with a wonderful gift. She also gave me Batman which I transferred to the iPod. I turned the screen about 44 times a minute while watching The Joker and The Dark Knight try to out smart each other. This got me thinking, “Could I control a motor with the movement of the iPod?” I had my next hack.
The iPhone or iPod Touch has an accelerometer that detects how the device is oriented. As the devices moves off axis (from straight up and down) the screen rotates. I want to use that feedback to control the position of a motor or servo or cause specific events to happen depending on the device’s position.
Taking the ioBridge IO-204 module, I connected the servo controller and a servo to one of the channels. On the servo I taped a Best Western hotel pen to show the movement of the servo. I found from hours of testing that the Best Western worked the “Best” and Hampton Inn worked slightly worse.
On the ioBridge website, I created 3 widgets that corresponded with the orientation of the iPod. “Left” for when tilted towards the left, “Right” when I turned right, and “Forward” when I was holding the iPod normally (straight up and down).
Warning: The next part involves some light programming. I made a quick HTML file with some JavaScript that detected the orientation of the iPod and called the appropriate widget. The orientation code is below for those of you that are interested in trying this for yourself:
[cc lang=”javascript”]function updateOrientation() {
switch(window.orientation){
case 0: widgetExecute(“Upright Widget ID”);
break;
case -90: widgetExecute(“Right Widget ID”);
break;
case 90: widgetExecute(“Left Widget ID”);
break;
}
}[/cc]
Load up the completed HTML file on your iPhone or iPod Touch and now you can control a servo with the turning of your iPhone. I call it “iTurn” (didn’t see that one coming, did you?).
Here is a YouTube video of the iTurn project: