# pH and NPK sensor

**URL:** <https://forum.arduino.cc/t/ph-and-npk-sensor/1404865>\
**Category:** Programming\
**Created:** [August 31, 2025, 5:15am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865 "2025-08-31T05:15:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 5:15am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/1 "2025-08-31T05:15:29Z")

</div>

Does anyone has a code for the RS485 4-in-1 npk and pH sensor? for arduino uno. Can't understand it. Just a student.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [August 31, 2025, 7:13am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/4 "2025-08-31T07:13:45Z")

</div>

Welcome. May I suggest you use the forum search to look for NPK sensor. Over the years this sensor has been discussed dozens of times.

You should also let the forum know which Arduino you are using. Also post the code you currently have along with a diagram of how you have connected the various parts of your project together.

What don't you understand about the code you have? Don't forget, if we can't see the code, then we can't understand it either.

You need the datasheet that is specific to your sensor as there are differences between the various NPK sensors that are for sale - mainly the register addresses for the various readings.

In case you don't already know, those 3 or 5 prong NPK sensors don't do what they claim to do. The consensus amongst the forum members with agricultural experience is that they simply don't (or can't) work and that only a chemical analysis can correctly determine the soil composition.

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 9:42am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/5 "2025-08-31T09:42:08Z")

</div>

Hello! This is all for a research work, and I am only a grade 10 student.

We needed a specific sensor which is the npk and pH measuring one, and we will be comparing the results of the sensor to the commercially available sensors to see if its effective.

this is the current code that we know and gathered online since we have a specific parts in the study that we need to connect to the sensor such as the bluetooth module and an LCD. And the main problem that we have is that we don't know how to add the pH reading in the code.

```arduino
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
// For the i2c supported Oled display module which is 128x64 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
#define RE 8
#define DE 7
 
// The following are the Inquiry frames which are send to the NPK sensor
//for reading the Nitrogen, Phosphorus, and Potassium values
// We defined three arrays with names nitro_inquiry_frame, phos_inquiry_frame, and pota_inquiry_frame 
// Each inquiry frame have 8 values
const byte nitro_inquiry_frame[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos_inquiry_frame[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota_inquiry_frame[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
 
byte values[11];
SoftwareSerial modbus(2,3);
 
void setup() {
  Serial.begin(9600);
  modbus.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

   display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  delay(500);
  display.clearDisplay();
  display.setCursor(25, 15);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println(" NPK Sensor");
  display.setCursor(25, 35);
  display.setTextSize(1);
  display.print("Initializing");
  display.display();
  delay(2000);
}
 
void loop() {
  // we will need three variables of the type byte to store the values of 
  // Nitrogen, phosphorus, and Potassium. 
  byte nitrogen_val,phosphorus_val,potassium_val;
 
  nitrogen_val = nitrogen();
  delay(250);
  phosphorus_val = phosphorous();
  delay(250);
  potassium_val = potassium();
  delay(250);
  
   // The following code is used to send the data to the serial monitor
  // but as we have connected the Bluetooth module, so it will send data to the 
  // Android cell phone Application

  Serial.print("Nitrogen_Val: ");
  Serial.print(nitrogen_val);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous_Val: ");
  Serial.print(phosphorus_val);
  Serial.println(" mg/kg");
  Serial.print("Potassium_Val: ");
  Serial.print(potassium_val);
  Serial.println(" mg/kg");
  delay(2000);
 
 // The following code is used to display the data on the Oled display
 //If you don't want to use the Oled display then you can simply delete the following code. 
 // Or you can also connect the Oled display module, this way you can display the data
 // on the Oled display module, and the data can also be send to the Android App. 
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(0, 5);
  display.print("N: ");
  display.print(nitrogen_val);
  display.setTextSize(1);
  display.print(" mg/kg");

   display.setTextSize(2);
  display.setCursor(0, 25);
  display.print("P: ");
  display.print(phosphorus_val);
  display.setTextSize(1);
  display.print(" mg/kg");
 
  display.setTextSize(2);
  display.setCursor(0, 45);
  display.print("K: ");
  display.print(potassium_val);
  display.setTextSize(1);
  display.print(" mg/kg");
 
  display.display();
}
 
/*
 * Now, we will need to create three user-defined functions to read the Nitrogen, Phosphorus, and Potassium values
 * These user-defined functions are going to be of the type byte
 */
 
 byte nitrogen(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(modbus.write(nitro_inquiry_frame,sizeof(nitro_inquiry_frame))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    // When we send the inquiry frame to the NPK sensor, then it replies with the response frame
    // now we will read the response frame, and store the values in the values[] arrary, we will be using a for loop.
    for(byte i=0;i<7;i++){
    //Serial.print(modbus.read(),HEX);
    values[i] = modbus.read();
   // Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4]; // returns the Nigtrogen value only, which is stored at location 4 in the array
}
 
byte phosphorous(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(modbus.write(phos_inquiry_frame,sizeof(phos_inquiry_frame))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(modbus.read(),HEX);
    values[i] = modbus.read();
   // Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4];
}

byte potassium(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(modbus.write(pota_inquiry_frame,sizeof(pota_inquiry_frame))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(modbus.read(),HEX);
    values[i] = modbus.read();
    //Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4];
}

```

Meanwhile, the circuit diagram is this, but instead of Nano we're using Arduino UNO

 ![308bc20a-0146-416d-9836-00b23d5bc407](https://europe1.discourse-cdn.com/arduino/original/4X/b/7/4/b74cba8d888aa4c2211bf756fe473ae2f2f2d88a.jpeg)

To be honest, I didn't know the sensor was probably a fake one and not that effective. We just searched one online and a lot of people bought it so we thought it was a good one. We could not find any other sensor that was suitable. Also, the version of the sensor (NPK and pH sensor only) does not have any much tutorial online, so we just looked for other alternatives how to make it work.

If you are wondering too, the yt tutorial that we watched is this one

[![](https://europe1.discourse-cdn.com/arduino/original/4X/0/f/a/0fa396ee889bf7c21ac223cd814ce03eb6f98a54.jpeg "Soil NPK Sensor with Arduino and Android Cell Phone Application for monitoring Soil Nutrient") ](https://www.youtube.com/watch?v=_93m1JdFhiY)

I have the file all about the sensor  
[氮磷钾PH.pdf](https://forum.arduino.cc/uploads/short-url/3apcOUhKxoYErXV7lxXdaUesX5o.pdf) (971.1 KB)

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [August 31, 2025, 9:55am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/6 "2025-08-31T09:55:13Z")

</div>

> [@jhdjfhja](#):
>
> I have the file all about the sensor, but I don't really know how to place one here.

To post images etc. you need trust level 1, you can get there by:

- Entering at least **5** topics
- Reading at least **30** posts
- Spend a total of **10** minutes reading posts

Users at trust level 1 can...

- Use all core Discourse functions; all new user restrictions are removed
- Send PMs
- Upload images and attachments

---

<div class="post-metadata">

**Author:** ![tigger](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tigger/32/1104210_2.png) [@tigger](https://forum.arduino.cc/u/tigger)\
**Post date:** [August 31, 2025, 11:07am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/7 "2025-08-31T11:07:22Z")

</div>

Years ago, I used to run an analytical laboratory, and when I see stuff like this, a three pronged device, claiming to be capable of analysing Nitrogen, Potassium and Phosphorous content, I get to be curiously sceptical.

Curious because I'm a bit out of touch with new developments, but am aware of solid state sensors and portable devices like drug wipes, Covid test devices and the blood glucose analyser I use regularly, a piece of design wonder, but as it's made by Roche, I'm confident it works. I also run glucose standards to check accuracy.

I'm less confident about an electronic device that can analyse simultaneously, an inert gas, a highly reactive non-metallic element and a highly reactive metallic element.

Of course, none of these are measured directly, but indirectly then expressed as mg/kg of N etc.

Nitrogen would be analysed as nitrate, nitrite and ammonia, with the nitrate and nitrite being reduced to ammonia for analysis. Phosphorous would be analysed colorimetrically and potassium by flame, atomic absorption spectroscopy or specific ion electrode.

All expensive and requiring dedicated facilities. pH is well documented and easily determined by an electrode or test strip in the field, as can the others.

I'm not dismissing this instrument, but would need to know a lot more about it before being confident in the numbers.

Another issue is quality control. All analytical methods in any sort of lab, are verified by the use of standards and blanks, plus calibration by using a range of known standards.

Water analysis is relatively easy, but in media like soil, analysis involves careful preparation before the real analysis starts.

If it works, all well and good, but there are a lot of hoops to jump through before taking numbers at face value.

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 11:30am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/8 "2025-08-31T11:30:25Z")

</div>

It would really be too late already to change all about our research so we really have to pursue this one. Our teachers and supervisors also did not tell us anything that it would not be possible that it won’t work or it won’t have any accurate readings.

I’m sorry if this will turn out desperate, but we don’t really have any other choice at this point.

I’m actually having second thoughts in competing now. We will need to present this research product and study to the district. And we just discovered now that the sensor is actually a problem

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [August 31, 2025, 11:30am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/9 "2025-08-31T11:30:52Z")

</div>

> [@jhdjfhja](#):
>
> ```arduino
> const byte nitro_inquiry_frame[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
> const byte phos_inquiry_frame[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
> const byte pota_inquiry_frame[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
> 
> ```

The data in these arrays need to match the sensor you are using. The 0x1E, 0x1F & 0x20 values are the register addresses within the device where the readings are stored. These need to match your specific device. NB If you have to change these values, then the last 2 bytes in each array will need to be re-calculated as the are a CRC16 checksum.

> [@jhdjfhja](#):
>
> ```arduino
> if(modbus.write(nitro_inquiry_frame,sizeof(nitro_inquiry_frame))==8){
> digitalWrite(DE,LOW);
> digitalWrite(RE,LOW);
> // When we send the inquiry frame to the NPK sensor, then it replies with the response frame
> // now we will read the response frame, and store the values in the values[] arrary, we will be using a for loop.
> for(byte i=0;i<7;i++){
> //Serial.print(modbus.read(),HEX);
> values[i] = modbus.read();
> // Serial.print(values[i],HEX);
> }
> Serial.println();
> }
> 
> ```

There is a major flaw in this piece of code and it is seen all over the internet where it has been copied from one project to the next. No check is made to see if a response has been received from the sensor. The code simply reads 8 values as soon as transmission has completed. Usually this results in 8 values of 0xFF being displayed.

Note that if the sensor does respond correctly, then your data usually gets out of sync. Your second message will be sent and the data read back in will be the response to the first message as that is already in the receive buffer.

You might want to simplify the code by stripping out all the OLED stuff. You can always add it back in once you get the code working.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [August 31, 2025, 11:41am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/10 "2025-08-31T11:41:13Z")

</div>

> [@jhdjfhja](#):
>
> I have the file all about the sensor  
> [氮磷钾PH.pdf](https://forum.arduino.cc/uploads/short-url/3apcOUhKxoYErXV7lxXdaUesX5o.pdf) (971.1 KB)

Here’s the google translate to english version of that PDF:

[0000\_PH (1).pdf](https://forum.arduino.cc/uploads/short-url/r6u16xPKLAxMQzJTUFczKdtn3q1.pdf) (1000.5 KB)

Section 5.3 has the register addresses. Looks like it uses addresses 0x04, 0x05 & 0x06 so you will have to change those arrays.

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 11:41am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/11 "2025-08-31T11:41:48Z")

</div>

I will try to look into this tomorrow. But one question, how can I insert the code for the value of the pH in the programming? since it’s only for NPK.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 31, 2025, 11:48am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/12 "2025-08-31T11:48:19Z")

</div>

> [@jhdjfhja](#):
>
> We needed a specific sensor which is the npk and pH measuring one, and we will be comparing the results of the sensor to the commercially available sensors to see if its effective.

Surely the fact that the sensor that you have is generally felt to be ineffective fits in with with that so why do you say

> [@jhdjfhja](#):
>
> It would really be too late already to change all about our research so we really have to pursue this one

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 11:52am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/13 "2025-08-31T11:52:05Z")

</div>

It’s the purpose of the research—to see if it will be effective or not. But at the same time, it HAS to be because we’ll fail if it’s not effective lol.

In the research paper, we need to compare our product to the commercially available ones to see the accuracy. But now that I asked around, it seems like the sensor does not provide accurate readings?

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [August 31, 2025, 11:52am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/14 "2025-08-31T11:52:09Z")

</div>

You would need to add a 4th array at the top of your code with the values for the pH register address. Those arrays are canned modbus messages so it helps to know what the values in them mean.

You could get all the data in one go if you were to slightly modify the example in section 5.4. If you were to change the 0x00 0x04 to 0x00 0x07 then that would request the contents of 7 registers starting with register address 0000 H (see table in section 5.3). You need to change the 0x44 0x09 in that message to 0x04 0x08 so that the CRC16 checksum is correct.

You would then send out just 1 message and get all the reading back together. Then you would pick out the values from the response message that you wanted.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 31, 2025, 11:55am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/15 "2025-08-31T11:55:09Z")

</div>

> [@jhdjfhja](#):
>
> It’s the purpose of the research—to see if it will be effective or not. But at the same time, it HAS to be because we’ll fail if it’s not effective lol.

That make no sense. Why will you fail if you meet the objective of the research ?

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 11:58am UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/16 "2025-08-31T11:58:28Z")

</div>

We have to defend the research, and we have to make an effective product. We won’t be able to finish Grade 10 if we don’t. That’s what our teacher said. 😓

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 31, 2025, 12:05pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/17 "2025-08-31T12:05:41Z")

</div>

> [@jhdjfhja](#):
>
> We have to defend the research,

If you use a sensible method to measure the effectiveness of the sensor you will be able to do this

> [@jhdjfhja](#):
>
> we have to make an effective product

You just moved the goalposts and extended the project

Have you got a written version of your assignment that you can share ? I am sure that forum members would like to see it

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 31, 2025, 12:49pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/18 "2025-08-31T12:49:24Z")

</div>

> [@jhdjfhja](#):
>
> In the research paper, we need to compare our product to the commercially available ones to see the accuracy.

It's not really a question of accuracy, but not being capable to measure those values.  
What are those "commercially available ones" that you compare to?

---

<div class="post-metadata">

**Author:** ![jhdjfhja](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jhdjfhja/32/1234844_2.png) [@jhdjfhja](https://forum.arduino.cc/u/jhdjfhja)\
**Post date:** [August 31, 2025, 1:04pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/19 "2025-08-31T13:04:05Z")

</div>

I’m not really sure yet since we’ll just borrow one from another school. It’s either maybe lab tested or the ones that are wireless.

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 31, 2025, 1:10pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/20 "2025-08-31T13:10:29Z")

</div>

To my opinion, your only hope to get out from the trap is that the device you compare to is similar to yours.

Description of one honest supplier:

"_NPK storage.The normal use method is that you measure NPK by other methods and then write the data to the device through RS485 command.  
It cannot be measured actually, because the nitrogen, phosphorus and potassium values measured by the equipment are not used as a reference. It is ok if it is only for project acceptance._"

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [August 31, 2025, 2:22pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/21 "2025-08-31T14:22:26Z")

</div>

The scam re NPK has been discussed numerous times on this forum and others. If your teachers are telling you to use this, then they have no clue what they are talking about. The sensor simply can not work; any data you see is not related to N, P or K. There are sensors that do that, but they cost a lot of money.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 31, 2025, 2:22pm UTC](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865/22 "2025-08-31T14:22:35Z")

</div>

> [@kmin](#):
>
> The normal use method is that you measure NPK by other methods and then write the data to the device through RS485 command.

Very handy quote! Where did you find it?

Never mind: I found [this page](https://www.niubol.com/Product-knowledge/Soil-NPK-Sensors-Principle.html) which gives a different explanation.

> Principle 2. [soil NPK sensor](https://www.niubol.com/Agricultural-sensor/Soil-NPK-sensor.html) actually measures the electrical conductivity of the soil. The manufacturer multiplies the measured conductivity value by a corresponding factor (based on the conventional soil content of nitrogen, phosphorus and potassium) to arrive at a value for the nitrogen, phosphorus and potassium content.
> 
> Due to the different soils and environments on site, such sensors cannot accurately measure the actual nitrogen, phosphorus and potassium content of the soil on site, but give an empirical, theoretical value.

Not that this is useful either, because NPK values don't depend on pH or conductivity.

[Next page](https://forum.arduino.cc/t/ph-and-npk-sensor/1404865.md?page=2)
