What to expect
In this activity, you will assemble a weather meter for your weather station that measures wind speed and direction. Then, you will add this functionality to your smart weather station project!
Connections
Measuring the properties of wind is an essential part of any weather station. Once you have these components working, you’ll add them to the rest of your project.
Materials
Micro:bit #1 with the battery pack connected
Docked to Weather:bit board
Micro:bit #2
Docked to IAQ board
SparkFun Weather meter kit
Weather Station Test Base Build
Screwdriver
6 PVC pipes
3 PVC tee connectors
Instructions
Part 0: Pre-Assemble the “Weather Meter”
Build the base as shown by pushing the PVC pipes into the tee connectors. The “bottom” metal tube from the SparkFun kit should be pressed firmly into the tee.
2. Follow these instructions to assemble only the anemometer and wind vane. Stop before the section on mounting the rain gauge or final mounting/ wire routing, as you’ll work on these in a later activity.
3. Read the instructions carefully, making sure that the wind vane is connected to the anemometer, and the anemometer is connected to the weather:bit port labeled “WIND”. If you have trouble displaying your data in the next parts of the activity, make sure your wire connections are solid. You’ll hear and feel a satisfying CLICK! when the connector is in place.
4. From now on, make sure your micro:bit is docked in the weather:bit board.
Part 1: Wind Speed
When the anemometer spins in the wind (the mechanism with the three cups), a sensor produces a reading that represents miles per hour. It is not necessary to understand the inner workings of the sensor, but it might be helpful to understand how the value is presented, and how you can “round” it to a reasonable length. The following code demonstrates each of the ways the value can be displayed.
Create a new makecode project and name it “4.3.1 Wind Speed”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Make sure your micro:bit is docked in the weather:bit and add the weather:bit extension.
3. To use the “weather meter”, you need to include the ‘start wind monitoring’ block from the weather:bit extension. This should be in ‘on start’, as it only needs to be initialized once.
4. By default, the ‘wind speed’ variable is a floating-point type of number(a.k.a float). (An integer is a whole number without a decimal point, while a float is a number that can have a decimal point.) Add the following code, download it, and test your anemometer by gently spinning it with your hand. With the weather:bit connected to your computer, you are able to view the wind speed float value in the serial monitor. You should notice that it has a lot of decimal places!
5. If you apply the round block (found in the math blocks), what happens to the number? By default, Makecode rounds to the next nearest whole number (no decimal point). This is an integer value. This approach may be fine at times, but what if your wind speed is greater than zero, but less than .5? Modify your program as shown. Download and test your program again.
6. With a little math creativity, you can round to the nearest tenths place. Can you think of a way to do it? The steps for building this formula are shown below. Modify your program as shown.
Programming note: It can be a little tricky “nesting” the blocks and bubbles in just the right spot, but it is important to represent the formula correctly. Download and test your program again, making sure the result is what you expect.
roundFormula = (round(wind speed * 10)) / 10
Part 2: Wind Direction
If you look closely at the base of the wind vane, you’ll notice markings for north (N), south (S), east (E), and west (W). If/ when you take your weather station outside, you’ll need to manually position your weather station base so that the N (north) marking is facing real north. The wind vane uses a network of resistors to provide a sensor reading that is translated into the direction the wind vane "points". The resulting value is from which direction the wind is blowing. The technical inner workings here are not critical to understand for this activity, but it is important to mention because this design makes it easy to have a “bug” in your code. Intermediate directions (such as NE, SW, etc.) are not marked on the base but are accessible in the code. Note: Sometimes the wind vane is between a direction. In this case, the “bug” is that the output string value will show ‘???’ (representing an unknown direction – resistor – value). You’ll create a workaround later in this activity.
Create a new makecode project and name it “4.3.2 Wind Direction”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Make sure your micro:bit is docked in the weather:bit and add the weather:bit extension.
Create, download, and view the following code in your serial monitor.
Slowly rotate the wind vane to a new direction with your hand (no data will display without movement), pressing the ‘A’ button repeatedly to stream the wind direction over serial.
Programming note: Wind direction values are strings, so you’ll need to make sure that the bubble is for text values (string values always have quotes around the value). You should see something like this:
You may notice that sometimes the reading shows “???”. One way you could work around this is to check if the direction is “known” by only showing the values that are not “???”. Add the following code to your program and test it. What happens when the wind direction value is unknown now?
Programming note: The “=” with quotations in the text boxes must be used to avoid errors.
Finally, add the following code that uses a variable to store the “last known direction”. This way, if an unknown direction occurs, it will just hold/show the last direction.
Programming note: This code uses the created variable “lastKnownDirection”. You can create this variable by selecting the “Variables” tab and click the “Make a Variable…”.
Download the code to your micro:bit and test everything out and make sure it makes sense and is working!
Programing note: Notice that this block is a+b and not just b like the last one.
Part 3: Add wind speed and direction to your console
Duplicate the code from activity 4.2.1 named “4.2.1 TX Sensors”. From the Makecode dashboard, select view all (next to My Projects) to find your project. It may be helpful if you switch to list view and sort by name instead of grid view. Don’t delete your original program, just make a copy in case you need it later. Name the new program “4.3.3.1 TX w Wind”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Modify your program so that “wind monitoring” is enabled in the ‘On start’ block. (You'll need to add the weather:bit extension if it is not already added.)
Modify your program to include wind speed and direction. Since several sensors are sending data at once, a small delay can be added to help the program run more smoothly.
Programming note: If quotations are not included as shown in a block and it results in an error, a quotations block can be found in the “Text” tab.
4. Once you have the TX program (the one that is connected to the weather:bit), you’ll need to work on the RX program (a.k.a. Wireless console – the one that is on the IAQ board). Duplicate your program “4.2.2 RX Console”. Name the duplicated project “4.3.3.2 RX w Wind”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
5. Modify your code to include the wind speed and direction. To include wind speed, add another condition that looks for the key value of the anemometer reading, similar to the BME 280 sensors.
Since the wind direction is a string value, you’ll need to add it in a different way. Include the following block in your program.
Finally, since you are starting to get quite a few sensor readings and many lines updating on the OLED display all at once, there are a few things you can do to clean it up and help it run more smoothly. Add a “station# id” and modify the timestamp to display an abbreviated month/day and time as follows:
Finally, to “refresh the screen” (clear everything right before showing the incoming data), add the “clear display” block when a number is sent to the TX micro:bit.
Download, test, fix any bugs if necessary! A screenshot of the completed “4.3.3.2 RX w Wind” is included to help with troubleshooting.
Wrap-up
Congratulations! You now have a wireless weather station that includes wind speed and direction on your console.
What did you find surprising or challenging about this activity?
How did you overcome those challenges?
Bonus Challenge (optional): Using what you have learned so far, create a way to show 16 directions instead of 8. For example, if a direction is between N and NE, instead of ???, it is NNE.
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity
In the next activity, you will incorporate the rain gauge and UVA sensor.
Acknowledgments
Activities from this unit utilize the SparkFun micro:climate kit. Activities have been adapted and/or derived from https://learn.sparkfun.com/tutorials/microclimate-kit-experiment-guide
This project is intended for experimental and academic purposes only.