Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Measure Soil Nutrient using Arduino & Soil NPK Sensor
Arduino Projects

Measure Soil Nutrient using Arduino & Soil NPK Sensor

Mamtaz AlamBy Mamtaz AlamUpdated:October 24, 2024136 Comments11 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Soil NPK Sensor Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this article, we will learn about the interfacing of Soil NPK Sensor with Arduino & make our own Arduino Soil NPK Meter. The soil nutrient content can be easily measured using NPK Soil Sensor & Arduino. Measurement of soil content N (nitrogen), P (phosphorus), and K (potassium) is necessary to determine how much additional nutrient content is to be added to soil to increase crop fertility.

The soil fertility is detected using NPK sensors. A major component of soil fertilizer is nitrogen, phosphorus, and potassium. The knowledge of the soil nutrient concentration can help us to learn about nutritional deficiency or abundance in soils used to endorse plant production.

There are multiple methods of measuring the soil nutrient content like using some optical sensors or using the spectrometer. But the spectral analysis method is not convenient and the drawback is the data are only 60-70% correct. While comparing the spectral analysis method with traditional wet chemistry methods, the accuracy of the products is yet to be fully resolved, given the paucity of data in that regard.

So, here we will use a JXCT Soil NPK Sensor to detect the soil nitrogen, phosphorous & Potassium in a soil. The JXCT Soil NPK sensor is a low cost, quick responsive, high precision & portable Sensor that works with Modbus RS485. The advantage of this sensor over a traditional detection method is that it gives very fast measurement & data are highly accurate. All you need is to insert its probe in soil and get the reading using Arduino. So, let’s learn in detail about the interfacing of Soil NPK Sensor with Arduino.



Bill of Materials

The components required for making a device that can help you in studying the Soil Nutrient Content is given below. You can purchase almost all the components from Amazon.

S.N.Components NameQuantityPurchase Link
1Arduino Nano Board1Amazon | AliExpress
2NPK Sensor1Amazon | AliExpress
30.96" OLED Display1Amazon | AliExpress
4MAX485 Modbus Module1Amazon | AliExpress
59-12V DC Power Supply1Amazon | AliExpress
6Connecting Wires10Amazon | AliExpress
7Breadboard1Amazon | AliExpress

Soil NPK Sensor

The soil NPK sensor is suitable for detecting the content of nitrogen, phosphorus, and potassium in the soil. It helps in determining the fertility of the soil thereby facilitating the systematic assessment of the soil condition. The sensor can be buried in the soil for a long time. It has a High-quality probe, rust resistance, electrolytic resistance, salt & alkali corrosion resistance, to ensure the long-term operation of the probe part. Therefore, it is suitable for all kinds of soil. It is suitable for the detection of alkaline soil, acid soil, substrate soil, seedling bed soil & coconut bran soil.

Soil NPK Sensor

The sensor doesn’t require any chemical reagent. Since it has High measurement accuracy, fast response speed, and good interchangeability, it can be used with any microcontroller. You cannot use the sensor directly with the microcontroller as it has a Modbus Communication port. Hence you need any Modbus Module like RS485/MAX485 and connect the sensor to the microcontroller.

The sensor operates on 9-24V & power consumption is very low. While talking about the accuracy of the sensor, it is up to within 2%. The nitrogen, phosphorous & potassium measuring resolution is up to 1mg/kg (mg/l).

Using this Soil NPK Sensor, you can make your own Arduino Soil NPK Meter or any Cloud IoT Based Soil Nutrient Content Monitoring System.

Specifications

1. Power: 9V-24V
2. Measuring Range: 0-1999 mg/kg (mg/l)
3. Operating Temperature: 5-45 °C
4. Resolution: 1mg/kg
5. Precision: ±2% F.S.
6. Output Signal: RS485
7. Baud Rate: 2400/4800/9600
8. Protection Class: IP68




MAX485 TTL to RS-485 Interface Module

The MAX485 TTL to RS-485 Interface Module allows us to use the RS-485 differential signaling for robust long-distance serial communications up to 1200 meters or in electrically noisy environments and is commonly used in industrial environments. It supports up to 2.5MBit/Sec data rates, but as distance goes up, the maximum data rate that can be supported comes down.

The data starts out as a typical TTL level serial as far as the microcontroller is concerned while the RS-485 module takes care of converting the electrical signals between TTL and the differential signaling used by RS-485. A significant benefit of RS-485 is that it supports multiple devices (up to 32) on the same cable, commonly referred to as ‘multi-drop’.


Specifications

1. Use MAX485 Interface chip
2. Uses differential signaling for noise immunity
3. Distances up to 1200 meters
4. Speeds up to 2.5Mbit/Sec
5. Multi-drop supports up to 32 devices on same bus
6. Red power LED
7. 5V operation


Pinout & Module Connection

The module has two 4-pin headers on the assembly.

1 x 4 Header (Data side)

RO = Receiver Output. Connects to a serial RX pin on the microcontroller
RE = Receiver Enable. Active LOW. Connects to a digital output pin on a microcontroller. Drive LOW to enable receiver, HIGH to enable Driver
DE = Driver Enable. Active HIGH. Typically jumpered to RE Pin.
DI = Driver Input. Connects to serial TX pin on the microcontroller

1 x 4 Header (Output side)

VCC = 5V
B = Data ‘B’ Inverted Line. Common with the B
A = Data ‘A’ Non-Inverted Line. Connects to A on far end module
GND = Ground

1 x 2 Screw Terminal Block (Output side)

B = Data ‘B’ Inverted Line. Connects to B on far end module
A = Data ‘A’ Non-Inverted Line. Connects to A on far end module




Interfacing Soil NPK Sensor with Arduino

Now, let us interface the Soil NPK Sensor with the Arduino Nano Board using the MAX485 Modbus Module. Check the connection diagram below.

Soil NPK Sensor Arduino

Connect the R0 & DI pin of from the Modbus to D2 & D3 Arduino using Software Serial. Similarly, we have to enable DE & RE high. To do this connect the DE & RE Pins to the D7 & D8 pin of Arduino. The NPK Sensor has 4 wires. The brown one is VCC which needs a 9V-24V Power Supply. The GND pin which is black in color. So connect it to the GND of Arduino. The Blue wire which is the B pin is connected to the B pin of MAX485 & the Yellow Wire which is the A pin is connected to the A pin of MAX485.

The 0.96″ SSD1306 OLED Display is an I2C Module. Connect the OLED Display VCC & GND pins to 3.3V & GND of Arduino. Similarly, connect its SDA & SCL pins to the A4 & A5 of Arduino. You can follow the circuit diagram & assemble the circuit on a breadboard or make a custom PCB.

NPK Sensor Arduino



Modbus RTU Command for NPK Sensor

Modbus commands can instruct a Modbus Device to:
1. change the value in one of its registers, which is written to Coil and Holding registers
2. read an I/O port: Read data from Discrete and Coil ports,
3. command the device to send back one or more values contained in its Coil and Holding register

A Modbus command contains the Modbus address of the device it is intended for (1 to 247). The Modbus address is also called an inquiry frame. Only the addressed device will respond and act on the command, even though other devices might receive it.

To learn more about the Modbus RTU Communication protocol, you may follow the following tutorials:

  • Modbus RTU Communication with Arduino
  • Modbus RTU Communication with ESP32
  • Modbus RTU Communication with Raspberry Pi Pico

The NPK Sensor has 3 different inquiry frame for reading the value of Nitrogen (N), Phosphorous (P) & Potassium (K). The inquiry frame is provided along with the instruction manual. For the NPK data the following individual inquiry frameworks:



1. Nitrogen: {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c}

The inquiry frame for getting Soil Nitrogen Value is:

You will get the following as a response:

You can calculate the Soil Nitrogen from the Response you receive. For example, if you get 0030 as a response then Soil Nitrogen Value will be:
0020 H(hexadecimal) = 32 (Decimal) => Nitrogen = 32mg/kg


2. Phosphorous:{0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc}

The inquiry frame for getting Soil Phosphorous Value is:

You will get the following as a response:

You can calculate the Soil Phosphorous from the Response you receive. For example, if you get 0030 as a response then Soil Nitrogen Value will be:
0025 H(hexadecimal) = 37 (Decimal) => Phosphorous = 37/kg


3. Potassium:{0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0}

The inquiry frame for getting Soil Potassium Value is:

You will get the following as a response:

You can calculate the Soil Potassium from the Response you receive. For example, if you get 0030 as a response then Soil Potassium Value will be:
0030 H(hexadecimal) =48 (Decimal) => Potassium = 48mg/kg


Source Code/Program

The source code for interfacing Soil NPK Sensor with Arduino & retrieving Soil Nutrient value from the Sensor via Modbus command is given below. You can send the command and retrieve the value in HEX Code. The HEX code needs to be converted into Decimal to get the Measured Soil Nutrient content data.

Since we are using OLED Display to display the Soil Nutrient values (Nitrogen, Phosphorous & Potassium) in mg/kg, you will need OLED Library. Download the following OLED Library and add it to the Arduino IDE.
1. Adafruit SSD1306 Library: Download
2. Adafruit GFX Library: Download

Here is the complete source code. Compile the code & upload it to the Arduino Nano Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#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
 
//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
 
byte values[11];
SoftwareSerial mod(2,3);
 
void setup() {
  Serial.begin(9600);
  mod.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(3000);
}
 
void loop() {
  byte val1,val2,val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);
  
  
  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);
 
  display.clearDisplay();
  
 
  display.setTextSize(2);
  display.setCursor(0, 5);
  display.print("N: ");
  display.print(val1);
  display.setTextSize(1);
  display.print(" mg/kg");
 
  display.setTextSize(2);
  display.setCursor(0, 25);
  display.print("P: ");
  display.print(val2);
  display.setTextSize(1);
  display.print(" mg/kg");
 
  display.setTextSize(2);
  display.setCursor(0, 45);
  display.print("K: ");
  display.print(val3);
  display.setTextSize(1);
  display.print(" mg/kg");
 
  display.display();
}
 
byte nitrogen(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(nitro,sizeof(nitro))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4];
}
 
byte phosphorous(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(phos,sizeof(phos))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4];
}
 
byte potassium(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(pota,sizeof(pota))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    }
    Serial.println();
  }
  return values[4];
}




Code Explanation

This Arduino code is designed to interact with an NPK (Nitrogen, Phosphorus, and Potassium) sensor, which are typically used to measure the levels of these nutrients in soil. This information is then displayed on an OLED screen.

1
2
3
4
5
6
7
8
9
10
11
12
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#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

This section includes necessary libraries for serial communication, I2C communication, and functionality for the OLED display. It also defines certain parameters such as screen width and height for the OLED display, pin number for reset, and pin numbers for the RE (Receive Enable) and DE (Driver Enable) pins used in RS485 communication.

1
2
3
4
5
6
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
 
byte values[11];
SoftwareSerial mod(2,3);

This part of the code declares and initializes arrays to contain byte sequences for requesting Nitrogen, Phosphorous, and Potassium readings from the sensor. It also initializes a byte array to hold response values, and a software serial interface on pins 2 and 3.

1
2
3
4
5
6
7
8
void setup() {
  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  
  //... OLED display initialization and message...
}

The setup function initializes the hardware serial port and software serial port at a baud rate of 9600. It also sets the RE and DE pins as outputs. It initializes the OLED display and shows a message.

1
2
3
4
5
6
7
void loop() {
  byte val1,val2,val3;
  val1 = nitrogen();
  val2 = phosphorous();
  val3 = potassium();
  //... Print values to the serial monitor and OLED display...
}

This is the main loop where it continually requests and retrieves Nitrogen, Phosphorous, and Potassium values from the sensor using the respective functions. It then prints these values to the serial monitor and updates the OLED display with these values.

1
2
3
4
5
6
7
8
9
byte nitrogen(){
  //... Send request, read response, return value...
}
byte phosphorous(){
  //... Send request, read response, return value...
}
byte potassium(){
  //... Send request, read response, return value...
}

These are the functions that handle sending the request byte sequences to the sensor and reading the response. They return the sensor reading values. In each function, it first sets the DE and RE pins high, indicating that it wants to write to the bus. Then it sends the request byte sequence for the respective nutrient. After sending, it sets DE and RE low, indicating that it wants to read from the bus. It then reads the response from the sensor into the ‘values’ array and returns the value of interest.

Note: The code is the only capable of measuring the Soil NPK values up to 255mg/kg. This is because we are only reading 8bit value. According to the datasheet of the Sensor, you can measure the value up to 1999mg/kg. To read such value we have to read 16bit data. Refer to the Soil EC Sensor Code to read such high values.




Monitoring Soil NPK Data on OLED Display

Once you upload the code to Arduino Nano Board, the OLED will initialize along with the sensor. The sensor will take some time for stability and the reading may be incorrect initially.

Once the sensor gets becomes stable, you can dip the sensor in the soil to get the NPK Reading. The volume of Nitrogen, Phosphorous & Potassium which are the Ammonium content in the soil will be displayed as mg/Kg.

 Soil NPK Meter Arduino

So this is how you interface Soil Nutrient Sensor Arduino & get the NPK Readings. Similarly, put the sensor in different samples of soil. You will see a variation in the volume of NPK depending upon the type of soil.

Soil NPK Sensor Arduino


Video Tutorial & Guide

Follow the following video to learn about the entire project & code information.

DIY Soil NPK Meter || Measure Soil Nutrient Content using Soil NPK Sensor & Arduino
Watch this video on YouTube.

Apart from measuring Soil NPK, you can also measure Soil Moisture Content using Soil Moisture Sensor, Soil Ph using Soil Ph Sensor & Soil EC & Salinity using Soil EC Sensor, which is explained in my one the previous post.

Thus, you can make your own Arduino Soil NPK Meter using the above guide & determine the fertility of the soil. You can also check the advanced version of this project. In the advance version, you can combine Soil NPK Sensor, Temperature Sensor & Soil Moisture Sensor with Arduino: IoT Based Soil Nutrient Monitoring.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT Industrial Temperature Monitor with MAX6675 & ESP8266
Next Article Electromyography(EMG) with MyoWare Muscle Sensor & Arduino

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 136 Comments

136 Comments

  1. myominhtet on December 1, 2020 10:59 AM

    can u read the npk modbus sepcification on the modbus scanner

    Reply
    • Mr. Alam on December 1, 2020 11:07 AM

      Maybe.
      I haven’t tried it. You can try and let us know.
      Thanks.

      Reply
  2. Myo min hyet on December 3, 2020 4:46 PM

    Yeah i can but i cant even know what the values are and there is some chinese words.I used CAS modbus scanner. Does the npk values show on serail montior coz i cant read the values thanks

    Reply
  3. Hussnain Uz Zaman on December 26, 2020 2:39 AM

    i created this same project a year ago. this sensor has pc software where you can configure everything of modbus. even address of you sensor and baund rate also.

    Reply
  4. Apofis on January 20, 2021 8:47 PM

    This sensor can be use to detect NPK in water?

    Reply
    • Mr. Alam on January 20, 2021 8:48 PM

      Nop. This sensor is designed for soil only.

      Reply
  5. Apofis on January 21, 2021 12:47 PM

    thx for your answer. Do you know if there is an NPK sensor for water?

    Reply
  6. Azhar on January 24, 2021 3:23 PM

    Have you compared its results with soil analysis of lab. I couldn’t find any research material related to testing of soil with this method.

    Reply
  7. myominhtet on February 6, 2021 8:53 AM

    can upgrade this project like soil npk recommendation with esp32 or something u could.

    Reply
  8. Jacob Fondevilla on February 6, 2021 7:45 PM

    Based on the result of the sensor, what it would be if it is converted on percentage?

    Reply
    • Mr. Alam on February 6, 2021 7:47 PM

      You can convert mg/kg into percentage. For example 130mg/1kg= 0.13gm/1000gm which is equivalent to 0.013%.

      Reply
  9. Srish S on February 9, 2021 8:38 AM

    Respected Mr. Alam,
    I am an computer science engineering student from Bangalore. I am in need of this sensor for my final year project and on searching for it, it doesn’t seem to be available anywhere and it is also very expensive. Is there anyway you could help us in this regard. I could return it right after the project is done. This is the most important component of the project and without it i won’t be able to do my project. I request you to help me out in this regard.

    Reply
    • Mr. Alam on February 9, 2021 8:57 AM

      You can get these sensors on aliexpress.

      Reply
  10. Gilbeys Jhon Ladion on February 10, 2021 10:37 AM

    Hi I tried to this but I only get 255, what could be the problem?

    Reply
  11. Gilbeys Jhon Ladion on February 10, 2021 11:49 AM

    By the way i’m using uno.

    Reply
  12. Aisha on February 10, 2021 3:15 PM

    Have you resolved the issue?

    Reply
  13. Aisha on February 10, 2021 3:17 PM

    Have you resolved the issue? I am also getting the same output

    Reply
  14. Mr. Alam on February 10, 2021 3:25 PM

    The reason that most of the people are getting 255 or 0 as output for all N, P & K values:
    1. Wrong connection of DI, DE, RE, RO with respect to code
    2. MAX485 Module should be powered via 5V & should have common GND
    3. The NPK Sensor needs 9V or 12V or more. Supply appropriate voltage to its VCC pin. The sensor won’t operate at 5V or anything lesser than 9V.
    4. Check the Slave address of NPK Sensor with respect to the datasheet or manual provided by manufacturer. The sensor will only give correct output if the address is correct. You can also contact the manufacturer for support.

    Reply
  15. Gilbeys Jhon Ladion on February 11, 2021 9:22 AM

    How long will the sensor stabilized? The nitrogen is now reading properly. but the P and K is not reading yet.

    Reply
  16. Monir on February 17, 2021 6:05 AM

    I need this sensor I,m from Bangladesh please help me

    Reply
  17. Edward Gordon Sagun Jr on February 28, 2021 4:46 AM

    Have you solve this problem yet?

    Reply
  18. Edward Gordon Sagun Jr on February 28, 2021 4:47 AM

    Have you resolve this issue. Cause i have the same problem tnx for answering

    Reply
  19. Roger on March 5, 2021 6:12 PM

    someone has tested it and confirms that it gives the data well?. thanks

    Reply
  20. Naim on March 8, 2021 8:43 PM

    Hi, is it possible to set up the NPK sensor with NodeMCU?

    Reply
  21. Naim on March 8, 2021 8:49 PM

    Hi mr Alam, can I use this sensor with NodeMCU?

    Reply
    • Mr. Alam on March 8, 2021 9:07 PM

      You can try. I was unable to get the result.

      Reply
  22. Juan mateu on March 11, 2021 2:10 PM

    Hi great job, it gives me an error while compiling.

    Usando librería SPI con versión 1.0 en la carpeta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
    exit status 1
    Error compilando para la tarjeta Arduino Nano.

    Reply
  23. shorn on March 28, 2021 1:33 PM

    i have questions. 1. should i purchase the npk sensor shown on the blog which is now 285 usd on amazon.
    . the same kind of npk sensors are sold in ebay for 90 usd. WHY it is so much different in price. are they same!
    2. i am learning hydroponics. why Mr. Alam said it can’t be used in fluid and only in soil. although its designed to use in soil the readings must be slightly offset. in otherwords there must be an approximate value shown which has somewhat direct relation to the npk content in hydroponic solution. this will be more than satisfactory for optimizing. further optimization may be dealt with ion specific electrodes.

    also, how is the working principle. is it using same principle as EC.
    in the diagram, the OLED vcc IS IT connected to ardrino pin and not main power supply of 5+v

    thanks

    Reply
    • Mr. Alam on March 28, 2021 1:44 PM

      You can buy this sensor from eBay if the sensor is the same. The price in Amazon is just so high. You can get the sensor at around 60$ from Chinese sites like aliexpress or Alibaba.
      The sensor is designed for measuring soil NPK value, not the water. I already checked with water, the result is not so good as expected. The working principle is based on ionization same as Electrical Conductivity.
      The OLED works at 3.3V and 5V too. It’s better to connect the OLED to 3.3V to reduce power.

      Reply
  24. Carson Can on March 30, 2021 2:07 AM

    Can anyone confirm the +/- 2% accuracy? As well can the probes be bent and still be functional or will they be off. Thanks

    Reply
  25. shorn77777 on April 3, 2021 8:56 AM

    Thanks Alam,

    const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
    const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
    const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};

    are these inquiries standard. or do we need to modify according to the sensor.

    Reply
    • Alex Newton on April 3, 2021 9:00 AM

      Modify the inquiry bit according to your sensor manufacturer. These are standard for most of the sensors. But it may vary for some sensors.

      Reply
  26. shorn77777 on April 3, 2021 11:02 AM

    if(mod.write(nitro,sizeof(nitro))==8){
    does it mean if we get a reply from the modbus rs485 for our inquiry frame nitro, meaning mod.write if its true does it mean we are receiving a response frame. are the receiving pins standard. the rest i understand it as if the size is 8 bit then so and so.

    for(byte i=0;i<7;i++){

    which location the response value is received or saved.

    C++
    1
    2
    3
    <code>//Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    </code>

    is it here.

    and where is it getting converted from hex to readable format.

    C++
    1
    2
    3
    4
    <code>Serial.print(values[i],HEX);
    }
    Serial.println();
    </code>

    }
    return values[4];

    one more thing Alam the receiving info is stored under 4th place. i want to know how the response info is saved and is it replacing the inquiry frame.

    Reply
  27. Rohit on April 8, 2021 2:38 PM

    How do you power up the npk sensor. Can you please help me for that ? Thank you

    Reply
    • Alex Newton on April 8, 2021 2:42 PM

      Power it using external 9V supply. You can use a 12V battery or a 9-12v DC Adapter

      Reply
  28. Paul on April 8, 2021 11:51 PM

    I’m sorry, I have tried 9v and 12v and I’m still getting a 255 value. I believe I’m correct in steps 1-2 as well.
    I have looked into “Soil EC Sensor Code” but remain unclear for me how do I read 16bit data.
    Additionally, what do you mean by “Slave address” in step 4 ?

    Reply
  29. Carson on April 10, 2021 9:17 AM

    Mr. Alarm can you respond?

    Reply
    • Greg on June 18, 2021 4:33 PM

      Hi Carson,

      I am unsure about this products specificity. The sensor is not accurate . I have experimented with some potting soil and the results are way off. The potting soil bag sais that nutrient levels are as follows N= 160-300 mg/kg ; P = 80-140 mg/kg ; K = 160- 260 mg/l.

      The result from the sensor without adding water: N: 26-27 mg/kg ; P: 10-11 mg/kg; K: 9- 10 mg/kg .
      The result from the sensor water (added 100 ml to 166 g of soil): N: 133-134 mg/kg ; P: 54 mg/kg; K: 50 mg/kg .

      Reply
  30. Peter Snoc on April 10, 2021 8:42 PM

    Hi,

    I do not understand the section of the wiring explaining :

    DE = Driver Enable. Active HIGH. Typically jumpered to RE Pin.

    Does it mean we should connect DE with RE ? this is not shown on the diagram image.

    Additionally, I’m trying to figure out as well why I’m getting a fixed value of 255.
    I’m using your code and an Arduino Uno board.

    Please could you clarify as you obviously know the caveats and did not give enougt details.

    Reply
  31. Ronald Morrison on April 17, 2021 3:00 AM

    Not everything works the same. I used an Arduino Nano and to get it to read the values of NKP I connected the D2 pin to the RX, the D3 to TX and removed the wired from D8 leaving the wire from RE on the RS485 adapter board attached to D7. I powered my unit from a lithium 12 battery to make it mobile by using that input on vin.

    Reply
  32. Ronald Morrison on April 18, 2021 9:09 PM

    Well, that was wrong. That change got it to always read ~51 on all 3. On my Arduino Nano, when I put an LED and resistor between D2 and ground the LED will always be on but with some flashing. With the LED plus resistor I get zero’s on all 3 parts of the display but it won’t read the values.

    Reply
  33. Solomon Ben on April 18, 2021 11:19 PM

    You can either enable it HIGH using the Arduino Digital Pin via Code. Or you can simply Short the DE & RE Together. In my case I enabled it high using the Arduino Digital Pin

    Reply
  34. Ronald Morrison on April 19, 2021 1:05 AM

    Which “it” do you enable high?

    Reply
  35. Garfield on April 19, 2021 5:36 PM

    same problem here (only 0xFF)… using mega 2650.
    Did you get it solved?
    BTW i sniffed the rs485 and after sending a 0D 0A (CR and LF) are send out by the arduino and sensor.

    Reply
  36. Piet Moenen on April 19, 2021 10:19 PM

    0xFF problem Solved…

    https://www.arduino.cc/en/Reference/softwareSerial
    Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

    Pins used to transmit must be of the type PCINT. very very annoying

    Reply
    • Alex Newton on April 19, 2021 10:21 PM

      Very right. Those pins which accept interrupt can only be used for Software Serial.

      Reply
    • Garfield on April 19, 2021 10:37 PM

      Garfield = Piet Moenen
      Elaboration: I used a 2560 and connected the DI and RO to pin 3 and 2. All i received was FF. The data transmitted was correct. (sniffed with PC (accessPort.. hence the CR and LF))
      After connecting DI and RO to pin 11 and 10 on the Mega 2560 and changing the code to
      SoftwareSerial mod(10,11);
      all was well.

      Although… after wattering the soil, the values change… so the question is… are NPK sensors any good? Do they measure the NPK values accurately?

      Reply
  37. Paul on April 20, 2021 12:06 AM

    Hello,

    It seems I’m having the same “FFFF” or 255 value. I’m using an Arduino Uno, are there any restrictions ?
    I have tested both : pins 3, 2 and pins 11, 10 (and updating code accordingly). According to my documentation, pins 3&2 should be compatible with interrupt.

    Any idea ?

    Reply
    • Ronald Morrison on May 24, 2021 1:56 AM

      Soldering the connections to the Arduino Uno seems to have solved the 255 problem for me. I must have been having connection problems with the breadboard. I have it wired exactly as the diagram shows for the Arduino Nano but with the Uno..

      Reply
  38. Garfield on April 30, 2021 3:38 PM

    You could connect a PC to the RS485 wires and sniffer the data… is that data also FF?
    You can also inject data from the PC in the RS285.

    Reply
  39. Frank on May 17, 2021 12:42 AM

    Hi, I have the same problem, were you able to solve?

    Reply
  40. MihneaStoica on May 18, 2021 12:59 PM

    I can confirm that the above tutorial is correct but the sensor does not measure directly the NPK content of the soil. By using benchmarking solutions of 50ppm N-NO3, 7ppm N-Nh4 and a few others + 2 samples of soil whose NPK content was determined using spectrophotometry, i have determined that this sensor is nothing more than an Ec sensor. If you wish to measure such thing, you can find way cheaper solutions out there and can infer the NPK content ( just like this sensor does) of the soil.

    Reply
  41. Ronald Morrison on May 24, 2021 1:52 AM

    When I made solder connections I started getting reasonable readings but only when the soil was wet.

    Reply
  42. Ronald Morrison on May 27, 2021 12:03 AM

    I have had success with measuring the NPK levels in my field by taking multiple samples at different locations. The OLED was nearly impossible to read in the sunlight so I brought the samples into my house in ziplock bags. The soil was dry so I used distilled water to wet it well. Inserting the probe and waiting until the reading quit changing gave me believable if not totally accurate numbers. I tried using tap water for the samples also and got wildly varying numbers depending on the type of soil. This will now give me a good basis for ordering fertilizer for my fields, making the project worth far more than its cost.

    Next to attempt is to use a Lilygo e ink display mounted to an ESP32 so I can just go around the fields and measure.

    Reply
    • Alex Newton on May 27, 2021 12:05 AM

      Nice to know you are satisfied and worked fine for you. God bless you. Do let us know the result, in future with ur fertiliser.

      Reply
  43. firsinapulia on June 3, 2021 3:53 AM

    did you solve the problem in the end?

    Reply
  44. Abdullah Al Araf on June 13, 2021 1:33 AM

    I do not know what I have done wrong, I only get:

    nitrogen value 255 mg / kg
    Phosphoro Value 255 mg / Kg
    Potassium Value: 255 mg / kg

    Reply
  45. firsinapulia on June 13, 2021 7:56 PM

    I returned the sensor and bought a new one. Now everything works

    Reply
    • Alex Newton on June 13, 2021 7:56 PM

      Congratulations. Glad to know it worked for you.

      Reply
  46. Branden on June 14, 2021 8:45 PM

    I am trying to find ways to make the sensor more space efficient. Would it damage the sensor if you cut/sharpen the prongs. Also, would it be possible to remove the casing of the sensor and stripping it down to just the prongs and connections?

    Reply
  47. MihneaStoica on June 16, 2021 7:05 PM

    I would advise you to compare your readings to a lab analysis. Maybe reach out to a nearby university of agronomy or agrochemistry and ask for their help. That’s what i did and found out that this sensor just infers the quantity of N P K in the soil and it has really unreliable results ( it probably just measures the electrical conductivity of the soil).

    Reply
    • Alex Newton on June 16, 2021 7:10 PM

      Thank you so much for the clear explanation and letting us know about the results given out by this sensor. We will compare the results of this sensor with the chemistry lab result and share the results here.

      Reply
    • Greg on June 18, 2021 4:52 PM

      I totally agree with MihneaStoica. I have compared the readings from potting soil and sand and the results do not look promising. Sand: N: 71mg/kg ; P: 29mg/kg ; K: 26 mg/kg. If I am to believe these results, then I could harvest 5 t/ha of wheat from sand, which is impossible because of sands low CEC

      Reply
  48. Greg on June 18, 2021 4:28 PM

    Hi Carson,

    I am unsure about this products specificity. The sensor is not accurate . I have experimented with some potting soil and the results are way off. The potting soil bag sais that nutrient levels are as follows N= 160-300 mg/kg ; P = 80-140 mg/kg ; K = 160- 260 mg/l.

    The result from the sensor without adding water: N: 26-27 mg/kg ; P: 10-11 mg/kg; K: 9- 10 mg/kg .
    The result from the sensor water (added 100 ml to 166 g of soil): N: 133-134 mg/kg ; P: 54 mg/kg; K: 50 mg/kg .

    Reply
  49. Jacob Fondevilla on June 19, 2021 8:22 PM

    Hi Mr. Alam, thank you for answering my question.
    May I have a request? Can you give me a pseudo code of the NPK sensor?

    Reply
  50. chamroeun on July 19, 2021 11:50 AM

    Hi,
    How to wire multiple RS485? I heard it can support up to 32 devices. But do we need separate MAX485 for each devices and how the wiring will work and how about the code?

    Thanks;

    Reply
  51. araf on July 29, 2021 2:30 PM

    I do not know what I have done wrong, I only get:

    nitrogen value 255 mg / kg
    Phosphoro Value 255 mg / Kg
    Potassium Value: 255 mg / kg

    please help me

    Reply
  52. Riaz Ahmed on August 16, 2021 2:50 PM

    Hi, some great work by you Alex/Alam. I also found that the registry codes given in the manual of JXCT NPK sensor I purchased via AliExpress from JXCT shop was incorrect. I tried your codes and it works. However I found the results somewhat confusing. In a pure soil the values of N=84 P=26 K=36. I added a dilute solution of Ammonium Nitrate and the values moved to 189/59/81. Next I added a garden food chemical that says its N/P/K is 20/20/20 percent and the values moved to 138/121/168. I again added Ammonium Nitrate and the values moved to 170/52/74 . So the addition of AmNit causes N/P/K to rise to nearly double. the addition of garden food chemical causes N to fall but P/K rise a lot. But the addition of AmNit again causes the N to rise but P/K to fall to nearly half….Are we really measuring NPK or just Electrical Conductivity. Can you answer.

    Reply
    • Admin on August 16, 2021 2:52 PM

      The device is internally programmed in such a way that the NPK represents the electrical conductivity of particular sample. And moreover the sensor can only give the accuracy of around 70%.

      Reply
  53. Riaz Ahmed on August 16, 2021 11:51 PM

    How internally programmed?

    Reply
  54. Riaz Ahmed on August 16, 2021 11:59 PM

    And also, is this the concept on which the JCXT NPK sensor is based? https://aip.scitation.org/doi/abs/10.1063/1.5142147

    Reply
  55. Rasika amarakith kumarage on August 22, 2021 2:15 PM

    Please let me advice , can i check liquid fertilizer npk.

    Reply
  56. Riaz Ahmed on September 1, 2021 1:04 AM

    Finally I tested through various chemical and conductivity tests and have come to the conclusion that these JXCT type NPK sensors are actually not measuring NPK but they measure soil electrical conductivity and this is then taken as a measure of Nitrogen. Next the so called microcontroller inside does is to use a straight line equation that uses solpe and intercept of Nitrogen vs EC plot and predicts Phosphorus and Potassium. No matter what you add the sensor will always give Nitrogen>Potassium >Phosphorus. If your soil has 46‰ urea and zero percent P and K the JXCT type will show Nitrogen as 200 and K nad P as 60 and 80. That is with no K and P the sensor will show they are! The 8 bit output means after N going over 255 the K nad P will be 90 and 120 but N will show 30, that means its the residual of the 8 bits appearing to show less N. If you use the K data and plot it against N then you get a straight line equation which can then be used to Predict N and then you can calculate N as 330 where K and P are 90 and 120. In short, buy a $12 at https://www.dfrobot.com/product-1662.html and $7 at
    https://a.aliexpress.com/_m0s5yU7 . Do not waste $70-90 on these duped JCXT sensors when you can yourself use EC as a measure of N. However no sensor based on EC can give you K and P because thats a myth.

    Reply
    • Admin on September 1, 2021 1:45 PM

      Thanks for all these tests and information and for letting us know about the capability of this sensor.

      Reply
  57. Riaz Ahmed on September 1, 2021 1:59 AM

    Instead of spending $70 use dfrobot TDS sensor and board for $7 at Aliexpress and measure electrical conductivity, EC, as a measure of Nitrogen. This JXCT type sensors are fraud, they actually are cheap EC sensors build as if they measure NPK. Instead these use EC to approximate Nitrogen and then calculate Pand K from Nitrogen! Your solution may have no P or K but these will always show them. If you add say 400ppm of N then the JXCT type will show K as 200 and P as 180 even though your solution will have zero P nad K. So dont be fooled, buy cheap TDS sensor!

    Reply
  58. jesus armando camacho felix on September 4, 2021 4:37 AM

    FOR ESP32
    #include <LiquidCrystal.h>
    #include <WiFi.h>
    #include <EEPROM.h>
    ////////////////////////////////////////////////////////////////////////
    // Definimos las constantes
    #define COLS 20 // Columnas del LCD
    #define ROWS 4 // Filas del LCD
    #define RS 13
    #define EN 12
    #define D4 14
    #define D5 27
    #define D6 26
    #define D7 25
    LiquidCrystal lcd(RS ,EN,D4,D5,D6,D7);
    ////////////////////////////////////////////////////////////////////////
    TaskHandle_t Task1;
    TaskHandle_t Task2;
    TaskHandle_t Task3;
    WiFiServer *Servidor;
    WiFiClient client;
    String cadena;
    boolean cliente=false;
    const byte NITROGENO[]={0x01,0x03,0x00,0x01e,0x00,0x01,0xb5,0xcc};
    const byte FOSFORO[]= {0x01,0x03,0x00,0x01f,0x00,0x01,0xe4,0x0c};
    const byte POTASIO[]= {0x01,0x03,0x00,0x020,0x00,0x01,0x85,0xc0};
    ////////////////////////////////////////////////////////////////////////
    void MENU(void *pvParameter);
    void SERVIDOR(void *pvParameter);
    void LECTURAS(void *pvParameter);
    int lectura(const byte trama[]);
    /////////////////////////////////////////////////////////////////////////
    // Create An LCD Object. Signals: [ RS, EN, D4, D5, D6, D7 ]
    void setup()
    {
    Servidor=new WiFiServer(25);
    Serial.begin(9600);
    WiFi.mode(WIFI_AP);
    WiFi.softAP(String(“AGROLINK”).c_str(),String(“12345678”).c_str());
    Servidor[0].begin();
    lcd.begin(20,4);
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.printf(“BIENVENIDO AL NPK”);
    lcd.setCursor(1,1);
    lcd.printf(” SCOPE”);
    IPAddress IP = WiFi.softAPIP();
    xTaskCreate(MENU,”MENU”,5024,NULL,2,&Task1);
    xTaskCreate(SERVIDOR,”SERVIDOR”,5024,NULL,2,&Task2);

    }
    void loop()
    {

    }
    ///////////////////////////////////////////////////////////////////////////
    void MENU(void *pvParameter)
    {
    while(true)
    {

    C++
    1
    2
    <code>delay(1);
    </code>

    }
    }
    ///////////////////////////////////////////////////////////////////////////
    void SERVIDOR(void *pvParameter)
    {
    while(true)
    {
    client = Servidor[0].available();
    if(client)
    {
    Serial.println(“New Client.”);
    while (client.connected())
    {
    if (client.available())
    {
    cadena=client.readStringUntil(‘\n’);
    if(cadena.equals(“ESCANEAR”))
    {
    cliente=true;
    if(Task3==NULL)xTaskCreate(LECTURAS,”LECTURAS”,5024,NULL,2,&Task3);
    }
    else if(cadena.equals(“STOP”))
    {
    cliente=false;
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.printf(“BIENVENIDO A AGROLINK”);
    lcd.setCursor(1,1);
    lcd.printf(” SCOPE”);
    }
    client.flush();
    cadena=””;
    }
    }
    }
    delay(1);
    }
    }
    ///////////////////////////////////////////////////////////////////////////////////
    void LECTURAS(void *pvParameter)
    {
    while(true)
    {
    if(cliente)
    {
    // client.println(“ENCENDIDO”);
    client.println(“N: 0p/m,K: 0p/m,P:0p/m,PH:0,T:0″);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.printf(” OBTENIENDO”);
    lcd.setCursor(0,1);
    lcd.printf(“PARAMETROS DE SUELO”);
    lcd.setCursor(0,2);
    lcd.printf(“N:0p/m,K:0p/m,P:0p/m”);
    lcd.setCursor(0,3);
    lcd.printf(“PH:0,Temp:0”);
    delay(500);
    }
    delay(1);
    }

    }

    Reply
  59. Bernardo on September 27, 2021 10:35 PM

    That is what i am getting as well….did your fix the problem?

    Reply
  60. emu on September 29, 2021 5:46 AM

    Thank you for this information, I’ve implemented parts of it in a project that uses a simimlar unit, but has 5 spikes rather than 3.
    I’m wondering if you know the polynomial used to compute the CRC bytes, (high and low), since they need to be incorporated into the inqury frame – the unit you’re using here has the CRC byes explicitly detailed in the documentation so the way they’re calculated isnt revealed, but in the documentation for the 5 – spike unit, there is no information on how the CRC bytes are computed.

    In your case, requesting from register 1e uses CRC bytes e40c – how are those CRC bytes determined?

    Reply
  61. Alex True on October 2, 2021 3:52 AM

    get only 0xFF as response … wiring checked. using arduino nano. Voltage also checked at 12.5V.

    Reply
  62. ify on October 12, 2021 9:52 PM

    Good day. Please can anyone explain what this means please?

    Arduino: 1.8.15 (Windows 10), Board: “Arduino Nano, ATmega328P”

    Sketch uses 16592 bytes (54%) of program storage space. Maximum is 30720 bytes.

    Global variables use 755 bytes (36%) of dynamic memory, leaving 1293 bytes for local variables. Maximum is 2048 bytes.

    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

    An error occurred while uploading the sketch

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    Reply
  63. BIBE 💞 on October 15, 2021 7:11 PM

    Can I ask sir If we can used it in determining the npk content in plant leaves? This will be a great help if you reponse. Thank you

    Reply
    • Admin on October 15, 2021 7:12 PM

      Not at all. The sensor is only designed for soil. You spectral sensor like AS7265x to measure the NPK content in leaves or something else.

      Reply
  64. BIBE 💞 on October 16, 2021 6:43 PM

    Thank you so much sir. Can I ask again sir if How much is the expected price of the spectral sensor like AS7265x

    Reply
  65. BIBE 💞 on October 16, 2021 7:34 PM

    Sir do you have any reference that spectral sensor like AS7265x can measure the NPK content of leaves?. Thank you so much sir for your responce

    Reply
  66. BIBE 💞 on October 17, 2021 9:10 AM

    Sir do you have any reference regarding that spectral sensor like AS7265x can detect the NPK content of plant leaves? Hope you consider my question. Thank you so much in advance

    Reply
  67. Alejandro Espinel on October 19, 2021 11:17 PM

    ify, tienes que seleccionar la opcion ATmega 328 (Old Bootloader) para poder cargar el programa en el nano. Otra opcion es que estes utilizando el puerto serial (pines 0 y 1) conectados a algun dispositivo y estes tratando de cargar el programa por el puerto USB, lo cual entraria en conflicto ya que son el mismo puerto y por eso no te deja cargar el programa, tendrias que desconectar el dispositivo de comunicacion provisionalmente mientras descargas el programa y despues conectarlo nuevamente.

    Reply
  68. abreham on October 21, 2021 11:03 PM

    any one able to send the soil npk sensor library for proteus

    Reply
  69. Hyunwoo on October 26, 2021 1:29 PM

    I also had a problem with communication not working properly.
    As a result of testing for several days, when I change the baud rate of Software Serial to 4800, the data comes in normally.
    mod.begin(9600); —> mod.begin(4800);

    Reply
  70. TNKHOA on November 24, 2021 9:14 PM

    i have had success using esp8266 to connect to rs485 and display on screen (including web server/blynk). And it is working perfectly. The power supply for it is only 5v (using the same 5v power supply for both npk sensor and esp8266). I have some pictures

    Reply
    • Admin on November 25, 2021 11:10 AM

      Can you share your code and pictures along with some documentation to our mail address: [email protected]. We will like to publish your work on our website with your name.

      Reply
  71. Predrag on December 7, 2021 9:38 PM

    Hi, does anyone have a pdf of that npk soil sensor? tnx

    Reply
  72. atjamil on December 15, 2021 7:15 PM

    Hi TNKHOA,
    Can you share your code to me ([email protected])?
    Thanks!

    Reply
  73. Riaz Ahmed on December 21, 2021 12:26 PM

    Hi, I purchased SEM225 6in1 sensor. It works fine with UART Assistant and gives proper values. However when using ESP32 or Atmega328P and your program here it gives wrong values. If temp and moisture only are sought the values are something, when nitrogen or ph is added to be sought the values of temp and moisture change. Any idea why this is happening?
    The baud rate is 4800, the serial works at 9600.

    Reply
    • Admin on December 22, 2021 1:49 AM

      Even i tested the same sensor in the past and got the same result what you are telling. The reason is signal isolation, one sensor is disturbing the other one.

      Reply
  74. Arunesh on January 6, 2022 6:58 PM

    Hello Sir , I have tried NPK sensor with Arduino UNO and it’s working correctly. But when I am using NPK sensor with Arduino UNO along with LoraShield module , I am not getting the result ; it’s showing 255 only. Could Anyone Help me with this?

    Reply
  75. Nazion Filho on January 20, 2022 12:01 AM

    Amigo quando você fala “onde você pode configurar tudo em Modbus. A pergunta é ? tem como configurar para os outros nutrientes como: Cálcio , Magnésio , Enxofre , Boro , Zinco , Ferro , Manganês , Molibidênio , Níquel e Cobalto.

    Reply
  76. Ronald Morrison on January 23, 2022 7:55 PM

    Your LORA shield needs digital pin 8 on your Arduino Uno. That pin is also needed for the NPK sensor. See line Line 11 in your Arduino IDE where it says, “#define RE 8” You could try changing that from 8 to 9 and see if that works.

    Reply
  77. phenom615 on January 31, 2022 10:10 PM

    please drop your email address, i want to contact you urgently regarding ion selective electrodes. [email protected]

    Reply
  78. phenom615 on January 31, 2022 11:45 PM

    please, kindly drop your email address for me. I want to contact you regarding ion selective electrodes. thanks. Mine: [email protected]

    Reply
  79. Abhishek Nilesh Parekh on February 19, 2022 9:34 PM

    I am working on this project but using MSP430 board and getting few errors.Can you help me with that sir?

    Reply
  80. Dub_35k on March 8, 2022 1:56 PM

    Hello guys, I’m a big fan of your projects. A massive thank you.

    In this precise project, in my case the measurment has significant changes almost every 5 seconds. I don’t know if this sensor need a little time gap to stablish. Could be a baud rate problem, maybe the sensor is damaged…

    Reply
  81. alberto elcullada on March 20, 2022 8:56 PM

    Good Day Mr. ALam I have problem running npk sensor in ttgo t-call esp32 sim800l the problem is that no pinout no tag given in the code can you help me

    Reply
  82. farmer@will on April 4, 2022 9:34 AM

    No accuracy at all. It’s based on EC and using mathematical conversion to N,PK. Even their own manufacturer also said like this. You can try to put Urea fertilizer(Pure nitrogen) and you will see that the N is still the same while PK increase instead.

    Reply
  83. farmer@will on April 4, 2022 1:23 PM

    No accuracy at all. It’s based on EC and using mathematical conversion to NPK. Even their own manufacturer also said like this. It’s waste of time and money with this one and can have a dangerous consequence if you follow its result.

    I even buy these Chinese made N/P/K tube(3 separate tubes) sensor with LCD. But the result are just the same as this 3 in 1. So the bottom line is they are all scam.

    Reply
  84. farmer@will on April 4, 2022 1:52 PM

    No accuracy at all. It’s based on EC and using mathematical conversion to NPK. Even their own manufacturer also said like this. It’s waste of time and money with this one and can have a dangerous consequence if you follow its result.

    Reply
  85. farmer@will on April 6, 2022 7:45 AM

    @Riaz Ahmed,
    How sure are you that JCXT uses this concept? I tested several of this sensors and all of them give very inaccurate result. I use Urea fertiliizer on the soil but the sensor read high value of K instead of N. I think it’s based on EC and convert the result to NPK.

    Reply
  86. Muzna on April 16, 2022 4:21 PM

    Can someone please guide why i am getting 255 for all values? i have rechecked my connections as per directions several time. Also i am using the inquiry frame from the manufacturer still i am having this issue. Please guide

    Reply
  87. Navid on May 18, 2022 12:05 PM

    Do you remember the name of the software?

    Reply
  88. Ovidiu on June 7, 2022 12:34 AM

    I performed 10 laboratory tests and compared the same samples with the sensor. The values delivered by the sensor are not even close to the laboratory values. Also, the values vary a lot with the soil moisture.

    Reply
  89. Navid on June 12, 2022 11:08 AM

    Hello. I had a question, what kind of soil does the soil npk sensor read better? Dry soil? Or wet soil? What percentage should the soil moisture be?

    Reply
  90. Mike on June 23, 2022 7:18 PM

    hi, thanks for your heads up. it worked for me, but i have a quick question. why dont it work with arduino mega hardware serial communication.

    Reply
  91. Diego Valdivia on June 30, 2022 4:33 AM

    Can someone help me with the code to read values ​​greater than 255, how can I read up to 1999 mg/kg as indicated in the sensor datasheet?

    Reply
    • Admin on June 30, 2022 7:36 AM

      Read the article properly. A method is already mentioned and a link is already attached on reading the value upto 1999.

      Reply
  92. megt12 on August 11, 2022 2:08 PM

    Did you fix it? I’m having the same issue, getting only 255. I’m using esp8266.

    Reply
  93. megt12 on August 11, 2022 2:08 PM

    Hey! Did you fix it? I’m also getting 255 and have been stuck here for some days!!

    Reply
  94. megt12 on August 11, 2022 2:16 PM

    Hi Admin, is there a solution to getting only 255 values? I’ve been stuck here for a couple of days unfortunately and followed all the steps in the guide and in the comment. I’m using Nodemcu with 8266. Thank you!

    Reply
  95. Dicko on August 12, 2022 4:09 PM

    Hi Guys, I have the same problem — getting 255. I have purchased the 3.3V version of this device.
    I am using an Arduino WAN 1310 and a MAX3485 with the NPK sensor and getting 255.
    If someone has fixed the 255 error, please could they share the details.

    Thanks

    Reply
  96. dicko on August 12, 2022 4:27 PM

    I am facing the same problem with getting 255.
    I am using a 3.3V version of the NPK sensor with an Arduino WAN 1310 and a MAX3485 transceiver.

    Any help would be appreciated, thanks.

    Reply
  97. aseem Kukkar on August 18, 2022 4:49 AM

    hlo sir i had request/question if i could use this sensor with arduino mega

    Reply
  98. Bijaylakhmi Goswami on August 26, 2022 6:07 AM

    Does JXCT 7 in 1 sensor detects EC and then mathematically converts to nitrogen? How accurate are pH and EC data? Kindly respond.

    Reply
  99. roydb48123f825b on September 7, 2022 4:34 PM

    How does this sensor differentiate between the 3 ions in soil? Normally done via ISFETS or Ion selective electrodes, this just looks like an EC probe? thanks

    Reply
  100. Subas on September 25, 2022 10:11 PM

    Dear Sir.

    If i have 4 Soil NPK Sensor, how do i read the individual sensor using the Arduino code. Could you please advice?

    Reply
  101. musa on October 24, 2022 6:15 PM

    Ask the seller you bought it from. It should give you the codes for each query.

    Reply
  102. Nabeel Hasnain (@HasnaiNabeel) on December 31, 2022 8:37 AM

    Did you solve the output? please share the details with me, that will be appreciated
    Twitter @HasnaiNabeel

    Reply
  103. nvmdesai on January 8, 2023 4:43 PM

    I downloaded the libraries and I copied the code, but for some reason I’m getting a compilation error related to the libraries. Could you add the download link to the file, rather than the github repository link? For some reason, the library isn’t getting called by the code.
    Error:In file included from /Users/namanmutalikdesai/Documents/Arduino/NPK_Sensor_Program_2/NPK_Sensor_Program_2.ino:1:0:
    /Users/namanmutalikdesai/Documents/Arduino/libraries/Adafruit-GFX-Library-master/Adafruit_GFX.h:12:10: fatal error: Adafruit_I2CDevice.h: No such file or directory
    #include
    ^~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1
    Error compiling for board Arduino Uno.

    Reply
  104. Rahma Simin Ali on January 10, 2023 11:21 AM

    I am using Arduino Uno with RS485 NPK sensor. But I am getting 255 for all NPK values not even dipping the sensor inside the soil and when i dip it into the soil same 255 mg/kg is showing. I have seen all the solutions provided for this problem like changing the baud rate, checking the connections, checking if 12V supply is being provided to the NPK sensor but did not work for me. I am unable to figure out the problem. If anyone could come up with a solution ,it would be of great help.

    Reply
  105. Dicko on January 10, 2023 11:51 AM

    Makes sure the soil is wet.

    Reply
  106. Rahma Aimi Ali on January 12, 2023 9:08 AM

    Did you get solution to your problem as i am facing the same error.

    Reply
  107. Jonnel Dela Cruz on January 14, 2023 2:56 AM

    Anyone can help me? I am getting an output

    N: 10mg/kg
    P: 111mg/kg
    K: 48mg/kg

    even the NPK sensor is off I am getting this ouput. Someone help me thank you

    Reply
  108. Jonnel Dela Cruz on January 14, 2023 3:04 AM

    I followed the code and diagram and I am getting an ouput just like this even the modbus and npk even it’s not plugged in and turned on.

    Nitrogen: 10 mg/kg
    Phosphorus: 111 mg/kg
    Potassium: 48 mg/kg

    Someone help me with this problem. Thank you in advance

    Reply
  109. Ronald Morrison on January 14, 2023 7:56 AM

    Those kind of displays are caused by noise on the input lines. If you restart the Arduino you are likely to get different values each time.

    Reply
  110. Sorin Dan on February 19, 2023 4:44 AM

    Hi
    Can someone help me with a system for measuring npk, ph, ec, moisture, temperature in the root of some blueberry plants? The system will consist of 6 sensors that must wirelessly transmit the data measured and visualized on the phone with the help of an application.
    Thank you
    [email protected]

    Reply
  111. Bintang on March 6, 2023 2:37 AM

    Hai Mr Alam. What is your tool? If yes can i get your email

    Reply
  112. Nisha on May 2, 2023 7:33 AM

    Hi, I have used the same code. But it is showing same values for all N=255 mg/kg, P=255 mg/kg, K=255 mg/kg. I am unable to figure out the problem. If anyone could come up with a solution ,it would be of great help.

    Reply
  113. ANJALI on July 5, 2023 1:58 AM

    hi Mr.Alam, im doing the same project with ESP32 but with TTL to RS485 converter not MAX 485 .i should use only RX and TX pin can you help me to do this

    Reply
  114. Mark John on October 7, 2023 9:33 PM

    Hello did you get done with your final project? Does it have any papers for research?

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Silicon Controlled Rectifier (SCR): Construction, Working & Applications
    Silicon Controlled Rectifier (SCR): Construction, Working & Applications
  • How to use ADS1115 16-Bit ADC Module with Arduino
    How to use ADS1115 16-Bit ADC Module with Arduino
  • IoT Based Patient Health Monitoring on ESP32 Web Server
    IoT Based Patient Health Monitoring on ESP32 Web Server
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.