Tuesday, June 15, 2010

Wind Direction Finder: Building and Coding

I've made steady progress on the small boat wind direction finder. Soon after the magnetic shaft encoder arrived in the mail, I mounted it to a 1/2 inch pvc end cap and attached a phone jack to the 5V, analog, and ground leads. This end cap/sensor configuration will be secured to the boat on the end of a foot long length of 1/2 inch pvc pipe. The pipe will raise the vane above the mast, away from the sails and lines as well as provide a solid, but removable way of attaching the sensor. (see photo below)

Before coding, I connected the sensor to the "analog input 0" pin on the Arduino (female phone jack ->; screw down electrical connector ->; breadboard ->; Arduino... a very round about way of doing things but it works) to feed sensor data to the micro controller. From here it was straight forward to write a code that would map the sensor readings to 360 degrees of wind direction. (see above photo)

Turbulent airflow around the wind vane, vibration in the boat, and the high sensitivity of the sensor will all cause an undesirable rapid change in the readout of wind direction. This can be solved by taking a number of readings within a short period of time and averaging them to provide the wind direction, free from unwanted "noise". Converting the code to produce an average reading proved somewhat problematic. Sensor readings close to "dead ahead" are either large (close to 360) or small (close to 0), but averaging these gives headings around 180, the completely opposite direction! With a bit of math and a few if statements I was able to hash out an averaging system that gives accurate readings in any direction. (for those interested in how this works just e-mail me, I'll explain and send you the code)

The remainder of the project is mostly mechanical in nature. A wind vane needs to be attached to the sensor, the pvc pipe needs to be affixed to the mast, wires run, and a dial created for easier readout. More to come later....

0 comments:

Post a Comment