[No.14] Never Miss Watering with a Moisture Warning Panel!

Programming and Making

Do you like growing plants? Plants like cactuses only need water once in a while, so it's easy to think "I'll do it later"... and then forget until the plant dries out. If the plant could tell you "Time for some water, please!", you'd feel too bad to forget... Is there a way to make that happen? This is the perfect time to invent something with SPACEBLOCK! Let's build a device that reminds you to water by showing a face when the soil gets too dry. You'll use the "soil moisture sensor module."

Elementary School ~ Intermed. 45 min
Here's the device you'll build!

What You Need & Getting Ready

Top row, from left: SPACEBLOCK Standard Package, soil moisture sensor module. Bottom row, from left: 8×8 RGB LED matrix panel, jumper wires

Connect the Expansion Parts to SPACEBLOCK

First, let's connect the LED panel and the soil moisture sensor to SPACEBLOCK.
The whole setup

Check the next picture for the details. Make sure you know where to plug in the 3 jumper wires coming from the "G," "V" and "S" pins of the soil moisture sensor.

Watch the pin socket positions when you connect

What Is a Soil Moisture Sensor?

A soil moisture sensor can measure how much water is in the soil.With no water the value is 0, and the more water there is, the bigger the number gets. Sending an amount or size to a program as a number like this is called analog input.

The soil moisture sensor raises or lowers the voltage on the pin it's plugged into on SPACEBLOCK, depending on how much water it measures. That voltage is turned into a number from 0 to 1023 and passed to the program.

The smaller the value, the less water is in the soil

Check the Soil Moisture Sensor Values

To use the soil moisture sensor value in a program, use the [Read analog voltage of (A0)] block in the "Input" category. Combine it with [Repeat] and [Show number (0)] and build the program shown in the next picture.
Run this program and the soil moisture values keep appearing in the console

When you run the program, the value measured by the soil moisture sensor appears in the console.When the silver sensor part isn't touching anything, the value is "0." But even just pinching it with your fingers makes it detect moisture, and the number goes up. Try pinching it with a wet tissue and see how the number changes.

Pinching the sensor with fingers gives a value of about 10 to 20
Caution!
Be careful not to get water on anything except the silver part of the soil moisture sensor. Keep water away from the SPACEBLOCK board and the wires, too.Water can cause damage or even a fire. Wrap insulating tape around any part that might get wet so you can use it safely. Vinyl tape works, but butyl rubber tape, which is also very waterproof, sticks to itself instead of using glue, so it's easy and handy to use.

Change the LED Panel Display Depending on How Dry the Soil Is!

Now that you know how to use the soil moisture sensor, let's build a warning system with the LED panel.

Create a variable

Create a new variable and name it "water."

Create the variable "water"
Combine the [Repeat] block and the [Number set (variable name) to ( )] block, and put the soil moisture sensor value into the variable "water".
Put the soil moisture sensor value into the variable "water"

Split the program by conditions

Next, make the program that switches the LED display. We'll show a gentle warning when the soil starts to dry, and a strong warning when it's very dry. To decide which values should trigger the warnings, actually stick the soil moisture sensor into a flowerpot and check how much the number changes with the condition of the soil.

Checking values with the soil moisture sensor in a flowerpot

Here are some reference values.

[Reference values]

  • 0–300: dry soil
  • 300–700: damp soil
  • 700–950: in water

This time, we'll show the first warning when the soil moisture sensor value goes below 500, and the second warning when it goes below 300. As shown in the next picture, use the [if ( ) then … else …] block and the [(0) (=) (0)] block to show the LED panel in 3 different ways depending on the value.

Branch into 3 cases depending on the soil sensor value

Choose what the LED panel shows

Add LED panel blocks inside the [if ( ) then … else …] block, and the program is finished as shown in the next picture.The plan is to show faces on the LED panel so you feel for your plant!

A program that changes the LED panel display based on the soil moisture sensor value

The program is done

That's it! Now a warning appears depending on how dry the soil is!

When the soil is moist enough, nothing happens...

QR code for project
A blue "Hey there!" face appears. The soil seems a little dry!

A red "I can't take it anymore!!" face appears. The plant has reached its limit! Water, quick!!!


Let's watch the video. Starting with the blue first-warning face, you can see the warning disappear once you water the plant and the soil gets moist enough.
When the plant shows a face like this, you'll really feel like you need to water it!
Now you'll never forget to water again!!