Piper Make: Soil Sensor Real-World Application
A few years ago, I designed the Piper Make soil sensor kit in a way that students could put together themselves and collect useful, real-world data.
While the kits have always worked well in a classroom setting for STEM activities, science labs, etc., we wanted to see just how long our sensors would last in real-world conditions.
All soil sensors eventually degrade to the point where they stop working – even the expensive professional ones. Soil sensors are used in outdoor and/or wet conditions in soil, and soil contains minerals that are corrosive to the metal parts of the sensor.
Building the Sensors
I built all four of my sensors according to the blueprint in the Piper Make Soil Sensor kit. I made sure to go slowly and carefully, making sure that there were no creases or folds in the copper tape and the vinyl sticker. The biggest “enemy” of the sensors is water getting into any part where there is metal, so it’s important for the copper tape to stay dry and protected.
One of the things I discovered I could do was actually solder the resistor and longer wires to each sensor as well. Normally, you use the included alligator clips to grab onto the exposed copper at the top, but I wanted something more permanent.
The 1MΩ resistor is soldered on to the copper strips along with the wires. This isn’t entirely necessary, but it makes the sensors a little more robust.
Building the Circuit
There are enough GPIO pins on the Raspberry Pi Pico to connect 12 LEDs, 4 sensors, and 1 buzzer. It’s more parts than what comes in a single starter or base kit, but I really wanted a “red-yellow-green" style indicator for each plant.
Here are the connections (each LED is in series with a 330Ω resistor):
Plant 1:
- Green LED: GPIO 5
- Yellow LED: GPIO 6
- Red LED: GPIO 7
- Soil Sensor: GPIO 0
Plant 2:
- Green LED: GPIO 8
- Yellow LED: GPIO 9
- Red LED: GPIO 10
- Soil Sensor: GPIO 1
Plant 3:
- Green LED: GPIO 11
- Yellow LED: GPIO 12
- Red LED: GPIO 13
- Soil Sensor: GPIO 2
Plant 4:
- Green LED: GPIO 14
- Yellow LED: GPIO 15
- Red LED: GPIO 22
- Soil Sensor: GPIO 3
Buzzer (optional - from the Piper Computer Kit):
- GPIO 4
Since the 1MΩ resistors are soldered to the sensors, I didn’t have to worry about them, but if you’re using the sensors as they come in the kits, just make sure to connect one leg of the resistor to the same GPIO pin that the sensor is connected to, and the other leg (and the other sensor wire) to ground.
Writing the Code
There are a few things that are different about my code versus what the tutorial for the sensor shows. The first is that my code is designed to monitor the sensors for a very long period of time. If you connect the sensors to the graph on Piper Make, you only want to send data to the graph about every 30 seconds, or even every minute at the most.
You can simply use a wait block to do this – but the problem with that block is that the sensors don’t collect any data while it’s waiting.
Instead, I used a repeat for __ seconds block. This lets the Pico collect data for a set amount of time, then exit the loop to graph it, then go back and do it again.
If you have a soil sensor, give this a try!
Collecting More Samples
If you have ever used sensors for data collection, you’ve probably noticed that they can be “noisy” - the data can bounce around a bit. This is where things like averages can be helpful to “smooth” out the data.
I like to use a technique called a low-pass filter to help smooth out the data coming from the soil sensor (or any other kind of sensor). This involves giving past sensor readings more “weight” and then averaging that with the current sensor reading.
Doing this can help "smooth out” your data so that you can see trends. The code looks like this:
Calibrating the Sensors
Once the smoothing is in place, the next job is to calibrate them. These sensors are all hand-built and soil can be variable, so it’s necessary to calibrate each sensor.
Calibrating is simply trying to find the sensors low (dry) value and its high (wet) value.
It’s important to start with soil that is as dry as you are willing to let it get. I actually had to wait a week and a half to let my houseplant’s soil dry out in order to collect the dry value for each sensor. Then, I fully watered each plant and collected each sensor’s wet value.
I did a little math to figure out what level the red, yellow, or green LED should be on, and then used some if-else blocks to set those values. Essentially, I wanted the LEDs to stay green until the plants were 50% wet / 50% dry. Then turn yellow below that. Once the plant is 20% wet / 80% dry, turn on the red LED.
If you'd like to see more of the coding or formulas I used for this project, please email me at matt@playpiper.com and I'd be happy to share them!
About the Author
Matthew Matz is an educator, product designer, and self-proclaimed "enginerd." He has worked as a science and engineering teacher and as a school principal in Oregon. He currently works on designing and building the hardware and software that goes into each Piper Make kit.