PIC-based APRS Weather Station     


PIC APRS 
Weather Station

~ Part 4 Files ~

 

Schematic

 

Source Code

 

All Software Files
(Zip contains files for hex, list, err, cod and asm.)


PIC-WX Windows program


Back to 
Digital Homebrewing Home Page


Part 4 - Wind Speed

Hi again, folks! In this installment we’re going to start working on a homebrew anemometer. I plucked this design off the internet and adapted it for our use here. The anemometer we’re going to build is called the Easter Egg Anemometer, for reasons that will soon be obvious. The original design can be seen at http://www.otherpower.com/anemometer.html. This design uses a brushless DC permanent magnet motor to which plastic easter egg halves are attached to make it spin in the wind. Figure 1 shows how it looks from the top, and Figure 2 shows how it looks underneath (where you can see the motor). From the pictures, it should be obvious how this design got its name!

  

 

The principle behind this anemometer is that the motor acts as a voltage generator as it spins. The output varies in frequency and amplitude with the speed of the motor. The faster the motor turns, the higher the frequency of the output sine wave. If we amplify this output we can use the PIC to count the frequency of the output and determine from a calibration table the speed of the wind that’s making it turn.

I’ll mention up front that a shortcoming of this design is that it doesn’t work for slight winds. It appears that it takes about 10 MPH or so to get it to measure. Lighter winds either fail to make it turn at all, or it turns too slowly for the output sine wave to be detected. If you’re skilled at creating mechanical things, you might be able to come up with a better design. As long as it outputs a series of pulses or a sine wave, it should be usable in place of the easter egg anemometer.

Building the Anemometer

Luckily, the people who designed this anemometer also sell the motors so others can build it. Go to http://www.otherpower.com/cgi-bin/v2/order1.cgi on the web (or click the “ORDER NOW!” link at the bottom of the anemometer page listed previously), and search the list for “Brushless Permanent Magnet DC Motor for Anemometer.” As I write this, they sell for $2.50 apiece plus shipping.

I constructed my anemometer by gluing a CD to the top of the motor (carefully ensuring that it’s centered) such that the CD spins on the motor’s axle. Then I took three easter egg halves, cut slits in their sides (see Figure 3) using a Dremel tool, and glued them in place on the CD by slipping the slits over the edge of the CD. You’ll want to make sure that the eggs are distributed evenly around the CD so that the system stays balanced. I recommend using the larger size of plastic easter eggs. Those that are the size of real eggs don’t work as well as the larger ones.

Of course, feel free to use a design of your own choosing when attaching the easter eggs to the motor if you’d like. The only important thing here is that the anemometer must spin at a speed approximately proportional to the wind speed. One thing done in the original article was to glue a fourth easter egg half over the top of the motor to seal it from the elements. I haven’t done that here yet but I probably will.

The motor has three pins for electrical connection. The center pin is ground, and the outside pins would be used to provide the driving signals when used as a motor. In our application, we’ll use the ground pin and only one of the outside pins (either one is fine). According to the original design, this motor will produce a 6-Hz sine wave when it is rotated at 1 RPM. 

Anemometer Signal Amplification

The amplitude of the signal coming out of the motor when it spins isn’t large enough for our PIC to be able to detect the signal, so I added a simple common-emitter amplifier circuit to bump up the voltage. I used the information in the “Hands-On Radio” article by H. Ward Silver, N0AX, from the February 2003 QST Magazine (pp.65-66), which worked quite well for my purposes. For the record, here are the design parameters I used:

·         Voltage gain AV=10

·         Transistor b=200 for the 2N2222A

·         Quiescent collector current Icq=4 mA

·         Quiescent collector-emitter voltage Vceq=2.5 V

·         Supply current Vcc=5 V

·         Base-emitter voltage Vbe=0.7 V

If you work out the math given in the article, you arrive at resistors values of R1=20.3 kW, R2=4.6 kW, RC=570 W, and RE=57 W. I chose the standard resistor values of 22 kW, 4.7 kW, 680 W, and 27 W to use in my amplifier. N0AX’s article does a good job of explaining this amplifier and I won’t repeat the explanation here.

PIC Code for Counting Pulses

 The code added to our PIC for counting pulses is actually pretty simple and short. The GetWindSpeed subroutine is where the pulses are actually counted. This routine sets up a loop (actually two nested loops) that checks once per millisecond to see if the wind input (RB1) has changed value (gone from high to low or vice-versa). If it has, a 16-bit counter made up of the lo and hi registers is incremented, and the new value of the wind input is saved for the next check. The actual checking and saving is done in subroutine CountWind. GetWindSpeed counts pulses for a total of about 3 seconds, and the total count is saved in lo and hi as a sixteen bit word.

GetWindSpeed is called from one of two other subroutines: TellWindSpeed and TellWindSpeedCW. TellWindSpeed is called from the main program loop when the PIC receives an ASCII “w” via its serial line. TellWindSpeed calls GetWindSpeed, and then calls SendAsciiNum to convert the 16-bit word in lo and hi to ASCII and return it to the PC as a five-digit string. After that, TellWindSpeed calls SendCRLF to send a carriage return and line feed (to go to the next line if you’re using something like Hyperterminal for debugging).

So, what the PC gets for wind speed is just a raw number indicating the number of transitions that occurred on the wind input line during the 3-second counting period. Since there are two transitions per complete sine wave, and the motor generates a 6 Hz signal at 1 RPM, you can divide the raw number by twelve to get the RPM of the motor if you’d like. Later we’ll use the raw number directly to develop a calibration between the anemometer output and true wind speed.

Calibration without a PC

 The original anemometer article explained how they calibrated it by mounting it on a vehicle and driving at set speeds while observing the anemometer output. This seems to me to be a simple and straightforward method, but in our case it would require a notebook PC to be used in the car. Knowing that not everyone has a notebook PC at their disposal, I decided to add some code to the PIC that would output the anemometer output on an LED using CW whenever a pushbutton is pressed. Since I already had some code from my Serial CW Sender project for doing so, it was only a matter of a few minutes before I had added the code and gotten it working. The LED is connected through a 1 kW resistor to RA0 (pin 17) of the PIC, such that when RA0 goes low, the LED lights. The pushbutton is connected to RB2 (pin 8), and RB2 is tied to +5 V using a 10 kW resistor, such that pressing the pushbutton grounds RB2, and releasing it causes RB2 to go high.

In the PIC code, TellWindSpeedCW is called whenever RB2 is low (meaning the pushbutton was pressed). TellWindSpeedCW calls GetWindSpeed, but instead of returning the anemometer output via the serial port, it calls SendCWAsciiNum to output the value in CW on the LED. SendCWAsciiNum behaves just like SendAsciiNum except that it calls SendCWChar for each digit to send. SendCWChar is a subroutine that takes the ASCII value in the CharToSend register and converts it into a stream of dits and dahs. It uses the ASCII value to look up the “CW value” in a lookup table named (appropriately) Table. Table is just a jump table, where the length of the jump is determined by the value in the W register, which is preloaded by SendCWChar. SendCWChar loads it with zero for the “0” character, one for the “1” character, etc. When Table is called, this value is added to the current program counter to make execution shift to one of the “retlw” statements. “retlw” is just a “return” statement where the value following the “retlw” instruction is placed in the W register prior to the return.

The value returned to SendCWChar by Table stores the dit/dah values in the lowest five bits, with a one meaning a dah and a zero meaning a dit. SendCWChar just marches through the bits, sending dits and dahs by calling SendCWDit and SendCWDah, respectively. I restricted the allowed values for CW characters to just the digits zero through nine. If you’re interested in a more general capability, Go examine my Serial CW Sender PIC code (which also includes code to handle a paddle). You can see it at http://home.earthlink.net/~golog.

With the addition of the LED and the pushbutton, then, you can calibrate the anemometer without needing to use a PC. If you choose not to use this method, the LED and pushbutton can be omitted, but make sure to tie RB2 to +5 V with a 10 kW resistor.

Calibration

 As I mentioned previously, probably the easiest way to calibrate the anemometer is to mount it on your car or truck and record the raw anemometer output at various highway speeds. It’s important to do this on a calm day, or the wind will skew your values. What you should end up with is a table that shows the raw anemometer output for each speed at which it was measured. Once you have that, it’s easy to determine a simple formula to use in calculating MPH from any value of anemometer output.

I haven’t gotten this far with my own setup yet, but the original article indicates that the response of the anemometer should be linear with wind speed, such that a simple straight line can be drawn through the calibration points. This means that I should be able to convert the raw anemometer output to a wind speed in MPH using a formula like

 

where v is the wind speed in MPH, f is the raw anemometer output, and m and b are constants. Some of you will recognize that formula as being that of a straight line, with a slope of m and a y-intercept of b. In our case, b should be close to zero, and m can be found fairly easily by choosing two data points from your table of calibration data and using the following formula:

where v2 and f2 are the speed in MPH and raw anemometer output from one data point, and v1 and f1 are the speed in MPH and raw anemometer output from your other data point. It would be best to choose two data points that are at opposite ends of your calibration range.

Another method of obtaining m from your calibration data involves the use of a linear least squares fit to your data points. Many scientific calculators can do this for you. If you’d like this to be done but don’t know how, email your data to me and I’ll do it for you. In the mean time, a value of 0.2 or so for m will give you ballpark results.

Windows Software

 I’ve modified my Windows software so that it includes an output for wind speed, and so that you can enter wind speed calibration information (the values of m and b previously discussed) for obtaining accurate speeds. Figure 4 shows the new display that includes wind speed. Figure 5 shows the Settings dialog box where you enter values of m and b. Even if you haven’t taken any calibration data yet, you can test your anemometer with a fan just to see that the indicated wind speed increases when the anemometer spins faster. Enter a value of 0.2 for m and 0 for b and that should give you reasonable numbers for output. Then try changing the value of m to see how it affects the reported wind speed.

Next Time

 That’s all for this installment. Next time I’ll follow up with my own calibration experience, and then we’ll get started on another sensor for the stations (although I’m not sure which one yet). Here’s a homework assignment: I’ve been thinking for awhile now about how to design an easy-to-build rain gauge for our system. Obviously, it needs some sort of digital output. Commercial systems use a tipping bucket, where a bucket empties itself when it gets full, and the tipping action triggers a switch. I haven’t yet figured out how to homebrew the mechanical parts of such a device yet. Any ideas?

See you next time!

 73, Dave NK0E


Page last modified:  July 30, 2003

Copyright 2003 G. Heron, N2APB