RS485 Soil NPK Sensor COM37, R33

Fr160,000

Soil nitrogen, phosphorus and potassium sensor is suitable for detecting the content of nitrogen, phosphorus and potassium in soil.

In stock

SKU: SEN13931 Category:

Description

Soil nitrogen, phosphorus and potassium sensor is suitable for detecting the content of nitrogen, phosphorus and potassium in soil. It can judge the fertility degree of soil by detecting the content of nitrogen, phosphorus and potassium in soil, thus facilitating the systematic evaluation of soil conditions by customers.

Features

  1. Easy to measure, not only for professionals, but also for non-professionals, just insert the instrument into the soil to measure.
  2. High precision, fast speed measurement, accuracy up to within 2%, and increased stability, more accurate data.
  3. The resolution is up to 1mg/kg (mg/l), on-site quick inspection, easy to carry, and can be read by inserting into the soil.
  4. Portable measurement, accurate grasp of the soil fertility status, the user can measure the soil condition at any time, according to the soil condition, the soil fertility can be balanced to achieve a suitable growth environment for the plant.
  5. The sensor uses high quality chip, low power consumption, high sensitivity and stable signal.
  6. IP68 grade waterproof and dustproof, to ensure the normal operation of components for a long time. Good sealing performance to prevent moisture from entering the interior of the instrument.
  7. High quality probe, rust resistance, electrolytic resistance, salt and alkali corrosion resistance, to ensure the long-term operation of the probe part. Therefore, it is suitable for all kinds of soil.
  8. Suitable for agricultural production, greenhouse breeding, orchard nursery, soil research.
  9. It is suitable for the detection of alkaline soil, acid soil, substrate soil, seedling bed soil, coconut bran soil.
 

Getting started with the Soil NPK Sensor

In this tutorial, learn how to interface soil NPK sensor with Arduino board and measure the values of main soil nutrients Nitrogen-N, Phosphorus-P, and Potassium-K present in the soil and display them on OLED Display  with I2C support and serial monitor.

Hardware required

  • Soil NPK Sensor
  • Arduino Nano
  • OLED 0.96″ I2C 128X64
  • MAX485 TTL To RS485 Module
  • Jumper wires

Connecting the Hardware

Connect all the required components as shown in the below schematic diagram to interface Soil NPK sensor with Arduino Nano through MAX485 to display the Soil NPK values on the OLED display.

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.

Note: RO to pin 8 & DI to pin 9 when using AltSoftSerial

 

Setting up the library

Install the required libraries listed below before uploading the code:

  • Adafruit SSD1306 – Adafruit_SSD1306.h – link
  • Adafruit GFX Library – Adafruit_GFX.h – link
  • AltSoftSerial Library – AltSoftSerial.h – link

Upload the Code

#include <AltSoftSerial.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);

// RO to pin 8 & DI to pin 9 when using AltSoftSerial
#define RE 6
#define DE 7

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];
AltSoftSerial mod;

void setup() {
Serial.begin(9600);
mod.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);

// put RS-485 into receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);

//Initializing and Configuring OLED display
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("Soil NPK Sensor");
display.setCursor(25, 35);
display.setTextSize(1);
display.print("Initializing");
display.display();
delay(3000);
}

void loop() {
byte val1, val2, val3;
Serial.print("Nitrogen: ");
val1 = nitrogen();
Serial.print(" = ");
Serial.print(val1);
Serial.println(" mg/kg");
delay(1000);

Serial.print("Phosphorous: ");
val2 = phosphorous();
Serial.print(" = ");
Serial.print(val2);
Serial.println(" mg/kg");
delay(1000);

Serial.print("Potassium: ");
val3 = potassium();
Serial.print(" = ");
Serial.print(val3);
Serial.println(" mg/kg");
Serial.println();
Serial.println();
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();
delay(3000);
}

byte nitrogen() {
// clear the receive buffer
mod.flushInput();

// switch RS-485 to transmit mode
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);

// write out the message
for (uint8_t i = 0; i < sizeof(nitro); i++ ) mod.write( nitro[i] );

// wait for the transmission to complete
mod.flush();

// switching RS485 to receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);

// delay to allow response bytes to be received!
delay(200);

// read in the received bytes
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}

byte phosphorous() {
mod.flushInput();
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);
for (uint8_t i = 0; i < sizeof(phos); i++ ) mod.write( phos[i] );
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
// delay to allow response bytes to be received!
delay(200);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}

byte potassium() {
mod.flushInput();
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);
for (uint8_t i = 0; i < sizeof(pota); i++ ) mod.write( pota[i] );
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
// delay to allow response bytes to be received!
delay(200);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}

Errors with Solutions:

Getting 255 for all NPK values:

  • RO to pin 8 & DI to pin 9 and RE to D6 when using AltSoftSerial
  • Check with connection between sensor and MAX485
  • Increase the delay to allow response bytes to be received!
  • Maybe you are not using code from the above

Getting no response from sensor data

  • Check the baud rate with the sensor manufacturer and try different baud rates
  • May be due to sensor or the Modbus module malfunctioning or not working.

Testing the circuit

After successful code upload place the 3 pin steel probe in soil which you want to measure the soil NPK values, and open the serial monitor to see the NPK values, also you can see the NPK values printed on OLED display as the below images.

Package includes:
1×Soil NPK Sensor