I'm having trouble reading my sensors reading

#include <SoftwareSerial.h>

#define RE 7
#define DE 8

const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11]; // Array to store received data
SoftwareSerial mod(1, 0); // Using pins 2 and 3 for communication

void setup() {
Serial.begin(9600); // Start serial communication with the Serial Monitor
mod.begin(4800); // Start communication with the sensor
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);

Serial.println("Sensor Initialized");
}

void loop() {
digitalWrite(DE, HIGH); // Enable transmission mode
digitalWrite(RE, HIGH);
delay(10);

if (mod.write(ph, sizeof(ph)) == 8) { // Send request to the sensor
digitalWrite(DE, LOW); // Switch to receive mode
digitalWrite(RE, LOW);
delay(10); // Allow time for response

// Read response from the sensor
if (mod.available() >= 11) { // Make sure we have enough data
  for (byte i = 0; i < 11; i++) {
    values[i] = mod.read();  // Store all the received bytes
    Serial.print(values[i], HEX);  // Print the raw byte values in hexadecimal
    Serial.print(" ");
  }
  Serial.println();  // Print a newline after the raw data

  // Interpret the data (based on your sensor's documentation)
  
  // pH value (assuming it's in values[4] and values[5])
  int16_t pH_raw = (values[4] << 8) | values[5];
  float soil_ph = float(pH_raw) / 100.0;  // Adjust divisor as necessary (e.g., dividing by 100)
  Serial.print("Soil pH: ");
  Serial.println(soil_ph, 1);  // Print pH value

  // Temperature value (assuming it's in values[6] and values[7])
  int16_t temperature_raw = (values[6] << 8) | values[7];
  float temperature = float(temperature_raw) / 10.0;  // Adjust divisor based on your sensor
  Serial.print("Temperature: ");
  Serial.println(temperature, 1);  // Print temperature value

  // Humidity value (assuming it's in values[8] and values[9])
  int16_t humidity_raw = (values[8] << 8) | values[9];
  float humidity = float(humidity_raw) / 10.0;  // Adjust divisor if necessary
  Serial.print("Humidity: ");
  Serial.println(humidity, 1);  // Print humidity value

  // EC value (assuming it's in values[10] and possibly another byte)
  // For example, EC could be in two bytes if applicable
  int16_t ec_raw = (values[10] << 8) | values[11];  // Adjust if more bytes are available
  float ec = float(ec_raw) / 1000.0;  // Adjust scaling if needed (divide by 1000)
  Serial.print("EC: ");
  Serial.println(ec);  // Print EC value

} else {
  Serial.println("Error: Incomplete data received.");
}

}

delay(3000); // Wait before the next reading
}

RESULT:
Humidity: 861.6

EC: 3.15

4B 98 68 C 4C 98 98 D F4 F4 F4

Soil pH: 196.1

Temperature: -2661.1

Humidity: -282.8

EC: -3.03

F0 C 8A 78 A C FD FA C0 88 78

Soil pH: 25.7

Temperature: -51.8

Humidity: -1624.8

EC: 30.84


RS485 Soil Sensor(Temperature&Humidity&EC&PH) Arduino WiKi- DFRobot
this link are similar to my sensor but he has different hardware im only using the senor, rs485 to tll and arduino uno r3


PLEASE HELP ME. I dont know how to use this forum

Solution: read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

can you send the link please?

Can you post the link in your next post and I will forward it to you as a direct message?

Every forum category has a pinned link to get you started. READ ALL OF IT.

i posted the link

Do what the comment says. Don't use pins 1 and 0.

still i idid not uuse thepin still same error

i reach to the shop where i bought it and they said this link should work:
RS485 Soil Sensor(Temperature&Humidity&EC&PH) Arduino WiKi- DFRobot

Hello, do yourself a favour and please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).

Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

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