Micro:bit Related ProductsJacdac SeriesJacdac Energy Practice KitCase 16: Smart Soil Moisture DeviceOn this pageCase 16: Smart Soil Moisture DeviceIntroductionUse the Jacdac soil moisture sensor to detect soil water content in real time. The Jacdac LED ring color and brightness visually indicate the soil moisture status: Red high brightness (100%) = soil is dry and urgently needs watering (moisture < 20); Blue medium brightness (80%) = soil is slightly dry (moisture 20–50); Green low brightness (60%) = soil is moist and suitable (moisture 50–70); LED off = soil is overly wet (moisture > 70). A simple three-color indicator so watering no longer relies on guesswork.Learning ObjectivesUnderstand multi-threshold graded judgment (if-elif-elif-else) — executing different actions based on which range a value falls into.Learn LED color coding — using the three colors red/blue/green to intuitively convey "dry/medium/wet" information.Explore the water-saving significance of precision irrigation in modern agriculture.Required MaterialsItemImageQuantitymicro:bit V21Jacdac Expansion Board1Jacdac 25cm Connector Cable2Jacdac Soil Moisture Sensor1Jacdac LED Ring1USB Cable1Sensor PrincipleSoil Moisture SensorThe Jacdac soil moisture sensor estimates water content by measuring the dielectric constant of the soil. Water molecules are polar; the higher the water content, the greater the soil's dielectric constant. The sensor converts this physical quantity into an analog numerical output.Moisture RangeSoil ConditionLED IndicationRecommendation0–20%DryRed LED, brightness 100%⚠️ Water urgently needed!20–50%Slightly dryBlue LED, brightness 80%💧 Can water moderately50–70%💚 MoistGreen LED, brightness 60%✅ Moisture suitable; no watering needed70+%💧 Overly wetLED off🛑 Stop watering; prevent root rotThe suitable moisture range for most plant root systems is between 50%–70%. Below 20%, water stress begins; above 80%, roots lack oxygen and may rot. Precisely controlling soil moisture is the most critical aspect of agricultural irrigation.Assembly StepsModel PrincipleSoil Moisture Sensor — The Plant's "Thirst Meter"In traditional farming, people insert a finger into the soil to judge wetness — it's crude and imprecise. The soil moisture sensor acts as the plant's "electronic thirst meter":Traditional MethodSensor MethodFinger test; subjective judgmentPrecise numerical value; objective quantificationCan only check a few times a day24/7 continuous monitoringCan only judge the surface layerCan measure moisture at root depthCannot record historyConnectable to IoT for long-term trackingThis case converts sensor readings into an intuitive three-color LED display — red stop (water shortage), green go (suitable), blue alert (slightly dry, needs attention) — as simple and easy to understand as a traffic light.Connection DiagramAs shown below, insert the micro:bit V2 board into the Jacdac expansion board, and use cables to connect the soil moisture sensor and LED ring to the Jacdac expansion board's edge connector.Programming SoftwareMicrosoft MakeCodeMakeCode ProgrammingStep 1: Adding the Jacdac ExtensionGo to Microsoft MakeCode and click "New Project".Enter a project name in the pop-up window and click "Create".Click "Extensions" in the code drawer.In the pop-up interface, type "Jacdac" and click the search icon, then select the Jacdac software library as shown.Step 2: Connecting the HardwareUse a USB cable to connect the micro:bit V2 board to the computer.Note: If this is the first time running a Jacdac program on the micro:bit V2, please pre-load a blank Jacdac program onto the board first. Otherwise, skip this step.Connect the sensor. MakeCode will automatically detect and simulate it in the simulator area, where sensor status is displayed in real time.Click "ADD BLOCKS" to add the sensor extension module.Note: When connecting a new sensor, repeat the "click 'ADD BLOCKS'" workflow once.Write the Program as ShownReference Program Linkhttps://makecode.microbit.org/_0JXiAC5rCeYdYou can also download the program directly from the webpage below. Once downloaded, you can start running the program.ResultInsert the soil moisture sensor probe into dry soil, and the LED ring lights up red (brightness 100%) — "Water shortage! Watering needed." Slowly add water to the soil; as the moisture value gradually rises, the LED changes from red to blue (brightness 80%) — "Soil absorbing water." Continue adding water to reach a suitable moisture level, and the LED changes to green (brightness 60%) — "Moisture just right." If too much water is added, the LED turns off — "Too wet, stop watering!" The entire process requires no reading of any numbers — the soil condition can be judged by the LED color alone.ThinkBesides LED ring color, what other methods could be used to indicate soil moisture? (Hint: sound, micro:bit 5×5 LED matrix displaying emoji expressions)If you wanted to turn this device into a true "automatic watering system," what additional actuator would you need?Program LogicTrigger ConditionActionSourceSoil moisture < 20 (dry)LED ring lights red at 100% brightness — urgent watering warningJacdac Soil Moisture SensorSoil moisture 20–50 (slightly dry)LED ring lights blue at 80% brightness — slightly dry; can water moderatelyJacdac Soil Moisture SensorSoil moisture 50–70 (suitable)LED ring lights green at 60% brightness — moisture suitableJacdac Soil Moisture SensorSoil moisture > 70 (overly wet)LED ring turns off — over-wet warning; stop wateringJacdac Soil Moisture SensorKnowledge Extension: From "Finger Test" to "Electronic Sensing" — The Precision Irrigation RevolutionI. Global Water Crisis and Agricultural Water UseAgriculture is the world's largest consumer of freshwater, accounting for approximately 70% of human freshwater withdrawals. However, about 50%–60% of water used in traditional irrigation methods is wasted through evaporation, seepage, and runoff — never actually reaching plant roots.Irrigation MethodWater Use EfficiencySuitable ScenariosFlood irrigation30%–40%Traditional agricultureSprinkler irrigation60%–70%Large-scale farmlandDrip irrigation90%–95%Greenhouses, orchards, high-value cropsSensor-based precision irrigation95%+Smart greenhouses, vertical farmsGlobal agricultural water accounts for approximately 70% of freshwater withdrawals. Promoting sensor-based precision irrigation could save hundreds of billions of cubic meters of water annually.II. if-elif-else — The Programming Paradigm of Multi-Level ClassificationThe four-level moisture judgment in this case (if-elif-elif-else) is the programming embodiment of multi-level classification thinking:if moisture < 20: Red LED → Dryelif moisture < 50: Blue LED → Slightly dryelif moisture < 70: Green LED → Suitableelse: LED off → Overly wetThis structure has countless applications in daily life:Application ScenarioClassification BasisMulti-Level OutputGrade levelsScore90+ Excellent / 80+ Good / 60+ Pass / <60 FailWeather warningsTemperatureRed / Orange / Yellow heat alertsAir qualityAQI indexGood / Moderate / Unhealthy for Sensitive / Unhealthy / Very Unhealthy / HazardousPhone batteryPercentage100% green / 20% yellow / 10% red flashingIII. Soil Moisture — More Than Just WateringPlant roots require a delicate balance of air and moisture. Soil that is too dry prevents roots from absorbing water and nutrients; soil that is too wet deprives roots of oxygen, leading to root rot. Different plants have entirely different soil moisture requirements:Plant TypeSuitable Moisture RangeWatering FrequencyCactus / Succulents20%–40%Once a week or lessTomato / Pepper50%–70%Every 1–2 daysRice80%–100% (flooded)Continuous floodingOrchids40%–60% (well-aerated)Every 3–5 daysReflection: The numerical value returned by the soil moisture sensor (0–100 or 0–255) is not the true soil water content percentage, but a relative value output by the sensor. In real applications, calibration using standard methods such as the "oven-drying gravimetric method" is required to convert sensor readings into accurate soil water content percentages. Calibration is an indispensable key step in all sensor engineering.