November 1, 2011 Leave a comment
Here we are on November 1st, 2011. As the sugar rush from last night dies off, it is a good time to begin planning for next year.
Halloween is a big deal around our place. Carving pumpkins has always been an epic ritual for my wife and me. We have done everything from adding Christmas lights as hair to dressing up our jack-o-lanterns in a tux and wedding dress (the year we were married). Below is last year’s entry: my carving of Yoda.
Sadly, this year we did not participate. That means that next year, we have to go even bigger to make up for this year. I’m thinking animatronics.
I purchased a voice recording unit from Radio Shack a few weeks ago and wanted to use that in this year’s pumpkin, but I decided to hold off until I could implement it in a grander scale. While doing some brain storming, I was suddenly struck with a memory of childhood: eating pizza at Chuck-E-Cheese with a half-dozen animatronic animals singing happy birthday to me. The part of this memory that has always stuck with me is the eyes. Always watching! The livelyhood of the characters came from the eyes darting back and forth. The rest of their movements were merely gravy. To me, moving eyes is the key to animating objects.
My goal for my jack-o-lantern was to add eyes that would move in a way that is relevant to the situation. Anyone can move an eyeball around, but making it move in a way that produces the sense of the object “watching” you is what will make this project worthwhile. I decided to make my pumpkin’s eyes watch the trick-or-treaters approach the door as they walk up the steps.
In this case, I don’t plan on moving the eyes up and down, but rather just left and right. In order to find the rotational degree of each eye ball in reference to where the kid is on my sidewalk, there are two variables that need to be considered: 1) the angle made up of where the kid is in relation to the plane of the jack-o-lantern face and 2) the distance between the kid and the plane of the face. Once I have these variables, I can rotate the eyes left to right in order to point both eye balls directly at the kid.
Here is the approach…
1) Determine the angle and distance variables using a servo-mounted ping sensor. Ping sensors are ultrasonic distance measurement sensors that send out an ultrasonic tone and then measure the time it takes to receive the echo. The shorter the time, the shorter the distance (since sound moves at a reasonably stable speed). By mounting the sensor on a servo and the servo in the dead center of the top of the pumpkin, the sensor can be wiped back and forth over a 180 degree range. The servo will start at 0 degrees (facing the left ear) and take a distance measurement. Once the distance has been measured, it will move 1 degree to the right and take another measurement. This will continue to 180 degrees (right ear). With distances measured on all 180 degrees, the angle with the shortest distance is picked as the one with the nearest target.
2) Eye balls made of ping pong balls (maybe with LEDs inside?) are mounted on independent servos (one for the right eye, one for the left). These are mounted inside of the pumkin with the eye balls exposed through the jack-o-lantern’s eyeball sockets. Two measurements are taken: L and R. L is equal to the center of the left eye ball to the center line of the jack-o-lantern (on which the ping sensor’s servo is mounted). R is equal to the distance from the center of the right eye ball to the pumpkin’s center line. These will be used later.
3) The three servos are controlled by an arduino that is mounted inside the pumpkin. Since we are using electronics, the traditional candle used to light up the pumpking will need to be replaced with LEDs, but that gives us flexibility for other special effects down the road. Maybe RGB lighting that fades from one color to another? We’ll see how that turns out.
4)Using the law of cosines in the code, we can determine the angle of each eye based on the angle of the ping servo and the shortest distance measured, being that the angle and the distance are related at that point of the distance sweep array.
Let’s say the D is the distance measured between the kid and the pumpkin by the ping sensor. R is the distance between the center line of the pumpkin and the center of the right eye. P is the angle of the servo at the time that D was measured. We want to find X which is the angle of the servo mounted to the right eye ball. To know X, we need to determine the distance of the leg of the triangle opposed to angle P. In a right triangle, this would be done with the standard pythagrean theorem. Knowing that it is unlikely that P=90 degrees, we need to use the more extensive one.
Or in our case:
With H determined, we can redo this same equation to determine the angle of x.
Using arccosine, x can be determined to provide the angle of the right eye ball. The same method would be used for the left eye ball.
5) Once the distance is less than a specified value, the voice recording unit is activated to play back the recorded message. Personally, I’m thinking of something like, “You aren’t coming for my candy, are you?” Currently, there is a momentary button used to trigger the playback. I plan to remove the momentary and replace it with a relay that is controlled by the arduino. A relay might be overkill, but I also like the idea of isolating the circuits.
As I mentioned earlier, this would all be processed by an arduino. Below is the shield I designed to interact with the servos, ping sensor, and the relay for the sound module.