The greenhouse node: know what your plants feel, and act before a hot afternoon or a dry bed costs the crop.
The sun comes out on a still afternoon. The vents are shut, nobody is on site, and in an hour the greenhouse passes 40 °C. By evening the seedlings have wilted. Or one dripper blocks, one bed dries out, and nobody sees it until the leaves turn yellow.
Build a small node for that greenhouse. It reads the air, the soil and the light, runs a fan or a watering valve by a rule of its own, and warns the right person in time. It also keeps the record a grower can use: the hottest hour of each day, how dry the air was for the leaves, and how much light the crop got.
What you end with
A greenhouse that reports its air, soil and light every minute, runs its fan or its water on its own, and sends an alert when it gets too hot, when the air is too dry for the leaves, when a bed stays dry, when the watering does not wet the soil, and when the node itself goes quiet.
What you need
Rough prices for single parts bought online, in
Get the parts wherever suits you: a local electronics shop, or online. Pick a shop and each Find it link searches there.
| # | Part | Qty | About |
|---|---|---|---|
| 1 | ESP32 DevKitAny 30 or 38 pin boardFind it | 1 | KSh 650USD 5.00 |
| 2 | SHT31 or SHT40 moduleAir temperature and humidity, I2C at 0x44Find it | 1 | KSh 455USD 3.50 |
| 3 | BH1750 light moduleGY-302 board, I2C at 0x23Find it | 1 | KSh 195USD 1.50 |
| 4 | Capacitive soil probev1.2 or v2.0, with its 3-wire cableFind it | 1 | KSh 156USD 1.20 |
| 5 | Relay module, 1 channelInput that switches at 3.3 VFind it | 1 | KSh 195USD 1.50 |
| 6 | 12 V fan or valveA 12 V fan, or a normally closed 12 V valve on the drip lineFind it | 1 | KSh 585USD 4.50 |
| 7 | 12 V supplyFor the fan or the valve only; 1 A for mostFind it | 1 | KSh 520USD 4.00 |
| 8 | 1N4007 diodeAcross the fan or the valve coilFind it | 1 | KSh 13USD 0.10 |
| 9 | Clear acrylic disc40 mm across, 2 mm thick, for the light windowFind it | 1 | KSh 130USD 1.00 |
| 10 | M3 threaded rod110 mm each, with 6 nuts and 6 washersFind it | 3 | KSh 260USD 2.00 |
| 11 | PG7 cable glandsFive for the box, one for the shield, one for the light podFind it | 7 | KSh 390USD 3.00 |
| 12 | Cable, 4 coreTwo runs for the sensors, one for the valve or fanFind it | 6 m | KSh 390USD 3.00 |
| 13 | Terminal strip, 8 way5.08 mm pitch, for the joins in the boxFind it | 1 | KSh 130USD 1.00 |
| 14 | USB cable and 5 V adapter1 A or more; the cable to match your boardFind it | 1 | KSh 520USD 4.00 |
| 15 | Screws and U-bolts4 x M3 x 10, 2 x M3 x 8 self-tapping, 2 x M6 U-bolts, 2 for the wallFind it | 1 set | KSh 325USD 2.50 |
| 16 | PETG or ASA, whiteWhite for the shield and the pod: they must reflect the sunFind it | 300 g | KSh 780USD 6.00 |
| Total | KSh 5,694USD 44 |
Also: a 3D printer, neutral-cure silicone sealant, a second thermometer for the check, and an account on siliconwit.io (free).

AIR_SENSOR to match. Both check every reading with a check byte, so a bad wire gives no number rather than a wrong one. Greenhouse air is often near 100 %: keep the sensor dry in its shield, never in the spray.The design, in 3D and on paper
Turn it, open Parts to hide the lid, the shield's plates or the pod, and use Section to cut through the shield and see the sensor hanging inside. The parts carry the numbers of the parts list.

Build it
Each step links to the lesson section that teaches it. Open one only when you need it.
Tick each step as you finish it. Your place is kept, so you can stop and come back.
Kept on this device. Sign in to keep it on every device.Kept with your account.
Wire it on the desk
Wire it on the desk with jumper wires first, and fit it in the greenhouse only when it works.
- The breakout boards carry their own pull-up resistors, so the bus needs none added. With two boards the pull-ups add in parallel, about 5 k: still right for 50 kHz on cables up to 2 m.
- The soil probe runs from 3V3, so its output stays inside what the ESP32 reads. GPIO 34 is on the first ADC, which keeps working while the Wi-Fi is on.
- A fan motor or a valve coil kicks back a high voltage when the relay opens. The 1N4007 across it, with its bar to the plus, gives that current a safe path.
Set your greenhouse
Choose what the relay runs, and set the numbers at the top of the sketch:
// --- your greenhouse ---#define RELAY_DRIVES_FAN 1 // 1: the relay runs a fan by the temperature. 0: a pump or valve by the soilconst AirSensor AIR_SENSOR = SHT31; // SHT31 or SHT4X (both at address 0x44)const float FAN_ON_C = 30, FAN_OFF_C = 27; // fan: on at, off at (the gap stops it chattering)const float WATER_BELOW = 35, WATER_UNTIL = 55; // pump or valve: start below, stop at (% soil moisture)const uint32_t WATER_MAX_S = 300; // the longest one run may last (5 minutes)const uint32_t SOAK_S = 1800; // wait this long after a run before the next (30 minutes)const float SOIL_DRY_MV = 2600, SOIL_WET_MV = 1200; // your probe's two points; set them by command (step 5)const float WINDOW_T = 0.92; // the clear window over the light sensor passes 92 % (acrylic)const long UTC_OFFSET_S = 3 * 3600; // your time zone in seconds, for "today" (UTC+3 shown)- A fan (
RELAY_DRIVES_FAN1) starts atFAN_ON_Cand stops at the lowerFAN_OFF_C. The gap between them is what stops it switching on and off every time a cloud passes. It also stays on for at least 2 minutes and off for at least 1, to save the motor. - A pump or valve (0) starts when the soil is below
WATER_BELOWand stops atWATER_UNTIL, or afterWATER_MAX_S, whichever comes first. Then it waitsSOAK_S, because water takes time to reach the probe; without that wait it would water again before the first water arrived. - UTC_OFFSET_S is your time zone, so "today" ends at your midnight.
Flash and check on the desk
Open greenhouse_node/greenhouse_node.ino in the Arduino IDE, choose ESP32 Dev Module, install PubSubClient and ArduinoJson (version 7), and upload. The sensors need no library: the sketch reads them itself. Compiled for the ESP32 with the esp32 core 4.0.0: 1.13 MB of flash (85 % of the default app space) and 68 KB of RAM for global data, with no warnings, for a fan or a valve, the SHT31 or the SHT4x, and with or without TLS.
Open the Serial Monitor at 115200 baud. It names each sensor it finds. The logic was tested on a laptop first; these lines come from those tests:
sht: CRC of 0xBEEF is 0x92; 25.0 C 60 % decoded; a flipped bit refusedlight: count 1200 = 1000 lux; MTreg 32 reaches 117758 lux; 20,000 lux for 10 h = 13.3 mol/m2 a daysoil: dry 2600 mV and wet 1200 mV; 1900 mV is 50 %; 40 mV (unplugged) is no readingvpd: 25 C 70 % = 0.95 kPa; 35 C 40 % = 3.37 kPafan: on at 30, off at 27; a cloud made 0 switches; a lost sensor turns it onwater: dry at 34 % opens, 55 % shuts after 120 s; three dry runs stop it with a faultday: min 18, max 34.5; a new day at local midnight66 checks, 0 failedsoil_mv drops by more than 1,000.Print the shield, the pod and the box
PETG or ASA, in white for the shield and the pod: they must reflect the sun. 0.2 mm layers, 3 to 4 walls, 20 % infill, no supports. About 300 g in all. PLA softens in a hot greenhouse.
| Part | Lay it |
|---|---|
| Shield plate (print 4) | Outer edge and tabs down. The cone leans in at 45 degrees. |
| Shield cap | Roof down. The cone leans out at 45 degrees. |
| Arm | Top face down, the pole plate standing up. |
| Light pod | Floor down, the window recess at the top. |
| Probe cap | Closed end down. |
| Box | On its back, open side up. 101 x 153 mm with its ears. |
| Lid | Front face down, skirt up. |
A bare sensor in the sun reads the heat of its own board, several degrees above the air. The shield's louvres shade it and let the air move through. Each louvre is a cone at 45 degrees, so it prints with no supports, and the columns on the tabs stack one on the next. Three M3 rods hold the four plates, the cap and the arm together.
The light pod sits on the arm, above everything else, so nothing shades it. A 40 mm clear acrylic disc closes its top; it lets through about 92 % of the light, and the sketch makes up for that with WINDOW_T. The probe cap slides over the top of the soil probe and is filled with silicone, so the water from the hose never reaches its parts.
Checked in FreeCAD 1.1: the four louvres, the cap, the arm and the pod stack without touching, with 13 mm of air between louvres; the rods, the glands and the cables clear every part; the sensor hangs 7 mm from the axis in a 48 mm opening; the light board fits the pod with 6 mm to its wall; the probe fits its cap; and every module fits the box with 8 mm to spare under the lid.
Fit it in the greenhouse
- The shield at the height of the plants' leaves, near the middle of the house: not by the door, not against the film or the glass, and not in the spray of the irrigation. Clamp the arm to a frame pipe up to 32 mm with two M6 U-bolts, or screw it to a wooden post. Push the air sensor up through the gland in the roof so it hangs in the middle of the stack.
- The light pod on the arm, as the model has it, with open sky above it.
- The soil probe in a bed that stands for the rest, between a plant and its dripper, pushed in to the line on the probe. Water must reach it: a probe the water never reaches calls for water forever. The firmware notices that (step 7).
- The box on a post or the frame, out of the spray, every cable entering from below through a gland. The 12 V supply stays in a dry place.
Calibrate the soil probe in your soil
The probe gives a voltage, higher in dry soil and lower in wet soil. Two points fix the line from 0 to 100 %:
- Dry. Let the bed dry to the point where you would water it by hand. Send
soil_dryfrom the device page (step 8). The node takes its reading at that moment. - Wet. Water the bed well and wait 30 minutes for the water to spread. Send
soil_wet.
Both points are kept through a restart. They must be at least 300 mV apart; if a command says they are too close, read soil_mv on the record and send the values yourself, for example {"command":"soil_wet","value":1350}. With these points, "35 %" means "a little wetter than the soil you would water by hand", in this bed. Check it once a season: probes and soils change.
The local rule
Every 5 seconds the board reads the sensors and decides the relay, with or without the network:
bool relayOn() { return RELAY_DRIVES_FAN ? fan.on : water.on; }
void driveRelay() { bool on = RELAY_DRIVES_FAN ? fan.update(airT, nowS()) : water.update(soilPct, nowS()); digitalWrite(RELAY_PIN, (on == (bool)RELAY_ACTIVE_HIGH) ? HIGH : LOW); static bool savedFault = water.fault; if (water.fault != savedFault) { savedFault = water.fault; prefs.putBool("fault", water.fault); } // kept through a power cut}For watering, the rule also watches whether the water works. A run that ends on the time limit and raises the soil by less than 3 points is a dry run: an empty tank, a blocked line, a closed tap, or a probe the water does not reach. After three dry runs in a row it stops watering and raises fault, so it does not run a pump dry or water the path all day. Send auto again when you have fixed it. The fault is kept through a power cut, so a restart does not start the dry runs again.
bool update(float moist, uint32_t nowS) { if (on) { if (isnan(moist)) { stop(moist, nowS, false); return on; } if (moist >= stopPct) { stop(moist, nowS, false); return on; } if (nowS - startedS >= maxRunS) { stop(moist, nowS, true); return on; } return on; } if (!autoMode || fault || isnan(moist)) return on; if (everRan && nowS - stoppedS < soakS) return on; if (moist < startPct) start(moist, nowS); return on; }FAN_ON_C. Check: the fan starts, and stops once the sensor cools below FAN_OFF_C, with the network still off.Connect it
On siliconwit.io, our monitoring service: Add Device, then Define my own device, with the fields of the reading below. Set the data interval to 60 seconds and add a Toggle command named relay. To look around first, with no sign-up, siliconwit.io/try gives you a device for about 30 minutes. Copy the Device ID and Access Token into these lines, with your Wi-Fi above them, and upload again:
const char* MQTT_HOST = "mqtt.siliconwit.io";const int MQTT_PORT = 8883; // MQTT over TLSconst char* DEVICE_ID = "SWD-XXXXXX"; // client ID, username, and the topic nameconst char* MQTT_PASS = "your-access-token"; // the Access Token#define USE_TLS 1 // 0 only for a test broker on your own network: then port 1883, and no certificateOne reading a minute, on d/<device-id>/t:
{"temp":31.4,"rh":62.0,"vpd":1.75,"soil":44,"lux":38250,"relay":1,"sensor":1,"soil_mv":1985, "dli":9.6,"tmin":17.2,"tmax":33.8,"auto":1,"ts":1795000630}The link is MQTT over TLS on port 8883, with the ISRG Root X1 certificate in the sketch. After a failed connect it waits 5, 10, 20, 40, then 60 seconds. While the network is down it keeps up to 12 hours of readings and sends them later, each with its own time, and the fan or the water keeps running by its rule. A watchdog restarts the board if the code ever gets stuck. Your own Mosquitto broker works the same: change the broker lines, as on the live sensor node.
Make it act
This is where the greenhouse stops being a surprise. Email alerts come with the free account (up to 10 rules); SMS with the Business plan. Rules can wait for a value to hold, so one warm minute does not wake anyone. Send each alert to the person who can act on it:
temp above 35, held for 10 minutes Too coldtemp below 8, held for 15 minutes Dry airvpd above 2.0, held for 30 minutes Dry bedsoil below 25, held for 30 minutes Watering faultfault equal to 1 Sensor faultsensor equal to 0, held for 10 minutes Not reportingthe device silent for 10 minutes The last one matters most. A node that has lost its power or its network cannot say so itself; only the service can notice the silence. Change the numbers to suit your crop.
Commands calibrate the probe and change the rule from the device page, and each gets a reply. The relay toggle runs the fan for 30 minutes, or one watering run, then hands back to the rule:
d/SWD-XXXXXX/c {"command":"soil_dry","session":"a1"}d/SWD-XXXXXX/k/a1 {"status":"ok"}d/SWD-XXXXXX/c {"command":"soil_wet","session":"a2"}d/SWD-XXXXXX/k/a2 {"status":"ok"}d/SWD-XXXXXX/c {"command":"fan_on_c","value":32,"session":"a3"}d/SWD-XXXXXX/k/a3 {"status":"ok"}d/SWD-XXXXXX/c {"command":"water_until","value":99,"session":"a4"}d/SWD-XXXXXX/k/a4 {"status":"error","message":"water_until must be 95 or less, and at least 5 above water_below"}// a command on d/<id>/c: run it, then reply on d/<id>/k/<session>void onCommand(char* t, byte* data, unsigned int len) { JsonDocument msg; if (deserializeJson(msg, data, len)) return; // not JSON: ignore it const char* session = msg["session"] | ""; const char* error = nullptr; JsonVariant v = msg["value"]; bool yes = v.is<bool>() ? v.as<bool>() : (v == "on" || v == 1); float n = v.is<float>() ? v.as<float>() : NAN; const char* cmd = msg["command"] | ""; if (!strcmp(cmd, "relay")) { // by hand: the fan for 30 minutes, the water for one run#if RELAY_DRIVES_FAN fan.command(yes, nowS(), 1800);#else if (!water.command(yes, soilPct, nowS())) error = "soil already wet, or no soil reading";#endif driveRelay(); } else if (!strcmp(cmd, "auto")) { // true also clears a watering fault if (RELAY_DRIVES_FAN) fan.autoMode = yes; else if (yes) water.rearm(); else water.autoMode = false; driveRelay(); } else if (!strcmp(cmd, "fan_on_c")) { if (!fan.setLimits(n, fan.offC)) error = "fan_on_c must be at least 1 above fan_off_c, and 50 or less"; } else if (!strcmp(cmd, "fan_off_c")) { if (!fan.setLimits(fan.onC, n)) error = "fan_off_c must be at least 1 below fan_on_c, and 5 or more"; } else if (!strcmp(cmd, "water_below")) { if (!water.setLimits(n, water.stopPct)) error = "water_below must be 5 or more, and at least 5 below water_until"; } else if (!strcmp(cmd, "water_until")) { if (!water.setLimits(water.startPct, n)) error = "water_until must be 95 or less, and at least 5 above water_below"; } else if (!strcmp(cmd, "soil_dry") || !strcmp(cmd, "soil_wet")) { // with no value: take the probe's reading now. With a value: that many millivolts. float mv = isnan(n) ? soilMv : n; SoilCal c = soilCal; if (!strcmp(cmd, "soil_dry")) c.dryMv = mv; else c.wetMv = mv; if (!c.probeOk(mv)) error = "no good probe reading"; else if (!c.valid()) error = "dry must be at least 300 mV above wet"; else { soilCal = c; soilPct = soilCal.percent(soilMv); } } else { error = "unknown command"; } if (!error) saveSettings(); if (*session) { char reply[160]; if (error) snprintf(reply, sizeof(reply), "{\"status\":\"error\",\"message\":\"%s\"}", error); else snprintf(reply, sizeof(reply), "{\"status\":\"ok\"}"); mqtt.publish((topic("k/") + session).c_str(), reply); }}Read the record
- The hottest hour.
tmaxandtminare today's, by your clock. A week of them shows whether the fan or the vents keep up, and on which days they did not. - Air for the leaves.
vpdis the vapour pressure deficit: how hard the air pulls water out of the leaves. About 0.8 to 1.2 kPa is good growing air. Above about 1.6 the plants close their pores and stop growing; below about 0.4 fungus has an easy time. It tells more than the humidity alone, because warm air at 60 % is much drier for a leaf than cool air at 60 %. - Light per day.
dliis the daily light integral so far today, in mol per square metre, worked out from the lux with a factor for sunlight. Fruiting crops such as tomatoes want about 20 to 30 a day, lettuce about 12 to 17. A shade net or dirty film shows up here as a number, week after week. - Water. With a valve,
runsandwater_minshow how often and how long it watered today. Watering that grows week by week, with the same weather, points to a leak or a blocked dripper.
The free account keeps 7 days of history. Share the device with up to 2 people, for example the grower and the farm manager.
You are done when
- The temperature agrees with a second thermometer in the shade beside the shield within about 1 °C, on a sunny afternoon.
- The soil reads near 0 % in the dry bed and near 100 % after a full watering, and a bed you water by hand climbs on the record.
- With the router off, the fan starts when the air passes
FAN_ON_C, or the valve opens when the soil falls belowWATER_BELOW. - An alert reaches your phone when you unplug the node for ten minutes.
- After a full day, the reading carries
tmaxanddli, and you know what those numbers mean for your crop.
Downloads
- Build sheet: parts, wiring and the steps on two A4 pagesgreenhouse-node-build-sheet.pdf · 101 KB
- Firmware: Arduino sketch, logic, testsgreenhouse-node-firmware.zip · 21 KB
- Print files (STL) and print notesgreenhouse-node-stl.zip · 274 KB
- Drawings: the assembly, then the box, the lid, a shield plate with the cap, the arm, and the light pod with the probe cap, with every size in mm (6 A3 sheets)greenhouse-node-drawings.pdf · 253 KB
- FreeCAD 1.1 model, with the spreadsheetGreenhouseNode.FCStd · 127 KB
- STEP, every part and moduleGreenhouseNode.step · 710 KB
- Wiring drawinggreenhouse-node-wiring.svg · 23 KB
Checked: the firmware compiles for the ESP32 with no warnings in all its variants (a fan or a valve, the SHT31 or the SHT4x, a relay that switches on high or low, with or without TLS). Its logic (the sensors' check bytes and units, the light in lux and per day, the two-point soil calibration, the vapour pressure deficit, the fan rule, the watering rule with its dry-run guard, and the day at local midnight) passes 66 checks on a laptop, with the address and undefined-behaviour checkers on. The parts were checked in FreeCAD 1.1 with every module in place. A season in a greenhouse is next: if yours needs a change, tell us in the discussion below.
References
- MQTT and cloud communication on the ESP32: a capacitive soil probe, its calibration, and commands to a device.
- Feedback, open and closed loop: on-off control, and why it needs a band.
- A production monitoring system: soil and air nodes on one service, with alerts.
- Sensirion SHT3x and SHT4x data sheets: the single-shot commands, the CRC-8 (polynomial 0x31, start 0xFF), and the conversion to °C and % RH.
- ROHM BH1750FVI data sheet: the high resolution mode, the 1.2 factor, and the measurement time register.
- FAO Irrigation and Drainage Paper 56 (Allen and others, 1998): the saturation vapour pressure, 0.6108 exp(17.27 T / (T + 237.3)) kPa.
- Thimijan and Heins (1983), HortScience 18: light units for plants, and about 0.0185 µmol/m²/s per lux for sunlight.
- Build: the weather station: the same radiation shield, larger, for outdoors.
- Build: the live sensor node: the same firmware family, with one sensor.
Ways to take this build
Fitted and watched by us
Our engineers fit the sensors, watch the readings and send a monthly record of what it found and saved.
Start with one siteKSh 15,000USD 150 for the build
Four video meetings over about six weeks: plan it, show progress, show it working. Ends in a project record anyone can check.
Build it with a supervisorOpen to all
Every step, the firmware and the printable files. Tick the steps as you go.
Start step 1Priced for the group
Your staff or students build the greenhouse node together, with reviews and a record for each person.
Ask for a groupPlus opens the worked answers in the lessons each step links to: see Plus.
Made by
Engineers who build what they teach, and answer for it.



My notes on this page
Kept on this device. To have them on every device, turn on keeping in My notes.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.