Soil NPK Sensor Library for Proteus Simulation: an Arduino UNO V4.0, a MAX485 module, the soil NPK probe, an OLED and two LEDs

Soil NPK Sensor Library for Proteus Simulation

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the new Soil NPK Sensor Library for Proteus Simulation. N, P and K - nitrogen, phosphorus and potassium - are the three numbers printed on every bag of fertiliser, because they are the three nutrients plants need most. The soil NPK probe is the farmer's gadget that measures them: three stainless needles pushed into the ground, and an RS485 cable that answers Modbus requests with the nutrients in mg/kg. With this library you can run a full Proteus simulation of the probe, frame by frame, so that your Modbus code works before the probe ever goes into a field.

Soil NPK Proteus simulation demo: the Arduino UNO V4.0 reading an RS485 NPK probe through a MAX485 module, N, P and K bars on the OLED, the OK and LOW LEDs
Figure: The soil NPK simulation running: a poor bed, fertiliser, then heavy rain.
Updates

Soil NPK Sensor Library for Proteus

Latest version: V1.0 (November 2026, this tutorial)

Helping Tools

The probe comes alive at run time: its PWR LED lights with the supply and the COM LED flashes with every answer it sends. The demo is a garden bed monitor: an Arduino asks the probe for N, P and K through our MAX485 module every two seconds, draws them as bars on an OLED, and lights an OK or a LOW LED - while the bed goes from poor soil, through a dose of fertiliser, to a heavy rain that washes the nitrogen away.

NOTICE: Our team has put a lot of effort into these small parts: the bodies, the animation and the pop-ups are all our own design, and you get them free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below or in the soil moisture board of our forum. And if our free libraries help you, you can buy us a coffee. So, let's get started with the Soil NPK Sensor Library for Proteus Simulation:

Soil NPK Sensor Library for Proteus Simulation: an Arduino UNO V4.0, a MAX485 module, the soil NPK probe, an OLED and two LEDs
Figure: The Soil NPK Sensor Library for Proteus Simulation.

What Does a Soil NPK Sensor Measure?

Plants take their food from the water in the soil. Nitrogen builds leaves, phosphorus builds roots and flowers, potassium keeps the whole plant strong. Too little of any one of them and the crop suffers; too much is wasted money and runs off into the rivers. A laboratory test tells you exactly what a soil holds, but it takes days. The NPK probe gives an estimate in seconds: its needles measure the soil's electrical properties, and its electronics turn them into three numbers, nitrogen, phosphorus and potassium in mg/kg (the same as parts per million). It is not a laboratory - but for watching a bed or a greenhouse change from day to day, it is a very useful tool.

The soil NPK probe at a glance
Soil NPK probe (RS485)
Measuresnitrogen, phosphorus and potassium, 0 - 1999 mg/kg, 1 mg/kg steps
Probea sealed epoxy head, three stainless needles about 60 mm long
Supply5 - 30 V DC (12 V is common), about 0.15 W
InterfaceRS485, Modbus-RTU, 9600 baud, 8 data bits, no parity, 1 stop bit
Address1 by default (1 - 254)
Cablebrown V+, black GND, yellow A, blue B

RS485 and Modbus

Fields are big, and a sensor may sit a hundred metres from its controller. RS485 carries the data on a twisted pair, A and B, as a difference between the two wires, so noise picked up by both cancels out. The probe speaks Modbus-RTU over it: the master sends a request - the slave's address, a function code, the register and how many to read, and a two-byte CRC - and the slave answers with the same address and function, a byte count, the data and its own CRC. A UNO has no RS485 of its own, so a small transceiver like the one in our MAX485 RS485 Module Library for Proteus sits in between: DI and RO are the UART's TX and RX, and DE / RE switch it between talking and listening.

The Registers

The soil NPK probe's registers (function 0x03)
RegisterHoldsNotes
0x001Enitrogenmg/kg
0x001Fphosphorusmg/kg
0x0020potassiummg/kg
0x07D0the device address1 - 254, written with function 0x06
0x07D1the baud code0 = 2400, 1 = 4800, 2 = 9600; counts after a restart

Many tutorials read the three nutrients with three separate requests. One request can read all three at once: 01 03 00 1E 00 03 65 CD asks slave 1 for three registers from 0x001E, and the answer 01 03 06 ... brings six data bytes - N, P and K, each with its high byte first.

Features of the Soil NPK Sensor Library for Proteus Simulation

  • A real-looking probe: the black epoxy head with its label plate, three stainless needles and the four coloured wires, drawn compact so it sits next to an Arduino on the sheet.
  • Animated: a PWR LED and a COM LED that flashes with every answer (our addition - the real probe has none).
  • Real RS485: the A / B pair works with our MAX485 module, at 9600 baud 8N1, the probe driving the pair only while it answers.
  • Real Modbus-RTU: functions 0x03, 0x04 and 0x06, the CRC, the address, exceptions for an unknown function, a wrong register or a bad value, and silence for a wrong CRC or another address.
  • A scene: a poor bed, fertiliser, then heavy rain, plus chips for sandy soil, a garden bed, compost and potting mix, fertiliser and rain at any time.
  • A pop-up: the probe in the soil with the nutrients as coloured grains, the last six Modbus frames byte by byte with their meaning, eight live tiles, graphs, an event log and a check page.
  • A complete package: about 2.6 MB with the library, our MAX485, OLED, 5 mm LED and resistor libraries, our Arduino UNO V4.0 and the demo, without the source code of the model.

The Soil NPK Sensor in Proteus

The device is SOILNPKTEP in TEPSOILNPK.LIB, under Sensors > Soil, with the prefix U and the model TEPSOILNPK.DLL. Search NPK or soil in Pick Devices. Four pins along the bottom: VCC (5 - 30 V), GND, A and B. Its properties: PROFILE (DEMO or STEADY), N, P and K (for STEADY, in mg/kg) and ADDRESS (1 - 247).

RS485 soil NPK probe from the Soil NPK Sensor Library for Proteus Simulation
Figure: The soil NPK probe.

Download Soil NPK Sensor Library for Proteus Simulation

Click the button below to download Soil-NPK-Sensor-Library-for-Proteus-v1.0.zip (about 2.6 MB, without the source code of the models):

Soil NPK Sensor Library for Proteus V1.0
  • README.txt: installation, the demo, the wiring, troubleshooting and the limits of the simulation.
  • Proteus Library Files: TEPSOILNPK.LIB, TEPMAX485.LIB, TEPOLED12864.LIB, TEPLED5MM.LIB, TEPRESISTOR.LIB and ArduinoV4TEP.LIB.
  • Proteus Model Files: TEPSOILNPK.DLL, TEPMAX485.DLL, TEPOLED.DLL, TEPLED5MM.DLL, TEPRESISTOR.DLL and TEPARDUINO.DLL.
  • Arduino Code: the demo sketch (it needs AltSoftSerial).
  • Proteus Simulation: the demo project, its HEX file and copies of the DLLs.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install Soil NPK Sensor Library for Proteus Simulation

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy the files from Proteus Model Files into the MODELS folder.
  4. Delete TEPSOILNPK.IDX from the LIBRARY folder if it is there.
  5. Start Proteus, press P and search for NPK.

Proteus Simulation of a Garden Bed Monitor

Our demo watches a vegetable bed. U2 is the NPK probe with PROFILE DEMO: the bed starts poor, with N 30, P 12 and K 95 mg/kg; at 4 seconds fertiliser is watered in, and the soil heads for N 140, P 62 and K 210; at 11 seconds a heavy rain washes the nitrate out - nitrogen falls to 35 and some potassium goes too, while the phosphorus, which binds to the soil, stays. The probe runs from a +12V terminal. U1 is our MAX485 module: RO to D8 and DI to D9 of our Arduino UNO Library for Proteus V4.0, DE and RE together to D2, and A and B to the probe. Our OLED SSD1306 Library for Proteus shows the readings, and two LEDs from our 5mm LED Library for Proteus sit beside it: OK (green, D5) and LOW (red, D6), each through 220 ohm. The Arduino's built-in monitor is the same window as our TEP Serial Monitor Advance for Proteus. Open SoilNPK-RS485-ArduinoUnoV4.pdsprj.

Soil NPK simulation in Proteus: Arduino UNO V4.0, a MAX485 module, the NPK probe, an OLED and two LEDs on an A4 sheet
Figure: The whole simulation on an A4 sheet.

The Sketch

The sketch is a small Modbus master written out by hand, so every byte can be seen. It talks through AltSoftSerial, a software UART on D8 and D9. The request for the three nutrients is six bytes:

  frame[0] = PROBE; frame[1] = 0x03; frame[2] = 0x00; frame[3] = 0x1E; frame[4] = 0x00; frame[5] = 0x03;

The CRC is the Modbus one - polynomial 0xA001, starting from 0xFFFF - calculated bit by bit:

    for (byte b = 0; b < 8; b++) c = (c & 1) ? (c >> 1) ^ 0xA001 : c >> 1;

Unlike the data, the CRC goes out with its low byte first:

  frame[n] = c & 0xFF; frame[n + 1] = c >> 8;               // the CRC's low byte goes first

RS485 is half duplex: only one side may drive the pair at a time. The sketch raises DE / RE while the request goes out, waits for the last stop bit with flush(), and drops it again to listen:

  digitalWrite(DE_RE, HIGH);                                // the MAX485 drives the pair

The answer's CRC is checked, and the three values are taken from it, each with its high byte first:

  for (byte i = 0; i < 3; i++) npk[i] = (unsigned int)frame[3 + 2 * i] << 8 | frame[4 + 2 * i];   // the high byte first

Each nutrient is compared with this demo's mark - N 50, P 25 and K 120 mg/kg. The OLED shows SOIL OK or FERTILISE in big letters and the three nutrients as bars with their marks and values, LOW beside any that is short.

Soil NPK Simulation Results

Open the project and press Run. The demo runs 19 simulated seconds and took 195 seconds on our PC with the pop-up open and the pictures being taken. Click the probe for its pop-up. Every number below comes from one simulation run, the demo exactly as it ships.

A Poor Bed

The probe powers up from the +12V terminal and takes its first measurement 0.4 seconds later: N 30, P 13, K 94 mg/kg. At 0.6 seconds the sketch sends its first request - 01 03 00 1E 00 03 65 CD - and 20 ms after the last byte the probe's COM LED flashes and its 11-byte answer comes back: 01 03 06 00 1E 00 0D 00 5E and the CRC. All three nutrients are under their marks, so the OLED says FERTILISE, every bar is short, the red LOW LED is on and the monitor prints "N 30 P 13 K 94 mg/kg LOW: N P K". The pop-up shows the soil with only a few coloured grains in it, and the frames list each request and answer byte by byte.

Soil NPK Proteus simulation pop-up: a poor bed, all three nutrients low, the first Modbus frames
Figure: A poor bed.

Fertiliser

At 4 seconds fertiliser is watered in, and the soil takes up the nutrients over a few seconds - the probe follows with its own lag, a new measurement each second. At 6.6 seconds the sketch reads N 89, P 39, K 158: all three are past their marks, the OLED turns to SOIL OK, the green LED takes over from the red one, and the monitor says "all fine". At 8.6 seconds the readings are 124, 53 and 191, and at 10.6 seconds 134, 58 and 204 mg/kg, close to the soil's new 140, 62 and 210. On the sheet the COM LED keeps flashing every two seconds, and in the pop-up the soil fills with blue, orange and violet grains.

Soil NPK Proteus simulation: the OLED with N, P and K bars and SOIL OK, the OK LED lit
Figure: The OLED: N, P and K.
The soil NPK garden bed simulation running in the Proteus workspace with the Arduino UNO V4.0 and the MAX485 module
Figure: The simulation in the workspace.
Soil NPK Proteus simulation pop-up: the bed fertilised, the Modbus requests and answers byte by byte
Figure: Fertilised.

Heavy Rain

At 11 seconds a heavy rain falls on the bed. Nitrate dissolves easily and drains away with the water, so the nitrogen drops: 109 at 12.6 seconds, 64 at 14.6, and 44 mg/kg at 16.6 seconds - under its mark of 50. The OLED goes back to FERTILISE with LOW beside N only, the red LED returns, and the monitor prints "N 44 P 60 K 188 mg/kg LOW: N". Phosphorus binds tightly to the soil and stays at 60; potassium loses a little, down to 185. At 18.6 seconds the nitrogen reads 38 - the gardener knows exactly which fertiliser to add, and only that one.

Soil NPK Proteus simulation pop-up: heavy rain, the nitrogen washed out of the soil
Figure: After the rain.

The Graphs, the Event Log and the Check Page

The Graphs page plots the three registers and the supply. The Event log keeps the power-up, the first measurement and the scene, and would record any Modbus exception or wrong CRC. The Check page sums up the run: the probe on 12.0 V drawing 12 mA; N 38, P 61, K 185 mg/kg with the soil at 35, 60 and 185; 10 requests and 10 answers at address 1, 9600 baud 8N1, no writes, no frames for others; no wrong CRC and no exception.

Soil NPK Proteus simulation graphs: nitrogen, phosphorus, potassium and the supply
Figure: The Graphs page.
Soil NPK Proteus simulation Event log: the power-up, the measurements and the scene
Figure: The Event log.
Soil NPK Proteus simulation Check page after the demo run
Figure: The Check page.

The monitor shows the sketch's side: the request, and a line every two seconds with the nutrients and what is low.

Arduino UNO V4.0 serial monitor in the soil NPK Proteus simulation: the nutrients every two seconds
Figure: The monitor.

NPK, Moisture and pH

Nutrients are only half the story. A plant can only take them up through water, so a soil moisture sensor like the one in our Capacitive Soil Moisture Sensor Library for Proteus tells you whether the bed needs watering - and NPK probes read low in dry soil anyway. The soil's pH decides how available each nutrient is; our PH-4502C pH Sensor Library for Proteus measures it in water and nutrient solutions. A smart farm watches all three: moisture for the pump, NPK for the fertiliser, pH for the balance.

Try It Yourself

  • Click Compost: N 260, P 120, K 420 mg/kg - the bars run full and the OLED says SOIL OK.
  • Click Sandy: almost nothing holds in sand - all three go LOW.
  • Set ADDRESS to 2: the probe ignores the sketch's requests, the pop-up logs them as "for slave 1", and the monitor reports no answer.
  • Change the request to read four registers from 0x001E: the probe answers with exception 2 - there is no register 0x0021.
  • Write 5 to 0x07D0 with function 0x06: the probe echoes the request and answers to address 5 from then on.

Ideas to Extend the Demo

  • Log N, P and K every hour to an SD card and draw a season's curve.
  • Read three probes on the same RS485 pair - give each its own address.
  • Send the readings to a phone over Wi-Fi with an ESP32 instead of the UNO.

Your Own Sketches

The demo sketch is in the zip file, and you can change it in the Arduino IDE. New to Arduino? Start with our Arduino Tutorial for Beginners. Export the compiled binary, and set the UNO's PROGRAM property to the new file. Our guide on How to get the HEX file from Arduino shows you where the file ends up.

Things to Know Before Using a Real NPK Probe

  • Contact: push all three needles fully into moist soil, with no stone in the way; dry or loose soil reads low.
  • An estimate: the probe works from the soil's conductivity; use it for trends and comparisons, and check it against a laboratory test now and then.
  • The baud rate: some probes ship at 4800 baud - check the label and match the sketch.
  • The wiring: A to A and B to B; long cables want a 120 ohm terminator at each end; and the probe's ground must join the controller's.
  • Power: most probes want 9 - 24 V or 5 - 30 V; a UNO's 5 V pin may not be enough for every model.

Troubleshooting

  • No answer from the probe: A and B swapped, no supply, another address, or DE / RE still high when the answer comes.
  • A wrong CRC: the baud rate or the frame format differs - the event log shows the bytes the probe saw.
  • Exception 2: the register is outside 0x001E - 0x0020, 0x07D0 and 0x07D1.
  • The values never change: the probe measures once a second, and soil changes slowly.
  • The part is not simulated: TEPSOILNPK.DLL is missing from MODELS and from the project folder.

Limitations of the Simulation

  • The RS485 pair, Modbus-RTU and the register map follow the vendors' manuals for this common probe; the probe is our own drawing, the needles shortened.
  • Our own choices: function 0x04 answered like 0x03, the 20 ms before an answer, the measurement each second with its 1.5 s lag and 1 mg/kg of noise, the scene and the LEDs.
  • Not modelled: other baud rates during a run, the effect of moisture and temperature on the readings, and the probe's accuracy class.
  • Arduino is a name of Arduino; this library is not made or endorsed by Arduino, Labcenter or any probe vendor.
  • Tested in Proteus 8.5 in November 2026 (the demo as shipped). Proteus 7 is not supported.

So, that was all about the Soil NPK Sensor Library for Proteus Simulation. I hope it helps you build your smart garden, your greenhouse logger or your farm's Modbus network before the probe goes into the ground - and shows that RS485 and Modbus are simple once you have seen the bytes: an address, a function, a register, a count and a CRC. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation