Only one year until next Halloween

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.

2010 Jack-o-Lantern

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.

Example of calculation

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.


So what is that thing?

It has been a while since I’ve made a post. Plenty of projects are going on that I could be documenting, but right now I just need to focus on turning the wrenches. I did have a moment worth discussing, however. Last night, my wife asked me a question that has stuck with me since I have yet to come up with a good answer. Of all topics, I thought this would be a great one to write about.

As I was surfing around some of my favorite diy sites, I stumbled across an article on something or another that was based on an Arduino. Having seen this word and heard me refer to it many times in the past, my wife asked, “What is an Arduino used for?”

This seems like a question that should have a very simple answer, but yet I can’t find it. Unlike duct tape, the Arduino is not meant for one single purpose and then used for a million other things, nor is it like a hammer which is really only good at pounding in nails. The Arduino wasn’t made for any given purpose. It wasn’t designed to solve a specific need. In a case like this, how do you describe the purpose of something to someone who doesn’t have a concrete understanding of the field when the object at hand doesn’t solve a specific need?

The best I was able to muster was a high-level description of what a microcontroller was. It is the brain behind the robots that build cars and the thermostat that controls the heat in the house. It is the computer that electronics use when they don’t use the kind of computer that sits on your desk at work.

I’m interested in what others have to say about this. How would you describe what an Arduino or any other microcontroller is to someone who hasn’t studied electronics?

Washing Machine Buzzer

Sometimes you need to do things the hard way.  This is one of those cases.

A few months ago, our washing machine died.  This one was beyond my ability to fix, so we broke down and bought a new one.  The model we chose had a bunch of fancy features, but the one that was missing was the end-of-cycle alarm.  With our last washer, we had grown used to hearing a buzzer when the cycle ended.  Now the washer stops and we go about our day not considering the wet clothes sitting in the washing machine. 

Any do-it-yourselfer with any self respect would have no problems opening up the control panel and adding a buzzer to the exising “Cycle Finished” light.  My wife, however, doesn’t have that kind of faith in me, so I have to do things the hard way.  Here is the plan:

A photoresistor will be placed over the cycle finished light.  The value of this sensor will be fed into an Arduino Pro Mini.  This will read the status of the washing machine.  When the light turns on, the arduino will activate a 9 volt buzzer (one second on, one second off) for ten minutes.

Figure 1:  Circuit diagram

Figure 2: Arduino code

int buzzcount=0;
int ledstatus=0;
int buzzerpin=2;  // connect to npn base 
int sensorpin=0;  // connect to photoresistor (w/ pull-down)

// preferences ///////
int trigger=512;    //
int buzzlimit=300;  //

void setup() {               
  pinMode(buzzerpin, OUTPUT);  

void loop() {

void buzz(){
  digitalWrite(2, HIGH);
  digitalWrite(2, LOW);

void setStatus(){
    buzzcount=0;  // reset to 0 when the lid is opened

Drone: Onboard Computer

While I haven’t yet nailed down which helicopter I’m using as a base, the onboard computer is all but finalized.  For now, let’s assume that I’ll be using the S031.  Give that, here is a description of the final product:

The s031 RC helicopter has an onboard 9.6 volt battery.  This will be used to power the Arduino, which supplies both 5v and 3.3v logic to the remaining parts.

Pins D11-D13 -> SD card shield (SPI interface)

Pins 0,1 -> GPS (Serial interface)

Pins A4, A5 -> Magnetometer/Accellerometer ( I2C interface )

Drone Parts

Continuing on with the drone helicopter project, the following is a high-level list of the materials used.

Part Vendor Price
 Syma s031 helicopter (tentative) Amazon  $58.65
 ADXL345 accelerometer Sparkfun  $27.95
 HMC5883L magnetometer Sparkfun  $14.95
 SR-92 GPS Cute Digi  $47.90
 Arduino Uno Sparkfun  $29.95
 microSD Shield Sparkfun  $14.95

Total price tag (not including minor components): $194.35.

The power will come from the helicopter’s internal battery, which is rated for 12 minutes of flight time.  The battery operates at 9.6 volts, which is within the operating range of the Arduino Uno, which, in turn, powers the rest of the components listed above.

Alternatively, I might upgrade the helicopter to the FXD Eagle A68689.  This model is rated for 25 minutes of flight time and is a bit larger, which suggests it will handle the weight of the onboard computer better.  The battery on this model is a 7.4 volt, which is still within the operating range of the arduino.

Drone Architecture Update

In my original post about the drone project, I had mentioned that the wayponts would be saved on an SD card, which is read via the Adafruit SD card breakout.  Since that post, I have narrowed my search of RC helicopters to the point where I no longer feel the need to use the Teensy micro controller to save weight.  Instead, I will use a regular Arduino Uno.

By using the Arduino, I can shift the architecture of this project away from the model of having a pcb board with breakouts for each of the components and move to a shield-style architecture.  The Arduino is styled in a way that allows the developer to stack modules on top of each other like legos.  Using this approach, I will no longer use the Adafruit module, but rather the Sparkfun SD card shield. 

A side benefit of migrating to the Arduino is that the voltage regulation is built in.  I will not need to build a voltage regulator to power the system, but rather pull the regulated voltage off of the Arduino.  The downside is that the Teensy has more I/O, but I can’t imagine that I’d be using all of the I/O on the Arduino, let alone enough to require more than what the Arduino supplies.

Drone: Overview

Since my garage is now in storage mode again (my wife has emptied the basement to repaint), woodworking has been put aside for a while.  I’m turning my attention back to electronics and have taken on a new project.  I’m looking to build a drone helicopter that will navigate to pre-determined GPS coordinates.

Here is the high-level approach:  Using a cheap, store-bought rc helicopter, I will remove the RC portion and replace it with a micro controller and a few sensors to interface with the helicopter’s controls.  Instead of the receiver managing the servos and speed controllers, the micro controller will do the driving using the arduino servo library.  GPS coordinates will be stored on an on-board SD card in a text file that can be read by the micro controller.  The micro controller will have three sensors attached: a GPS module, a 3-axis magnetometer, and a 3-axis accelerometer.  The magnetometer and the GPS will manage navigation and the accelerometer will manage the stabilization and motion of the helicopter.  In a later version, I plan to add an ultrasonic transducer (i.e. ping sensor) to augment the navigation, but let’s learn to walk before we learn to run.

Here is my strategy…

First, I’ll take the helicopter and locate a few things:  Battery, rc receiver, speed controller of the main rotor, and speed controller for the tail rotor.  With each of these noted, I will remove the  rc receiver.  How much does this unit weigh?  This is a good question to ask since it gives me a little wiggle room for the weight of the computer(micro controller, sensors, and board) I’ll be adding.  Since the toy helicopter I plan to use will be fairly small, weight is the primary concern.  While I would like to use a regular Arduino, I think this is a great opportunity to use a Teensy.  Every ounce saved will help.

Next, I have to power up the added computer.  Tying into the existing battery, I will add a voltage regulator circuit.  While this probably wouldn’t be necessary (depending on the voltage of the battery) if I were using an arduino with a built-in regulator, the Teensy does not have on-board regulation.  The board will need to have regulated 5v and 3.3v output.  One that exists, I can add the Teensy micro controller, the GPS, the magnetometer, and the accelerometer.  The GPS is the largest of all of these.  I plan to tuck it into the body of the helicopter where the RC receiver once sat and wired to the board with some hookup wire.  The rest of the sensors and the SD card breakout will mount directly to the board, which will be mounted to the bottom of the helicopter.

In following posts, I’ll go into detail on how the sensors are used and how the drone computer is designed.