Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1071

7 in 1 Soil sensor NPK value not change

$
0
0

Hello guys, can you help me ? i have problem on my NPK sensor. My sensor already can get 4 value from sensor like pH, Temprature, EC, Humidity, but N P K value is not working. This is my code i got from tutorials on youtube.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 3);  // RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(4800);
}

void loop() {
  byte queryData[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x08, 0x04};
  byte receivedData[19];

  mySerial.write(queryData, sizeof(queryData));  
  delay(1000);  
  mySerial.flush();

  if (mySerial.available() >= sizeof(receivedData)) {  
    mySerial.readBytes(receivedData, sizeof(receivedData));  

    
    unsigned int soilHumidity = (receivedData[3] << 8) | receivedData[4];
    unsigned int soilTemperature = (receivedData[5] << 8) | receivedData[6];
    unsigned int soilConductivity = (receivedData[7] << 8) | receivedData[8];
    unsigned int soilPH = (receivedData[9] << 8) | receivedData[10];
    unsigned int nitrogen = (receivedData[11] << 8) | receivedData[12];
    unsigned int phosphorus = (receivedData[13] << 8) | receivedData[14];
    unsigned int potassium = (receivedData[15] << 8) | receivedData[16];

    
    float kelembapanTanah = (float)soilHumidity / 20.0;
    float SuhuTanah = 1.0175*(soilTemperature / 10.0) - 1.1524;


    Serial.print("Humidity : ");
    Serial.println(soilHumidity);
    Serial.print("Temp : ");
    Serial.println(SuhuTanah);
    Serial.print("EC : ");
    Serial.println(soilConductivity);
    Serial.print("pH : ");
    Serial.println((float)soilPH / 10.0);
    Serial.print("N : ");
    Serial.println(nitrogen);
    Serial.print("P : ");
    Serial.println(phosphorus);
    Serial.print("K : ");
    Serial.println(potassium);  
    // delay(30000);
  }
}

And i use this RS485 :

instead of using the default like this, because i always get 255 value.

images

previously my npk value always get 0, and now stuck on 32 for n, 88 for p and 104 for k after my friend use Coolterm software. i dont know why.

this is my sensor :

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1071

Trending Articles