nop18
May 19, 2024, 4:58pm
1
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.
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 :
rsmls
May 19, 2024, 5:09pm
2
nop18:
my NPK sensor
AFAIK there's no reliable way to measure NPK with a simple sensor. It requires chemical lab analysis. I wouldn't even bother trying to get this to work; it's a waste of time.
5 Likes
The sensor does not measure N, P or K values. It is not entirely clear what those things do, but you make have a defective fake that cannot even make up numbers.
1 Like
xfpd
May 20, 2024, 3:08pm
4
Verify the sensor, transceiver and Arduino share the ground wire.
2 Likes
Hi @nop18 ,
Welcome to the forum..
The checksum looks backwards..
nop18:
{0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x08, 0x04};
should be..
{0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08}
good luck.. ~q
2 Likes
nop18
May 23, 2024, 9:14am
6
Sry guys, just back from college.
ah really ? i think it will work. But i find some documentation about NPK sensor and its working @@ .
nop18
May 23, 2024, 9:15am
7
this is my wiring.
i try to find this app but cant find it.
So i try using Qmodmaster and CoolTerm for checking the address.
nop18
May 23, 2024, 9:17am
8
thanks
i try this but my sensor not respond.
Could be the power source if you are indeed powering this sensor using a 9v battery..
Could also be on the wrong address..
Check this sketch out..
USE_CAST is defined as true, it will use the second set of data with address 255..
Address 255 is the broadcast address, all sensors should respond and change the 255 with their currently set address..
As the address and baud rate can be changed..
Try address 255 and also different bauds..
double check wiring..
good luck.. ~q
1 Like
nop18
May 24, 2024, 9:57am
11
I've tried it on 9v, 12v, and 24v but still same. Im using this
and this is my sensor address
i use 0000 until 0006 address.
I use your code and this is my output
Is it like this ?
but the value still stuck at 32, 88 and 104.
1 Like
rsmls
May 24, 2024, 10:57am
12
So? As I said earlier, there's no way a sensor like that can specifically measure N, P or K. It'll produce numbers, but they won't mean anything.
1 Like
Yes, it looks like you are getting proper response back from the sensor..
No idea how these sensors work or if they in fact do..
good luck.. ~q
system
Closed
November 20, 2024, 12:29pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.