Skip to main content

Case 13: Smart Greenhouse


Introduction

Simultaneously use the Jacdac temperature & humidity sensor and soil moisture sensor to monitor the greenhouse environment in real time. Only when all three indicators are within acceptable ranges (temperature < 35, humidity < 75, soil moisture < 50) does the micro:bit LED matrix display a smiley face indicating "crop growing conditions are good." If any indicator falls outside the range, a frowny face alarm is displayed. Press button A to rotate the 360° building-block servo forward and open the ventilation window; press button B to reverse the servo and close the ventilation window; touch the Logo to stop the servo.


Learning Objectives

  1. Learn about the temperature & humidity sensor and soil moisture sensor — core sensors for greenhouse environmental monitoring.
  2. Understand multi-condition logic judgment (AND) — all conditions must be met simultaneously to be considered satisfactory.
  3. Learn multi-sensor fusion — synthesizing readings from multiple sensors to make comprehensive judgments.
  4. Explore the applications and significance of smart greenhouses in modern agriculture.

Required Materials

ItemImageQuantity
micro:bit V21
Jacdac Expansion Board1
Jacdac 10cm Connector Cable1
Jacdac 25cm Connector Cable2
Jacdac Temperature & Humidity Sensor1
Jacdac Soil Moisture Sensor1
Jacdac Servo Module1
360° Building-Block Servo1
USB Cable1

Sensor Principle

Two Key Greenhouse Sensors

This case simultaneously uses two types of Jacdac sensors, forming a complete greenhouse environmental monitoring system:

SensorMeasurementThreshold in This CaseRole in the Greenhouse
Temperature & Humidity SensorAmbient temperature; air humidity< 35 (suitable); < 75 (suitable)Moderate temperature → comfortable; too low → close window for insulation; moderate humidity → not stuffy or dry
Soil Moisture SensorSoil water content< 50 (suitable)Moderate soil moisture → no irrigation needed

Assembly Steps


Model Principle

Smart Greenhouse — Replacing the Farmer's Eyes with Sensors

In traditional farming, farmers rely on experience to judge "should I ventilate today? should I water today?" A smart greenhouse replaces human senses with sensors:

Traditional MethodSmart Greenhouse MethodAdvantage
Touch the soil to judge wet/drySoil moisture sensorPrecise numerical values, 24/7 monitoring
Feel whether it's hot or coldTemperature sensorAccuracy to 0.1°C
Judge stuffiness by feelHumidity sensorQuantified indicators, automatic recording

In this case, the 360° building-block servo simulates the greenhouse's motorized ventilation window — forward rotation opens the window for ventilation and cooling; reverse rotation closes the window for insulation; touch the Logo to stop.


Connection Diagram

As shown below, insert the micro:bit V2 board into the Jacdac expansion board, and use cables to connect the temperature & humidity sensor, soil moisture sensor, and 360° building-block servo module to the Jacdac expansion board's edge connector.

Connection Diagram


Programming Software

Microsoft MakeCode


MakeCode Programming

Step 1: Adding the Jacdac Extension

  1. Go to Microsoft MakeCode and click "New Project".

    New Project

  2. Enter a project name in the pop-up window and click "Create".

    Create Project

  3. Click "Extensions" in the code drawer.

    Extensions

  4. In the pop-up interface, type "Jacdac" and click the search icon, then select the Jacdac software library as shown.

    Search Jacdac


Step 2: Connecting the Hardware

  1. Use 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 micro:bit

  2. Connect the sensors. MakeCode will automatically detect and simulate them in the simulator area, where sensor status is displayed in real time.

    Sensor Simulation

  3. Click "ADD BLOCKS" to add the sensor extension module.

    Note: When connecting a new sensor, repeat the "click 'ADD BLOCKS'" workflow once.

    ADD BLOCKS


Write the Program as Shown

Program Screenshot


https://makecode.microbit.org/_ac7XFk7rE4Fa

You can also download the program directly from the webpage below. Once downloaded, you can start running the program.


Result

When all three conditions — temperature < 35, humidity < 75, soil moisture < 50 — are simultaneously satisfied, the micro:bit LED matrix displays a smiley face, indicating that the greenhouse environment is suitable for crop growth. If any one indicator exceeds its threshold (temperature ≥ 35 OR humidity ≥ 75 OR soil moisture ≥ 50), a frowny face alarm is immediately displayed. Press button A to rotate the 360° building-block servo forward (100), simulating opening the ventilation window. Press button B to reverse the servo (-100), simulating closing the ventilation window. Touch the Logo to stop the servo.


Think

  1. Real greenhouses need to monitor temperature, humidity, light, CO₂ concentration, and many other parameters simultaneously. If a light sensor were added, how should the program be modified?
  2. In this case, all three conditions must be met to show a happy face. If the logic were changed to "alarm if any one exceeds the threshold," how should the logic be changed? (Hint: AND → OR)

Program Logic

Trigger ConditionActionSource
Temperature < 35 AND humidity < 75 AND soil moisture < 50 (environment suitable)LED matrix displays smiley faceJacdac Temperature & Humidity + Soil Moisture Sensors
Any indicator exceeds threshold (temperature ≥ 35 OR humidity ≥ 75 OR soil moisture ≥ 50)LED matrix displays frowny faceJacdac Temperature & Humidity + Soil Moisture Sensors
Button A pressed360° building-block servo rotates forward (100), simulating opening the ventilation windowmicro:bit V2 Button A
Button B pressed360° building-block servo rotates in reverse (-100), simulating closing the ventilation windowmicro:bit V2 Button B
Logo touched360° building-block servo stops rotatingmicro:bit V2 Logo touch key

Knowledge Extension: Smart Greenhouses — When Agriculture Meets IoT

I. What Is a Smart Greenhouse?

A Smart Greenhouse is a modern agricultural production system that integrates sensor monitoring, automatic control, and data analysis. By deploying multiple sensors to collect environmental data in real time, the control system automatically adjusts temperature, humidity, light, irrigation, and more, creating the most suitable growing environment for crops.

Traditional FarmingSmart Greenhouse
At the mercy of weather; heavily affected by climateEnvironment controlled; stable year-round production
Manual watering and fertilizing based on experiencePrecise sensor monitoring; automatic irrigation and fertilization
Pest and disease detection is late; heavy lossesEarly warning; precision prevention and treatment
Severe water and fertilizer wasteWater and fertilizer savings of 30%–50%
Unstable yieldsYields can be significantly increased

II. Greenhouse Environmental Parameter Standards

Environmental ParameterSuitable Range (most crops)Sensor Type
Temperature20°C–30°C (daytime) / 15°C–20°C (nighttime)Temperature sensor
Air Humidity60%–80%Humidity sensor
Soil Moisture50%–70% field capacitySoil moisture sensor
Light Intensity20,000–50,000 luxLight sensor
CO₂ Concentration800–1,200 ppmCO₂ sensor

According to FAO statistics, the global population will reach 9.7 billion by 2050, and food demand will increase by approximately 60%. Precision agriculture, represented by smart greenhouses, is one of the key technologies to address this challenge.


III. AND Logic — From Code to Life

The core logic of this case — multiple conditions all satisfied simultaneously (AND) — exists far beyond code:

ScenarioAND Logic
Passing an examLanguage passed AND Math passed AND English passed
Rocket launchWeather OK AND Equipment OK AND Trajectory OK AND Communications OK
Phone unlockFace matched AND eyes looking at screen (anti-photo unlock)
Greenhouse达标Temperature OK AND Humidity OK AND Soil OK

The three-condition AND judgment program you wrote follows the exact same logic as SpaceX's pre-launch "Go/No-Go" checklist — thousands of conditions must all be green before ignition. Programming mindset is everywhere.