Application Note on Wind Direction

 

Have you ever wondered how to determine the wind direction digitally? The following code can help you with this problem.

 

Background: This code uses a modification of Gray code. Gray code means that only one data bit changes from the one state to the other.

 

An example of Gray code is

0000

0001

0011

versus binary code of

0000

0001

0010

If you were to use binary code for direction, there may be difficulties when changing states. For example, when the weather vane would change from 0001 to 0010, two bits need to change simultaneously. This simultaneous change is not always possible, thus the code could result in 0011 instead of 0010. Gray code only requires one bit to change at one time, thus the direction will be more accurate.

 

Actual code:

The code assumes north to be 0000, south to be 1111, east to be 0110, and west to be 1001. These values were determined from the modified Gray code.

The attached code requires 4 digital signals. The code then does comparisons on these signals and then outputs the corresponding 16 ascii values (e.g. N, NE, NNE, etc) needed for an LCD display.

winddir.html 

 Written by Erika Peter.

If you have any questions or comments, please contact me at epeter@ualberta.ca.