ESP32-WROOM-DA MODULE and 7 in 1 Soil sensor using RS485 to TTL converter

That's good. I see you removed one of the power rails before clipping the 2 breadboards together. That seems to work well. Don't loose that power rail!

I like this type of breadboard. You can clip them together, edge-wise or length-wise, remove power rails if needed etc.

My favourite breadboards are even more flexible because they are half-size. Best of all, they are slightly wider and have 6 holes, not 5, in each group.



1 Like

hi sir I did your recommendation this is now what im receiving after

Sent Query: 1 3 7 D0 0 1 84 87
Bytes available: 3
Received Data: 50 79 84
Sent Query: 1 3 7 D0 0 1 84 87
Bytes available: 2
Received Data: 50 11
Sent Query: 1 3 7 D0 0 1 84 87
Bytes available: 6
Received Data: 34 2 0 1 79 84
Sent Query: 1 3 7 D0 0 1 84 87
Bytes available: 5
Received Data: 12 0 1 79 84
Sent Query: 1 3 7 D0 0 1 84 87
Bytes available: 4
Received Data: 0 1 79 84

End of the response is matching to request, so you have confirmation that the TX is successful and correct. You have problem with RX.

You don't answer anything about voltage changes I suggested...

Guys here me out I use thee code that I found here in the forum

#include <SoftwareSerial.h>

#define RE 33
#define DE 32

const uint32_t TIMEOUT = 500UL;

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};

const byte nitro[] = {0x01, 0x03, 0x00, 0x04, 0x00, 0x01, 0xc5, 0xcb};
const byte phos[] = {0x01, 0x03, 0x00, 0x05, 0x00, 0x01, 0x94, 0x0b};
const byte pota[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0b};

byte values[11];

SoftwareSerial mod(16, 17); // Rx pin, Tx pin // Software serial for RS485 communication

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

  delay(500);
}

void loop() {
  float  moist_val, temp_val, ph_val;
  uint16_t ec_val, nitro_val, phos_val, pota_val;

  Serial.println("Moisture: ");
  moist_val = moisture();
  //float Val1 = val1 * 0.1;
  delay(1000);
  Serial.print(moist_val);
  Serial.println(" %\n");
    
  Serial.println("Temperature: ");
  temp_val = temperature();
  //float Val2 = val2 * 0.1;
  delay(1000);
  Serial.print(temp_val);
  Serial.println(" C\n");
  
  Serial.println("Conductivity: ");
  ec_val = conductivity();
  delay(1000);
  Serial.print(ec_val);
  Serial.println(" us/cm\n");
  
  Serial.println("Ph: ");
  ph_val = ph();
  //float Val4 = val4 * 0.1;
  delay(1000);
  Serial.print(ph_val);
  Serial.println(" pH\n");
  
  Serial.println("Nitrogen (N): ");
  nitro_val = nitrogen();
  Serial.print(nitro_val);
  Serial.println(" mg/kg\n");
  delay(1000);

  Serial.println("Phosphorous (P): ");
  phos_val = phosphorous();
  Serial.print(phos_val);
  Serial.println(" mg/kg\n");
  delay(1000);

  Serial.println("Potassium (K): ");
  pota_val = potassium();
  delay(1000);
  Serial.print(pota_val);
  Serial.println(" mg/kg\n");
  
  delay(5000);
}

int16_t moisture() {
  float MOIST3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(moist, sizeof(moist));
    mod.flush();
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
    MOIST3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
  }
    Serial.println();
    return MOIST3and4;
   
}

int16_t temperature() {
  float TEMP3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;
// switch RS-485 to transmit mode
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
// write out the message
  mod.write(temp, sizeof(temp));
// wait for the transmission to complete
  mod.flush();
// switch RS-485 to receive mode
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
    TEMP3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
  }
    Serial.println();
    return TEMP3and4;
 
}

int16_t conductivity() {
  int16_t EC3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(EC, sizeof(EC));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
    EC3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
  }
   Serial.println();
   return EC3and4;
 
}

int16_t ph() {
  float PH3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(PH, sizeof(PH));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount < sizeof(values) ) {
     values[byteCount++] = mod.read();
      printHexByte(values[byteCount - 1]);
    }
    PH3and4 = (((values[3] * 256.0) + values[4])/10); // converting hexadecimal to decimal
  }
  Serial.println();
  return PH3and4;
 
}

int16_t nitrogen() {
  int16_t NITRO3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;
  
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(nitro, sizeof(nitro));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount<sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount-1]);
    }
    NITRO3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
  }
  Serial.println();
  return NITRO3and4;
 }

int16_t phosphorous() {
  int16_t PHOS3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(phos, sizeof(phos));
  mod.flush();
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount<sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount-1]);
    }
    PHOS3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
  }
  Serial.println();
  return PHOS3and4;
  //return (int16_t)(values[4] << 8 | values[5]);
}

int16_t potassium() {
  int16_t POTA3and4;
  uint32_t startTime = 0;
  uint8_t  byteCount = 0;
  
// switch RS-485 to transmit mode
  digitalWrite(DE, HIGH);   
  digitalWrite(RE, HIGH);
  delay(10);
  mod.write(pota, sizeof(pota));
  mod.flush(); // wait for the transmission to complete
// switch RS-485 to receive mode
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);

  startTime = millis();
  while ( millis() - startTime <= TIMEOUT ) {
    if (mod.available() && byteCount<sizeof(values) ) {
      values[byteCount++] = mod.read();
      printHexByte(values[byteCount-1]);
    }
    POTA3and4 = (((values[3] * 256.0) + values[4])); // converting hexadecimal to decimal
  }
  Serial.println();
  return POTA3and4;
}

void printHexByte(byte b)
{
  Serial.print((b >> 4) & 0xF, HEX);
  Serial.print(b & 0xF, HEX);
  Serial.print(' ');
}

this is the result

Phosphorous (P):
01 03 02 00 0C B8 41
12 mg/kg
Potassium (K):
01 03 02 00 04 B9 87
4 mg/kg
Moisture:
01 03 02 00 A9 78 3A
16.00 %
Temperature:
01 03 02 01 09 79 D2
26.00 C
Conductivity:
01 03 02 00 73 F9 A1
115 us/cm
Ph:
01 03 02 00 44 B8 77
6.00 pH

tell me it already work???

I try to water the soil this is the data it read :sob::sob:

01 03 02 01 2B F9 CB
299 mg/kg
Phosphorous (P):
01 03 02 02 E5 78 AF
741 mg/kg
Potassium (K):
01 03 02 02 E3 F8 AD
739 mg/kg
Moisture:
01 03 02 02 23 F8 FD
54.00 %
Temperature:
01 03 02 01 06 39 D6
26.00 C
Conductivity:
01 03 02 06 6C BB C9
1644 us/cm
Ph:
01 03 02 00 3B F9 97
5.00 pH

Maybe it's time to mention the elephant in the room.

The sensor you are using has been discussed many times on this forum. Many of the opinions are not positive. They say that the sensor may be capable of measuring temperature, humidity, conductivity and perhaps even pH with a degree of accuracy. But they also say that the sensor's ability to measure concentration of Phosphorus or Potassium is, well, bunkum. So maybe you should not worry too much about the readings for those particular parameters.

3 Likes

Devices that can measure just nitrogen are costing at least 4 digits.
7 in 1 doesn't lower the price.

1 Like

thank you for the lesson sir even the manufacturer where I bought this sensor say so, it was also on their product description


I might include this on our project documentation

thank you for the help sir <3

Off the top of my head I would say that your temperature and pH routines are not working correctly. Using your data above, temperature should come out at 26.2C and pH should come out at 5.9.

Hi sir what can you recommend to fix that? any help would be appreciated

All your functions are integers instead of float.

1 Like