Integrating NPK Sensor to ESP-WROOM-32

I am having issues in integrating npk sensor with esp-wroom-32 board.
The readings are always in linear relation with each other.
That is:
N: x
P: x/2.8 (to nearest integer)
k: x/2 (to nearest integer)

Query frame is in the code and it is matched with the manual.


I'm attaching my code. Please help me with this

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

 
 
#define RE 26
#define DE 27
 
//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
 
byte values[11];
SoftwareSerial mod(16,17);
 
void setup() {
  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

  delay(3000);
}
 
void loop() {
  byte val1,val2,val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);
  
  
  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);

}
 
byte nitrogen(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(nitro,sizeof(nitro))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    Serial.print(" ");
    }
    Serial.println();
  }
  digitalWrite(DE,LOW);
  digitalWrite(RE,LOW);
  return values[4];
}
 
byte phosphorous(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(phos,sizeof(phos))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    Serial.print(" ");
    }
    Serial.println();
  }
  digitalWrite(DE,LOW);
  digitalWrite(RE,LOW);
  return values[4];
}
 
byte potassium(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(pota,sizeof(pota))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    Serial.print(" ");
    }
    Serial.println();
  }
  digitalWrite(DE,LOW);
  digitalWrite(RE,LOW);
  return values[4];
}

I moved your topic to a more appropriate forum category @yashmohan811 .

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

If you had read that you would have known that the Nano ESP32 category you selected is only for use when discussing subjects directly related to the new Arduino Nano ESP32 board; NOT for use just because your development board happens to have an ESP32 microcontroller on it.

Thanks in advance for your cooperation.

Hey have you already solved your ESP-WROOM-32?

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