A fresh-cut tree is a traditional holiday decoration in many homes. It is essential to keep it supplied with fresh water. Wouldn’t it be nice to have an ornament that could help remind you to check the water under your tree?
This project is part of a series showing how computationally-enabled devices work in our daily lives. It uses a MakerBit to demonstrate how a simple water level detector might indicate a low water level with lights in a tree-shaped ornament. The steps we followed are shown below.
Caution: This is a demonstration of a concept, only. The assembly shown here is not designed or intended to prevent a real tree from going dry. Before you decide whether to use any water-level sensor with a real tree, you should read the safety notice below, in Step 6.
Step 1: Gather the Components
- Roger Wagner’s MakerBit+R
- micro:bit controller (The actual controller is included in the MakerBit+R starter kit. The plastic case accessory shown on the micro:bit is sold separately. For example, this link shows one sold at Amazon.)
- Ribbon cable (included)
- 9-volt battery connector (included)
- 9v Battery (included, but also easily available)
- Water sensor (Ours came in the Elegoo 37-Sensors kit. Available separately online.)
- 3 jumper wires with female contacts on both ends. (included)
- Some LEDs (included; shown in other photos, below)
Step 2: Hook Everything Up
A. MakerBit Connections
Push the micro:bit into the MakerBit. You will need the USB cable that comes with it to connect to your computer for programming purposes. After you program it, you can run the device just with the 9-volt battery.
Plug the mixed LED ribbon cable into the black socket header for LEDs 11-16.
Plug the 3-socket connector of three jumper wires onto the black, red, and white posts on the pin header, on the row labeled A0. Black is for GND (ground), red for +5v, and white for “signal”, which will be Analog pin 0).
It’s not time to connect the battery yet, but the second photo shows where it will go.
B. Connect the moisture sensor
The other ends of the wires need to go onto the three pins of the sensor in a specific way, as shown in the third photo. Connect the pin labeled “S” to the white post on the MakerBit. Connect the “+” pin to the red post. Finally, connect the “–” pin to the black post. We used wires the same color as the posts, to help keep good order.
C. Insert the LEDs into the ribbon cable
We’re using 4 lights: one red, one yellow, two green. Notice that each LED has two pins. One pin is shorter than the other. Pay attention to the short pin. It goes into the connector on the side that has the little triangle.
The code in this project uses four connectors in the middle of the cable, the ones for pins 11, 12, 13, and 14. Examine the labels by the black socket on the MakerBit, to see which pair of pins goes with each pin number. Then study the cable to see how the wires relate to the pins. Hint: the black-and-white pair connects to pin 12. The photos show which wires to use.
The fifth photo shows everything hooked up and ready to go.
Step 3: Understand the Plan
The water sensor in this project has a web of electrical contacts that are all kept just slightly apart from each other. When dry, it’s like an open switch. When wet, the water conducts electricity between the contacts. The deeper it gets, the more contacts become wet and able to conduct electricity. In this way, the sensor can indicate the water level as a resistance to the flow of electricity that increases or decreases as the depth changes. There is some simple additional circuitry on the sensor that amplifies the sensitivity of the detector to moisture, and reports the amount of moisture to the analog pin of the micro:bit (through the MakerBit) as a number.
Zero means the sensor is dry, that is, has the greatest resistance. A number greater than zero means the sensor detects water. The deeper the water, the greater the number. We turn lights on as the number increases, and turn them off as the number decreases.
Our tests showed that the sensor reading increases and decreases as expected in response to changes in the water level. It becomes more sensitive when the water drops low and very clearly indicates when it is dry. That supplies enough information to form a general idea of the water situation. We would not rely on this sensor to measure a deep water level precisely. Thankfully, we don’t need to know the exact depth for our purposes.
A simple display with four LEDs can tell us when the tree might need more water. Ours has a red LED at the base, then a yellow one, topped by two green ones. The plan is to turn these lights on and off as the water level under the tree goes up and down. Green indicates water is present. Yellow suggests low water. Red means dry.
Step 4: Build the Display
This part is left up to your imagination. We will show what we did. You could use an old greeting card or just about anything.
Cut out a little tree and poke holes to hold the four LEDs. Push the LED through from behind the ornament, but not all the way through, just up to the lip on the base of the LED. Hold the LEDs in place with a bit of tape on the back. See this link for helpful details on how to install LEDs.
Step 5: The Code
The MakeCode online block-style editor works very well for this project. The picture shows a screenshot of the code.
You can open the editor in a browser window, with the code already loaded ready for editing, using this link: https://makecode.microbit.org/#pub:_H5h9T7KasE46.
What does the code do?
In the Start section, it tells the micro:bit to not use its built-in LED display. This instruction frees up the digital pins for us to use in our project. Then it turns the red LED on (pin 11) while turning the other three LEDs off.
In the Forever section, it reads the numeric value coming from the sensor on pin 0. Then a series of “If… Then” blocks compares this value to (somewhat arbitrary) constants we determined experimentally by dipping the sensor in and out of water. Feel free to experiment further with different values for these constants.
As the sensor value gets larger, the program turns on more of the LEDs. As the value gets smaller, it turns them off.
It is good coding practice to include a pause block in a forever loop. The pause allows the micro:bit an opportunity to work on other things for a short time. This code pauses for 1,000 milliseconds, equal to one second, which means we are checking the water level 60 times a minute.
Use the MakeCode editor to compile the code, then upload it to the MakerBit. This link connects to the official guide for how to do that. https://www.microbit.org/guide/quick/.
Step 6: Check It Out!!!
Connect the battery to the MakerBit and put the sensor into some water. Be careful to put only the end with the metal strips in the water. Keep the electronic components dry at the end where the wires connect.
READ THIS SAFETY NOTICE:
A dry tree is a fire hazard. It can catch fire and burn your house down. You should not rely solely on a water-level sensor to decide when your tree needs water. The assembly described in this article is for illustrative purposes only, intended to show how water-level sensors might function in everyday use. However, devices like this one cannot protect a tree against going dry. You will still need to check your tree visually and maintain a safe lookout at all times to ensure your tree has the water it needs.
Position the sensor in the reservoir under your tree and set the display where you can see it. When you regularly check your tree, notice how the LEDs change as the water level changes. The information can help you learn how sensors work, and may help to remind you to check the water under your tree.
Step 7: For Educators: STEAM Challenges and Suggested Standards
Maker challenge: extend the wires going to the display, so you could actually hang it higher up in a real tree.
Tool challenge: get to know your MakerBit! You can connect LEDs to any of the MakeBit’s digital pins using the sockets and cable attached to the black box connector of the MakerBit. This example used numbers 11 through 14. Can you change the setup and the coding to use different pins, say, numbers 5 through 8?
Science challenge: Investigate the behavior of the sensor. Do the following experiments.
- Dry the sensor thoroughly, then insert it into water in measured steps, for example one millimeter at a time. Record the depth at which each light turns on.
- Dry the sensor thouroughly again. Then plunge it into water up to near the top of the metal stripes. Withdraw it in measured steps, such as one millimeter at a time. Record the depth at which each light turns off.
- Assess the data you collected. Do the lights respond to the same water level in both directions? If the numbers do not match, make a list of possible explanations for the behavior you observe.
Math challenge: Calculate the number of milliseconds you would need to put in the pause block in order to check the water just once per minute, or once per hour.
Engineering challenge: Think of different ways this device could be used. Would a difference in the readings resulting from the immersion direction matter in the actual application of this device? Why or why not?
Tech challenge: the round plug on the MakerBit allows you to connect a direct current power source of anywhere from six to twelve volts. The little nine-volt battery might not last a long time. What other power source could you connect to keep the water sensor running continuously?
Coding challenge: how would you change the code so only one LED lights up: green, yellow, or red depending on the water level? How does the display behavior change if you change the constants in the code?
Art challenge: decorate the display ornament, or design something else that looks completely different! The test of a good display design is that it makes the information obvious.
NGSS (Next Generation Science Standards)
4-PS3-4. Apply scientific ideas to design, test, and refine a device that converts energy from one form to another.
4a Students know and use a deliberate design process for generating ideas, testing theories, creating innovative artifacts or solving authentic problems.
5b Students collect data or identify relevant data sets, use digital tools to analyze them, and represent data in various ways to facilitate problem-solving and decision-making.