Authors
Publication
Pub Details
Date
Pages
In the last issue’s “anemometer” article, I showed how to build a simple but effective (and cheap) device to tell how fast the wind blows. Now, I will carry on with plans for an equally important device to determine wind direction. This project, as all future “weather station” articles shall be, is intended to be added onto what has already been covered. It is my hope that by covering the CONCEPTS in this one specific application, you can adapt the same methods in your own completely different projects. So even if you’re not the least bit interested in monitoring the weather, perhaps you can obtain something of value for that robot you’re building to vacuum the house (now THERE is a marketable product!).
In very simple terms, what we will do in this project is build a weathervane, a very low tech device which has been around for hundreds of years. But we’ll add a new twist to this weathervane by hooking it up to the Universal I/O Port so the computer can monitor and record wind direction.
What You Will Need
In keeping with the tradition set in Part l, of using simple inexpensive commonly available parts, here is a list of most of the items you will need:
- 1 metal lid to a coffee can or similar small flat piece of metal
- 1 coat hanger
- 1 variable resistor (the volume control swiped from a junked radio or TV)
- length of hook-up wire
- 1 555 Timer Chip (Radio Shack)
- 1 .1uf capacitor
- 1 100 Kohm resistor
- 1 1 Kohm resistor
In addition, you will need some type of 8 bit parallel I/O port such as my Experimenter’s Universal Input/Output Port which is described in my Catalog.
The software presented here is designed to work with this port, however any port will do as long as you change the IN instructions to correspond to the address of the port you use.
General Principles
How do you take the twisting motion of-a weathervane and convert it into something meaningful to a computer? I tinkered with quite a few ideas before I struck upon the method shown here. I started by building an array of 4 electrical contacts (one for each compass point) which were configured in a circle around a rotating vane. On the vane, I attached metal brushes which would close a circuit which was then fed into the input port. Depending on which circuit was closed at any given time, I could tell which way the vane was pointing. I arranged the brushes and the contacts they touched in such a way that four contacts could even determine Northeast, Southeast, etc as well as just N, S, E, or W. If the brushes closed just one circuit, I knew that the wind was coming from one of the 4 main compass points. However, if the circuit representing East was closed, and at the same time, the North circuit was closed too, I knew that the wind was coming from the Northeast. I spent a lot of time trying to perfect this method, but I ran into enormous problems.
First, the brushes and contacts were exposed to the weather. I live in an area where rain can reach the acidity of orange juice. Any metal objects left in the elements corrode terribly. Such corrosion on the brushes would make it stop working after every storm. Also, the alignment of the brushes and the contacts must be very precise. Both the tension of the brushes and the location of the contacts had to fit within very close tolerances. While it was possible to build the assembly if great care was exercised, a strong gust of wind could knock the delicate arrangement out of alignment. Another disadvantage which I was not pleased with was the fact that each of the four contacts would require one bit of the input port. On the face of it, this doesn’t seem like a big sacrifice. But four bits is four bits. Someday, we might wish we had them to use for something else. As I worked on one failure after another following the “brush/contact” tack, I kept thinking there had to be a better way.
What finally emerged was a completely different approach which eliminates the delicate, tedious to build brushes entirely. Instead, a variable resistor, the same thing used as the volume control in a TV set or radio, is altered slightly so it can be turned a full 360 degrees. The wind vane is mounted onto the shaft where the knob used to go. When this assembly is mounted out on a mast, the wind will turn the resistor’s “wiper” resulting in a unique resistance which varies as the wind direction changes. What is more it is very easy to mount and still provide protection from the elements.
The varying electrical resistance produced by the wind is fed into an oscillator circuit.
This produces a series of digital pulses whose frequency varies as the resistance varies. Therefore, in exactly the same way that digital pulses were read in last issue’s anemometer circuit to determine relative wind velocity, the digital pulses produced by the oscillator, and governed by the wind vane, are read by the computer to determine wind direction. In fact, only four bytes of additional machine code are needed to make the wind speed software from the last issue also work to determine wind direction! And to make it even better, only one precious bit of the I/O Port is used, so we have oodles of unused bits waiting for future projects.
Now the Specifics
Phase | of building the computerized weathervane consists of obtaining a fairly high resistance variable resistor, also called a potentiometer, and performing some minor surgery on it so its shaft can turn a full 360 degree circle. You can pull one of these pots off an old TV or radio, or you can buy a new one from your friendly local Radio Shack dealer. What you want is one with a fairly long metal shaft, and one which has a total resistance of 500 Kohms to 1 megohm. The exact value is not critical. The resistor I used had a resistance of 679 Kohms which was measured between the two outside pins of the resistor.
Before you open the resistor up, look at the metal housing and notice that directly behind the center pin, there is a small slot where the case was punched inward (see diagram).
This is a stop which.the innards of the resistor hit against if you try to turn the shaft too far. Since our purposes require that the resistor be able to turn in a full circle, we must remove this stop. To do it, use a small screw driver to bend back the metal tabs which hold the cover on. Then carefully remove it. With a hammer, punch, screw driver, pliers, and whatever else is necessary, beat away at the stop from the inside until you have either flattened it or removed it entirely. It doesn’t really matter how you do it so long as the stop is removed to the point where the inside wiper can freely turn past it when the cover is put back on. I had very good luck just squeezing with heavy pliers until the stop was flattened.
While the variable resistor is apart, you can see that it consists of a rotor assembly with 2 brushes which slide along a black carbon material. This carbon is what creates the electrical resistance. Each end of the carbon is connected to an outside lug of the three connectors to the resistor while the center pin is hooked to a small metal ring which hits the rotor. If you try to turn the rotor at this point, you’ll see that the brushes on the rotor get stuck on this ring as they pass it. Therefore, it is necessary to try to move the obstructing arm out of the way. It is very easy to do. Pull the rotor completely out of its hole so that the ring is in plain sight. Then with a screw driver, press down on the arm leading to the center lug right where the arm joins the ring. With your fingers or needle nose pliers, grasp the ring and bend it upward slightly so that you bend the arm right where the screw driver is holding it.
Increasing the bend at this point will cause the arm to be squeezed down lower (and out of the way of the brushes) when the pot is reassembled. Put everything back together now and try turning the shaft a full 360 degrees. You will feel a slight drag as the brushes on the rotor cross the arm. This is unavoidable. What you should aim for is the smoothest turn past the arm you can get. If you’re not satisfied, try bending the ring a tiny bit more.
Phase 2: Building the Weathervane
Now find a piece of narrow board such a 1 x 3 about 2 feet long. At one end drill a 3/8 inch diameter hole and turn the threaded part of the modified variable resistor into it. You may also want to gob a small amount of epoxy onto the resistor where it contacts the wood. This will prevent the weathervane from flying apart in a gale. The metal shaft should extend through the hole and out the other side of the board. Place the plastic knob back on the end of the shaft, and leave plenty of space so it does not drag on the wood. Now cut up the coat hanger and fashion it so one end fits tightly around the knob without slipping. Exactly how you do this depends a lot on the shape of the knob. If the one you use is round and offers nothing to “grab onto” so as to prevent the wire from slipping, you might want to drill a hole in the knob to pass the coat hanger wire through. Be inventive. If all else fails, use more epoxy to hold it tight. Bend the other end of the coat hanger paper clip fashion so that you can slip the coffee can lid down into it. Make sure you have a tight fit. Later, after everything tests out ok, you will want to epoxy this in place as well, but don’t do it yet. You may need to replace the vane with something larger to make it more sensitive to small puffs of wind.
At this point, the weathervane is finished. It should look something like the picture shown here. Different circumstances, however, will result in slightly different appearances. Do not be afraid to release your own creative genius on your own design. At any rate, the vane must now be set out in a light breeze to see how easily it turns. Ideally, the vane should turn even in a very light breeze. If it does not, check the resistor shaft and the coat hanger wire. Free them if they are dragging against the wood base. Another way to increase the vane’s sensitivity is to increase the area of the vane. Use a larger piece of metal if necessary, or lengthen the distance to the resistor by using a longer piece of coat hanger. Remember, however, that the more weight you add, the more drag there will be, so use the lightest materials you can find. Once you’re happy with the assembly, glue or screw the vane securely to the coat hanger.
Phase 3: Building the Oscillator Circuit
This part covers construction of the electronic circuitry which generates the digital pulses which are read by the computer. The schematic diagram shows how to wire up the very common 555 timer chip so it will output a frequency which varies as the variable resistor turns in the wind. To connect this resistor to the chip, use a long length of light weight speaker wire. This can be obtained in spools from Radio Shack or a HI-FI dealer. Solder one lead to the center lug of the resistor, and the other lead to either one of the other two lugs. It doesn’t matter which. Power the 555 chip using the 5 volts supplied by your computer. If you build this circuit on the same board as the LM339 circuit used by the anemometer, you can simply extend the +5vdc and ground connections over to the 555. The output of the timer comes from pin 3. It is this pin which you want to connect to Dl of the Input port.
To check for proper operation and also to help understand what this circuitry does, wire everything up and temporarily connect an earphone between pin 3 and the ground. You will be able to actually hear the tone produced by the 555. By moving the weathervane to a different position, you’ll hear the tone change. This is the signal which is fed into the computer through the input port. The program which reads the port, determines the frequency and prints the corresponding direction on the screen.
Phase 4: Now the Software
With the timer built, the weathervane constructed, and everything wired up to the computer, enter or load the program listing for the anemometer given in Updates Vol. 3, No. 1 (page 10, or 12 depending on which computer you use). Once its in, alter line 10 so it appears exactly as it does below. This alteration, makes it possible to use the same machine code for determining both wind speed and wind direction.
Add the lines on the next page to the Basic. They translate the frequency received into the more meaningful points of the compass and have been written so as to work equally well in both the TS1000 and 2068.
For TS2068
10 LET a$=CHR$ 1+CHR$ 0+CHR$ 0+CHR$ 118+CHR$ 62+CHR$ 195+CHR$ 50+CHR$ 120+CHR $92+CHR$ 219+CHR$ 207+CHR$ 230+CHR$ 1+CHR$ 95+CHR$ 58+CHR$ 120+CHR$ 92+CHR$ 254+CHR$ 0+CHR$ 200+CHR$ 219+CHR$ 207+CHR$ 230+CHR$ 1+CHR$ 187+CHR$ 40+CHR$ 243+CHR$ 3+CHR$ 24+CHR$ 239
For TS 1000
10 LET A$=CHR$ 1+CHR$ 0+CHR$ 0+CHR$ 118+CHR$ 62+CHR$ 60+CHR$ 50+CHR$ 52+CHR$ 64+CHR$ 219+CHR$ 223+CHR$ 230+CHR$ 1+CHR$ 95+CHR$ 58+CHR$ 52+CHR$ 64+CHR$ 254+CHR$ 0+CHR$ 200+CHR$ 219+CHR$ 223+CHR$ 230+CHR$ 1+CHR$ 187+CHR$ 40+CHR$ 243+CHR$ 3+CHR$ 24+CHR$ 239
For TS1000 and TS2068
95 IF X>64 THEN LET X=64
115 GO SUB 6000
116 PRINT AT 6,0;"DIRECTION:";D$;" "
117 PRINT AT 7,0;DIR;" "
6000 REM DIRECTION SUBROUTINE
6002 LET MASK=2
6004 LET A$(13)=CHR$ MASK
6006 LET A$(24)=CHR$ MASK
6010 LET DIR=USR WIND
6011 LET MASK=1
6012 LET A$(13)=CHR$ MASK
6014 LET A$(24)=CHR$ MASK
6015 IF DIR<=58 THEN GO TO 6100
6020 IF DIR<=65 THEN GO TO 6110
6025 IF DIR<=85 THEN GO TO 6120
6030 IF DIR<=105 THEN GO TO 6130
6035 IF DIR<=155 THEN GO TO 6140
6040 IF DIR<=225 THEN GO TO 6150
6045 IF DIR<=400 THEN GO TO 6160
6050 LET D$="NW"
6055 RETURN
6100 LET D$="N"
6105 RETURN
6110 LET D$="NE"
6115 RETURN
6120 LET D$="E"
6125 RETURN
6130 LET D$="SE"
6135 RETURN
6140 LET D$="S"
6145 RETURN
6150 LET D$="SW"
6155 RETURN
6160 LET D$="W"
6165 RETURN
How Does the Software Work?
You will recall from the last issue that the function of the short machine code, USR WIND, is to monitor the input port and and determine how many transitions from low to high occur in one second’s time. In other words, it determines frequency. The four previously mentioned bytes which are added this time do not alter this. Their job is to allow the computer to look at the pulses coming in at just one individual bit of the port at a time.
In this way, we can have a frequency coming in at bit 0 from the spinning anemometer, and another frequency at bit 1 from the weathervane. The computer can use the same machine code to monitor both, and we still have 6 more bits of the port for future uses.
The disassembly here shows USR WIND. If you compare it with that found in the last issue of Updates, you’ll see that the difference is that after every IN instruction, there is inserted an AND 01.
BGIN LD BC,0000
HALT
LDA A,3C
LD (FRAM),A
IN A,(DF)
AND 01
STOR LD E,A
CNT_ LD A,(FRAM)
CP 00
RET Z
SMPL IN A,(DF)
AND 01
CP E
JR Z,CNT_
INC BC
JR STOR
Using AND in this way is a very useful technique for “masking”, or ignoring, unwanted bits of a number. What happens with the AND instruction is this: The computer matches each bit in the accumulator with the corresponding bit of the number following the AND instruction. If both bits are 1, the computer keeps the | in the given bit of the accumulator. But if one of the bits is 0, the computer loads a 0 into that bit of the accumulator.
Therefore, we can input a value from the port which may have any number of bits set to 1. If we don’t care about the state of any of the bits except bit 0, we could use AND 01 to turn all the bits in the accumulator to 0 except the right most bit. If we want to look only at bit 1 (the next bit to the left), we could use AND 2 which in binary is 00000010. Here, every bit will be reduced to 0 except bit 1.
Quiz time: True/false- You would use the AND 03 instruction to mask all bits except bit 2 (the third from the right.)
Answer: False. AND 03 or binary 00000011 would mask all bits except bits 0 and 1. Bit 3 would be forced to 0.
When the computer is determining wind velocity, it wants to look at bit 0 so AND 01 is used. When it determines wind direction, it wants to ignore bit 0 and look only at bit 1 since that is where we are feeding the tone. Lines 6002 to 6006 change the AND 01 into AND 02 to accomplish this. It is the 13th and 24th characters of A$ which store the number to be ANDED with the accumulator. We simply use LET statements to alter the machine code in A$ accordingly.
Note that lines 6011 to 6012 change A$ back to the original AND 01 instruction so that when the subroutine returns, the computer will look at the right bit when it determines wind speed again.
Converting a Tone Into a Compass Point
After the computer obtains the frequency produced by the timer (lines 6000 to 6014), it must next translate that frequency into a point on a compass. This is done by lines 6015 to 6045 in a straightforward manner. Line 6015 says:
IF DIR<=58 THEN GOTO 6100
In English, this means, “If the tone has a frequency of 58 or less, execute the program lines starting at 6100. This is where the computer assigns the first possible compass point, “N” or “North” to D$.
If the frequency is greater than 58, line 6020 considers the next possible frequency range and if it falls between 59 and 65, D$ is assigned the value “NE”. The computer simply plays the game, “if you see this, print that” when it decides which direction to assign to D$. “If the tone is within this range, make D$ equal that compass point.”
The values shown in lines 6015 to 6045, of 58, 65, 85, 105, 155 225, and 400 are values I obtained when I calibrated my weathervane. They will not be the same for you because the the components you use in the 555 timer circuit as well as the way you position your weathervane can result in a totally different frequency. Through trial and error, you must determine the proper values for these program lines based on the way your weathervane is configured.
This calibration can be done fairly easily. Before you actually mount the weathervane high on a mast, set it within easy reach, but point the board in the same direction it will go when it is fastened to the mast. Using a compass, mark out the 8 compass points on the board, and then turn the vane arm so it is pointing North by Northeast. Run the program and note the number which is printed just below the line which says “DIRECTION:”. This number is the value you want to stick in line 6015 in place of the 58 that I used.
Next, swing the arm so it points East by Northeast and run the program again. The number printed on the screen replaces the 65 I used in 6020. Again, point the vane to East by Southeast. Run the program and use the number displayed to replace the 85 in line 6025. By going through the remainder of the compass points, you can fill in the proper values for 6030 to 6045.
On the surface, this calibration process seems very simple, but two complications can arise which can prove to be troublesome. They both have to do with the nature of the modified variable resistor used to govern the tone frequency. If you hook up an earphone and listen to the tone change as you sweep the vane around in a circle, you will hear the tone gradually increase until it reaches a maximum. Then, as you continue the sweep, the tone instantly drops to the lowest frequency and gradually begins its upward climb again. Depending on the alignment of the vane assembly, it is possible that the lowest frequency and the highest frequency both represent the same compass point. If this happens to you, there are two things you can do: 1. re-align the vane assembly to eliminate this situation, or 2. program the computer to handle it. I chose option 1 but programming around the problem is not too difficult. You would simply add to the affected program line like so:
IF DIR > nn OR DIR<= xx THEN GOTO yy
In this line “nn” would be some value just less than the maximum tone. “xx” would be the low frequency cut-off point, and “yy” is the proper program line to go to.
The second complication which can crop up stems from the fact that our “modified” resistor is being made to do something it was never intended to do. That is, swing around in a full circle. I suspect that different resistors will produce different results, but every one that I used had an area where the vane could turn without changing the tone frequency. In a “bad” resistor, this area could cover an arc of as much as 45 degrees. “Better” resistors were substantially less. Again, depending on the alignment of the entire weathervane, you could find that this “dead area” coincides precisely with a major compass point. The only solution I could come up with was to carefully align the vane so that the dead area was between compass points rather than smack dab on top of one. For most hobbyists, aligning the vane will not pose too much of a problem. But, those of you who really get into this project and want to improve “resolution” to much more precise compass points beyond the 8 major directions, will want to find a variable resistor capable of rotating the full 360 degrees. I understand that such resistors are manufactured, but they are not common and you’ll have to dig deeper than a Radio Shack store to find it. If anyone finds a source for these devices, please let me know and I’ll pass the word along.
Final Points
After you have written the software, built the hardware, and worked out all the bugs, congratulate yourself for being so tenacious.
The final phase has come. Now it is time to mount the weathervane on the mast along with the anemometer you built. Use angle brackets and screws to position the weathervane just below the wind cups, bearing in mind that you must keep the board which supports the resistor and vane pointing in the same direction that it was when you calibrated the system. One very good way to insure that this will be the case is to first place your compass on the board and note its degree heading during the calibration process. Then, mount the weather vane on supports as illustrated using just one screw to hold it in place. Put the compass back on the board and rotate the assembly until it is in exactly the same position it was for calibration. Then fasten the board tight using more screws. Be sure that the vane arm will clear the mast as it twists in the breeze.
Now you’re fully outfitted with a digital computerized recording anemometer and wind direction indicator. You could have bought one of equal value for $300 to $600. Instead you got by with a $70 port board, a cheap computer, and about $1200 worth of your time. But it was great fun wasn’t it? Stay tuned to future Updates articles which will add more weather monitoring capabilities. If you think of something to add yourself, let us all know about it.