4.4
Rain and Sun
Rain and Sun
What to expect
In this activity, you will install and configure an Ultraviolet type-A (UVA) . There is also UVB, UVA is the more common of the two so that's the one we measure. sensor to measure radiation from sunlight. Next, you will install and configure a “tipping bucket rain gauge” (TPRG) to measure rainfall over time. Finally, you will add these elements to your wireless smart weather station console.
Connections
You’ll continue to explore and build your smart wireless weather station.
Materials
1 micro:bit for TX with the battery pack connected
Docked to weather:bit board
1 SparkFun Gator:UV sensor (includes wiring harness)
1 micro:bit for RX
Docked to the IAQ board
Rain bucket from SparkFun kit
Instructions
Part 1 of 3: UV Sensor
UV is an important part of climate monitoring in part because it can adversely affect your health. Check this out to learn what UV is, how it is measured and reported, how it affects us, and what can be done to avoid the risks of exposure.
Create a new makecode project and name it “4.4.1 UV Sensor”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Carefully connect the UV Sensor as shown. Notice the yellow wire is at the top and the red wire is at the bottom. The connector is designed to only fit one way, so don’t force it. Be gentle, but make sure it is fully connected. If you have to remove it for any reason, only grab the connector. Don’t pull on the wires!
3. Add the gator-UV extension to your program.
4. In the ‘On start’ block, initialize the UV sensor.
5. The UV sensor provides a reading that must be converted into an index value. (Table adapted from SparkFun.)
6. For testing purposes, you can create some logic like this, and experiment by moving the sensor close to the window, taking outside, shining a UV light on it (if you have one), or covering it up with your hand (a zero reading should report “no UVA reading”) in the serial monitor.
Programming note: “UVindex” is a created variable. You can create this in the “Variables” tab. If quotations are not included in the blocks they can be found in the “Text” tab.
Part 2 of 3: Rain Gauge
Rainfall can be measured by a tipping bucket rain gauge (a.k.a TBRG). Basically, there is a rocking switch inside the bucket that sends a signal to the micro:bit every time a certain amount of rain has been collected. The converted value and other programming have already been done for you and are part of the block found in the extension. According to the manufacturer, one ‘bucket tip’ trigger is approximately 0.011 (inches) of rain. This gauge and sensor are somewhat experimental, but we’ll add it to your project anyway, as it represents a common and important element of any weather station.
We won’t go too deep into the technical details in this activity, but check this out if you are curious about how rainfall is measured and the math behind the formulas.
Do not mount the rain gauge yet; instead, just plug it into the port on the weather:bit labeled RAIN. (You’ll mount it later after testing.) No other parts of the weather station need to be connected at this time.
2. Create a new makecode project and name it “4.4.1 Rain Gauge”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! Make sure that the weather:bit extension is added.
3. Create the following code and test it in your serial monitor by gently rocking the rain gauge side-to-side until you hear a light “thump”. This is the rocking switch inside. Each time it “thumps” represents a bucket tip of rainwater and should increase the reported value by approximately .022 in your serial monitor. If you are getting a different value, use this number in your code and it will be corrected in the next code block.
No water is needed at this time.
4. Once you have verified that you are getting a reading, modify your code to include a variable that counts the number of bucket tips, then calibrates the count value to the measurement provided by the manufacturer.
Programmer’s note: Currently, the only way to ‘reset’ your measurement is to reset the micro:bit (or when you download a new program). This is due to the limitations of the provided extension. You will see a workaround for this in a later activity.
Part 3 of 3: Adding UV and Rainfall to Your Weather Station Project
TX
To add UV and Rain to your weather station project, duplicate your last TX project “4.3.3.1 TX w Wind” and name it “4.4.3.1TX Wind, UV, Rain”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! This way you can keep a working example in your files while adding new functionality in a separate program. Add the following code to the “on start” block
2. One way to send your UV sensor data over radio is to create a numerical “key” code on the TX that can be decoded on the receiver RX. On the TX program, create a variable called “UVKey” and set it to a different number based on the UV index value (note: this does not need to match the UVI value, which is often used to describe the UV level. This is just for encoding/ decoding purposes when sending and receiving data.)
Since the logic is going to have several conditions, you can simplify programming by defining a function that can be called from another place in the program.
3. Since there are few steps to getting the rainfall value in inches from the sensor, define another function to handle converting rain bucket tips to inches of rain. Since the rain value is already a number, you don’t need to create a numerical key code as you did with UV.
Programmer’s note: You could also go back and do the same thing with wind direction if you wanted, but it is not required.
4. Call these functions after the wind direction in your code. Notice a brief pause is included here as well.
RX
5. Duplicate 4.3.3.2 RX w Wind” and name it “4.4.3.2 RX w UV and Rain”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! This way you can keep a working example in your files while adding new functionality in a separate program.
6. Defining a “decode” function for the UVKey and converting it to a string (text) can be useful here. Add the following code to your program.
7. Check for send values from rain and call the UV decode function in your program. Notice the UVKey variable is being set to the value coming from the TX before the decoder function is called.
Test everything out to make sure it works!
Going further ideas:
Determine and display the UVI-Values as well as the labels.
Use the built-in ZIP LEDs on the IAQ board or add an LED neopixel strip to show the suggested UVI color from the chart.
Wrap-up
Congratulations! You now have all the components of the outside weather station installed, configured, and displaying on the OLED.
What did you find most challenging about this activity?
Did you modify the code or do things differently? If so, how did it go?
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity
In the next activity, you will mount all of the components and make the project ready to go outside. You will also configure the IAQboard to capture and display indoor climate data.
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