These values from post #14?
01 03 02 01 B5 78 63
They did not come from your code in post #1. The image in post #2 came from the code in Post #1.
These values from post #14?
01 03 02 01 B5 78 63
They did not come from your code in post #1. The image in post #2 came from the code in Post #1.
yes sir, about on the first attempt on post #1, i just replace my 9v battery for the power source of my sensor with another 9v then i try to run and upload it, the outcome on serial monitor becomes like that on my post (screenshot) that has hex values on the output
and i noticed that the readings from every parameter are inaccurate for an instance the ph level, it gives me 5.90 even if i didn't put in a soil, but once i put it on the soil its not changing it stays on 5.90
Replacing your battery changed the output from 0.0
to 01 03 02 01 B5 78 63
?
You code in Post #1 is not complete... correct it. The reason I did not see any of your hex values is that your code stopped here:
void printHexByte(byte b)
{
Serial.print((b >> 4) & 0xF, HEX);
Serial.print(b & 0xF, HEX);
Serial.print(' ');
Now I see the issue. See the word HEX (twice)? Change that to DEC (twice).
Here is how I know to make "hexadecimal" and "decimal" from the same number... run this code....
int value1 = 240; // decimal
int value2 = 0xB5; // hexadecimal
void setup() {
Serial.begin(115200);
Serial.print("Value1 (");
Serial.print(value1);
Serial.print(") ");
Serial.print(value1, DEC);
Serial.print(" ");
Serial.println(value1, HEX);
Serial.print("Value2 (");
Serial.print(value2); // prints decimal by default
Serial.print(") ");
Serial.print(value2, DEC);
Serial.print(" ");
Serial.println(value2, HEX);
}
void loop() {}
This bad data is standard for this device. Inaccurate or completely fake. See what you can do to your code to adjust your results. If you use distilled water, you should adjust your code to get a pH 7. You can make your own distilled water by boiling water and collecting the steam on a cold surface, letting the steam condense and run down the surface into a jar.
i think i already figure it out
type or paste code here#include <SoftwareSerial.h>
#define RE 7
#define DE 6
const uint32_t TIMEOUT = 1000UL; // Increased timeout for sensor response
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 pin, Tx pin
void setup() {
Serial.begin(4800); // Match with the sensor's baud rate
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500); // Allow sensor to stabilize on startup
}
void loop() {
Serial.println("Moisture: ");
float moistureValue = readSensor(moist) * 0.1;
Serial.print(moistureValue);
Serial.println(" %");
Serial.println("-----");
Serial.println("Temperature: ");
float temperatureValue = readSensor(temp) * 0.1;
Serial.print(temperatureValue);
Serial.println(" °C");
Serial.println("-----");
//Serial.println("Conductivity: ");
//int conductivityValue = readSensor(EC);
//Serial.print(conductivityValue);
//Serial.println(" us/cm");
//Serial.println("-----");
Serial.println("pH: ");
float phValue = readSensor(PH) * 0.1;
Serial.print(phValue);
Serial.println(" pH");
Serial.println("-----");
delay(5000); // 5-second delay before the next cycle
}
int16_t readSensor(const byte* command) {
uint32_t startTime = 0;
uint8_t byteCount = 0;
memset(values, 0, sizeof(values)); // Clear previous data
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(command, 8); // Send command (8 bytes)
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while (millis() - startTime <= TIMEOUT) {
if (mod.available() && byteCount < sizeof(values)) {
values[byteCount++] = mod.read();
}
}
// Check if response is valid
if (byteCount < 7) {
Serial.println("Error: Incomplete response");
return -1;
}
// Verify CRC (Optional, depends on sensor response format)
// Combine high and low bytes of data
return (int16_t)(values[3] << 8 | values[4]);
}
void printHexByte(byte b) {
Serial.print((b >> 4) & 0xF, HEX);
Serial.print(b & 0xF, HEX);
Serial.print(' ');
}
Hello it's me again, I have a problem about this RS485 sensor, can someone help. I already make it work but, this time it always gives me a same output for different parameters. I already put it in a soil, dry and wet, but still giving me a static output. What should be the solution for this?
You seem to expect that we can look into your room. How should anybody know what the reason for the obeserved behaviour of constant values will be without giving detailed information?
Do you expect the users here to write a 100 pages tutorial that covers all possible reasons?
Do you have time to read a 100 pages tutorial?
No!
It will be much more efficient if you take 20 to 40 minutes of your precious time to
Is this the same sensor you are talking about in this discussion?
https://forum.arduino.cc/t/3in-1-5pin-probe-rs485-soil-sensor-error-readings/1341533
Can someone help, I think my RS485 soil sensor is not working since it gives me the same output over and over where it is -0.10 for every parameters it read, specifically the Temperature, Moisture and pH.
I already checked my code and wirings multiple times but it keeps on having the same output.
here's , my code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
// Define LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust 0x27 to your LCD's I2C address if necessary
#define RE 10
#define DE 11
#define RELAY_PIN 8 // Pin connected to the relay module controlling the water pump
const uint32_t TIMEOUT = 2000UL; // Increased timeout for sensor response
const byte moist[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
const byte temp[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA};
const byte PH[] = {0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A};
const float MOISTURE_THRESHOLD = 20.0; // Moisture level below which the pump will turn on
byte values[11];
SoftwareSerial mod(2, 3); // Rx pin, Tx pin
void setup() {
Serial.begin(9600); // Match with the sensor's baud rate
mod.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
digitalWrite(RELAY_PIN, LOW); // Ensure pump is off at startup
lcd.setCursor(0, 0);
lcd.print("Initializing...");
delay(1000);
}
void loop() {
// Moisture reading
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Moisture:");
float moistureValue = readSensor(moist) * 0.1;
lcd.setCursor(0, 1);
lcd.print(moistureValue);
lcd.print(" %");
delay(2000); // Display for 2 seconds
// Control water pump based on moisture level
if (moistureValue < MOISTURE_THRESHOLD) {
digitalWrite(RELAY_PIN, LOW); // Turn pump ON
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pump ON");
} else {
digitalWrite(RELAY_PIN, HIGH); // Turn pump OFF
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pump OFF");
}
delay(2000); // Display for 2 seconds
// Temperature reading
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temperature:");
float temperatureValue = readSensor(temp) * 0.1;
lcd.setCursor(0, 1);
lcd.print(temperatureValue);
lcd.print(" C");
delay(2000); // Display for 2 seconds
// pH reading
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("pH Level:");
float phValue = readSensor(PH) * 0.1;
lcd.setCursor(0, 1);
lcd.print(phValue);
delay(2000); // Display for 2 seconds
}
int16_t readSensor(const byte* command) {
uint32_t startTime = 0;
uint8_t byteCount = 0;
memset(values, 0, sizeof(values)); // Clear previous data
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(command, 8); // Send command (8 bytes)
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
startTime = millis();
while (millis() - startTime <= TIMEOUT) {
if (mod.available() && byteCount < sizeof(values)) {
values[byteCount++] = mod.read();
}
}
// Check if response is valid
if (byteCount < 7) {
Serial.println("Error: Incomplete response");
return -1;
}
// Combine high and low bytes of data
return (int16_t)(values[3] << 8 | values[4]);
}
void printHexByte(byte b) {
Serial.print((b >> 4) & 0xF, HEX);
Serial.print(b & 0xF, HEX);
Serial.print(' ');
}
Have you compared your vcery large sketch to any of the hundreds of examples doing the same thing?
There might be a reason why those that work are smaller.
I already did sir
can someone help :<
It's written on your code..
If there is no valid byte, it gives -1 and the sensor output is multiplying that *0.1.
How is your hardware/wiring?
You haven't provided any details about your sensor.
Is it this sensor?
If yes dfrobot has a demo-code on this side.
Where did you buy this sensor? Does the seller provide links to demo-codes?
Perhaps you should read the topic here, it is the same code as yours.
That's a clue for you. Have a look in the code you posted (which looks like it was adapted from a piece of demo code I posted on the forums quite a while back) for where that message is and what causes it to be printed out.
Then you can insert some debug print statements to see what's occurring.
I'll make a wild guess that the value of byteCount is 0. If I'm right, then see if you can figure out what that means.
You should also provide a drawing (as already requested) of how you have connected the various parts of your project together as that may also hold a clue.
Now I'm confused! Over in your other thread you said the sensor was working (or is that a slightly different sensor with 4 readings?):
NOTE If it's the same sensor you are talking about, then please stick to one discussion thread as we won't know what you have been advised in the other thread and may be offering conflicting advice.