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 no

Here is the sensor that I want to use:


CTTO- I have same project anyone can help me ?

#include <SoftwareSerial.h>

#define RE 7
#define DE 6

const uint32_t TIMEOUT = 2000UL; // Extended timeout to 2000ms

// Modbus commands for each sensor reading
const byte moist[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
const byte temp[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA};
const byte EC[] = {0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x25, 0xCA};
const byte PH[] = {0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A};

byte values[11];
SoftwareSerial mod(2, 3); // Rx, Tx pins for software serial

void setup() {
Serial.begin(9600);
mod.begin(9600); // Set to match sensor's baud rate
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500);
}

void loop() {
// Read each sensor value
Serial.println("-----");

Serial.println("Moisture: ");
float moistureValue = readSensor(moist, "Moisture") * 0.1;
Serial.print(moistureValue);
Serial.println(" %");

Serial.println("Temperature: ");
float tempValue = readSensor(temp, "Temperature") * 0.1;
Serial.print(tempValue);
Serial.println(" *C");

Serial.println("Conductivity: ");
uint16_t ecValue = readSensor(EC, "Conductivity");
Serial.print(ecValue);
Serial.println(" us/cm");

Serial.println("pH: ");
float phValue = readSensor(PH, "pH") * 0.1;
Serial.print(phValue);
Serial.println(" pH");

delay(5000); // Delay before reading again
}

int16_t readSensor(const byte command[], const char* sensorName) {
uint32_t startTime;
uint8_t byteCount = 0;

// Send command
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(command, sizeof(command));
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay(100); // Give time for sensor to respond

// Read response
startTime = millis();
while (millis() - startTime <= TIMEOUT) {
if (mod.available() && byteCount < sizeof(values)) {
values[byteCount] = mod.read();
Serial.print(sensorName);
Serial.print(" Byte ");
Serial.print(byteCount);
Serial.print(": ");
Serial.println(values[byteCount], HEX);
byteCount++;
}
}

// Check if response length is correct
if (byteCount >= 7) { // Expected response length for each sensor
int16_t result = (int16_t)(values[3] << 8 | values[4]);
Serial.print(sensorName);
Serial.print(" Raw Value: ");
Serial.println(result);
return result;
} else {
Serial.print("Error: Incomplete response for ");
Serial.println(sensorName);
return 0; // Indicate an error if not enough bytes were received
}
}

This is the code I saw from the internet

I moved your topic to an appropriate forum category @efwawfa .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.


This is the response

Be aware that the device is a scam, it is not possible to measure NPK with that device. It must be a school project because we have been getting one or two requests a day.

What Arduino board, what Rs485 converter, how's the wiring...?

My bad, I see so many of these I didn't look close enough.

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