Build an ESP32 Garden Fertility Station: NPK and EC Soil Sensors for Data-Driven Feeding
ESP32 DevKit development board
RS485 NPK soil nutrient sensor probe
Soil EC (conductivity) sensor probe
MAX485 TTL-to-RS485 converter module
12V 2A power supply
DC-DC buck converter module
IP68 waterproof junction box enclosure
1413 ยตS/cm conductivity calibration solution
Waterproof cable gland assortment
Prices and availability as of Nov 22, 7:04 AM ET and subject to change. The price shown on Amazon at the time of purchase applies.
Most DIY soil-sensing projects stop at moisture: a capacitive probe, an ESP32, a WiFi report, done. That answers "does this bed need water" but says nothing about "does this bed need food." Nitrogen, phosphorus, and potassium (NPK) deficiency and excess soil salinity (measured as electrical conductivity, or EC) are the two things that actually determine whether a fertilizer program is helping or quietly burning your plants' roots, and until recently the sensors to measure them were lab equipment, not maker parts. RS485 NPK soil sensor probes and basic EC probes have both come down enough in price that a fertility station is now a realistic weekend ESP32 build. This project covers wiring both sensor types, the calibration reality that most sellers don't mention, and turning raw probe output into fertilizer decisions you can actually act on.
What You're Actually Measuring
Cheap integrated NPK soil sensors (the common garden-stake probes sold for a reasonable price on marketplaces) typically use optical/spectroscopic or basic electrochemical methods internally and output pre-scaled N, P, and K values in mg/kg over RS485 Modbus โ they do the hard analytical chemistry for you and hand you a clean register read. This is good news for a weekend build but means you are trusting a black box: these sensors are reasonably reliable for trend tracking (is nitrogen climbing or falling after I fed) but should not be treated as lab-accurate absolute values, and they drift meaningfully with soil moisture content, since most of the common designs are not fully moisture-compensated. A separate EC probe measures soil electrical conductivity directly, which correlates with total dissolved salts (including fertilizer salts) in the soil solution โ rising EC after a feeding, falling EC after a heavy rain or leaching flush, is the signal you actually want for catching over-fertilization before it burns roots.
Wiring the RS485 Bus
Both the NPK probe and most EC probes in this price range speak RS485 Modbus RTU rather than a simple analog or I2C interface, which is actually convenient: you can put both sensors on the same two-wire RS485 bus, each with its own Modbus slave address, and read them sequentially from a single MAX485 module. Wire the probe's A/B differential pair to the MAX485's A/B terminals, the MAX485's RO/DI to two ESP32 UART GPIOs, and DE/RE to a third GPIO for transmit/receive direction control (tie DE and RE together โ the ESP32 drives that pin high to transmit a request and low to listen for the response). Both sensor types need their own 9-24V supply separate from the ESP32's 3.3V/5V logic rail; run a single 12V supply to both probes and a buck converter down to 5V for the ESP32 to keep the wiring to one power brick at the bed.
Reading the Registers
Each probe ships with (or the seller will provide on request) a short Modbus register map โ typically nitrogen, phosphorus, and potassium as three consecutive holding registers on the NPK probe, and conductivity, temperature, and sometimes moisture on the EC probe. The ModbusMaster Arduino library handles the request/response framing; a typical read is a function-code-3 "read holding registers" request to the probe's slave address, parsed into three 16-bit integers that you scale per the datasheet (commonly direct mg/kg for NPK with no scaling factor, and ยตS/cm for EC, sometimes requiring a x10 or /10 factor โ confirm against the specific datasheet you received, since this varies between sellers even for visually identical probes).
The Calibration Reality
This is where most sensor tutorials wave their hands. The EC probe is straightforward to verify: dunk it in 1413 ยตS/cm calibration solution at room temperature and confirm the reading is close to that value (most of these probes have an onboard trimmer or Modbus calibration register for a two-point offset if it's off). The NPK probe is much harder to verify yourself without lab equipment, and you should treat its absolute numbers with real skepticism โ the honest approach is to use it as a trend instrument: record a baseline reading in a bed before feeding, apply a known quantity of fertilizer, and watch how the reported values move over the following days. If nitrogen climbs after a nitrogen feed and falls over two weeks as plants take it up, the sensor is doing its job even if the absolute mg/kg number isn't laboratory-precise. Soil moisture is the biggest confound for both sensor types โ take readings at a consistent time relative to watering, or better, log moisture alongside NPK/EC and only compare readings taken at similar moisture levels.
Turning Numbers Into Feeding Decisions
Push all four values (N, P, K, EC) to Home Assistant over MQTT or ESPHome's native API alongside a moisture sensor, and build a simple automation: alert when EC crosses a high threshold (risk of fertilizer burn โ flush with plain water), alert when nitrogen trends downward for more than a week with no corresponding plant growth explanation (time to feed), and log everything to a long-term statistics graph so you can see, season over season, whether your feeding schedule is actually matching plant uptake or whether you're dumping fertilizer into soil that's already saturated. The real value of this build isn't any single reading โ it's having a week-over-week trend line that turns "I think the tomatoes look a little pale" into an actual decision backed by data from the bed itself.
Safety and Durability Notes
These probes are buried in wet soil permanently, so every electrical connection between the probe and the enclosure must go through a proper waterproof cable gland, not electrical tape and hope. Keep the RS485 bus run under about 10 m per probe run without termination resistors to avoid signal reflection issues on long cable runs, and route sensor cable separate from any nearby irrigation solenoid valve wiring to avoid switching-noise interference on the Modbus bus.