Soil 3 in 1 sensor (moisture, temperature and Electrical Conductivity)

Hello guys, I need to create a arduino project using the 3 in 1 soil sensor that measures moisture , temperature, electrical conductivity. And I do not know what is the code for it and also the pinouts of the whole project. Hope someone can help.

Here is the sensor that I want to use:

Is this this the write arduino code I saw this fron twh internet:

#include <SoftwareSerial.h>
#include <Wire.h>

// Define RS485 pins for RE and DE to switch between transmit and receive mode
#define RS485_RE 8
#define RS485_DE 7

// Modbus RTU requests for reading NPK values
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};

// A byte array to store NPK values
byte values[11];

// SoftwareSerial object to communicate with the RS485 module
SoftwareSerial modbus(2, 3); // RX, TX

void setup() {
// Start serial communication with the computer
Serial.begin(9600);

// Start serial communication with the RS485 module
modbus.begin(9600);

// Set RS485 pins as outputs
pinMode(RS485_RE, OUTPUT);
pinMode(RS485_DE, OUTPUT);

// Turn off RS485 receiver and transmitter initially
digitalWrite(RS485_RE, LOW);
digitalWrite(RS485_DE, LOW);

// Wait for the RS485 module to initialize
delay(500);
}

void loop() {
// Read NPK values and print them to the serial monitor
Serial.print("Nitrogen: ");
Serial.print(readValue(nitro));
Serial.println(" mg/kg");

Serial.print("Phosphorous: ");
Serial.print(readValue(phos));
Serial.println(" mg/kg");

Serial.print("Potassium: ");
Serial.print(readValue(pota));
Serial.println(" mg/kg");

// Wait for 2 seconds before reading values again
delay(2000);
}

// Sends a Modbus RTU request and reads the response to get a value
byte readValue(const byte* request) {
// Set RS485 module to transmit mode
digitalWrite(RS485_RE, HIGH);
digitalWrite(RS485_DE, HIGH);

// Send Modbus RTU request to the device
modbus.write(request, sizeof(request));

// Set RS485 module to receive mode
digitalWrite(RS485_RE, LOW);
digitalWrite(RS485_DE, LOW);

// Wait for the response to be received
delay(10);

// Read the response into the values array
byte responseLength = modbus.available();
for (byte i = 0; i < responseLength; i++) {
values[i] = modbus.read();
}

// Return the value from the response
return values[3] << 8 | values[4];
}

That code won’t work, it’s not posted properly… read the forum guides.

Wherever you bought the probe, download the datasheet / example code and also please post that in

Sorry, I am new to the forum. Here is the data sheet of the probe:

Post a link to the data sheet, not a picture of it.

The code you posted is for one of those so-called "NPK" sensors, which are fraudulent. They measure soil conductivity, and make up some meaningless numbers for N and P and K.

Ohhh i see i am still a beginner in arduino. Here is the link of the data of probe

Based on my research from the tutorial videos the npk sensors have an identical hardware probe with my moisture, temperature and EC, i think the only difference is the function itself

Putting aside the issue over the capability of the "sensor", have a search of the forum for "NPK Sensor". There are many discussions on this type of sensor that start out with code very similar to what you have posted.

Thank you, i will try to find that.

what is the update about this? i recently ordered NPK sensor but the one i received is that sensor. now i cant do anything about it so i will just use this for our capstone project. can someone update or help me in operating this thing. thank you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.