hi man, i got the same sensor from comwintop, im using arduino uno and i want to know if you resolve it only changing the ttl to rs485 module, im using max485
A MAX485 based RS485 module should work fine with an UNO.
i tried this code from another post about this
#include <AltSoftSerial.h>
// RO to pin 8 & DI to pin 9 when using AltSoftSerial
#define RE 6
#define DE 7
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
byte values[11];
AltSoftSerial mod;
void setup() {
Serial.begin(9600);
mod.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
// put RS-485 into receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay( 1000 );
}
void loop() {
byte val1, val2, val3;
Serial.print(" Nitrogen: ");
val1 = nitrogen();
Serial.print(" = ");
Serial.print(val1);
Serial.println(" mg/kg");
delay(250);
Serial.print("Phosphorous: ");
val2 = phosphorous();
Serial.print(" = ");
Serial.print(val2);
Serial.println(" mg/kg");
delay(250);
Serial.print(" Potassium: ");
val3 = potassium();
Serial.print(" = ");
Serial.print(val3);
Serial.println(" mg/kg");
Serial.println();
Serial.println();
delay(5000);
}
byte nitrogen() {
// clear the receive buffer
mod.flushInput();
// switch RS-485 to transmit mode
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);
// write out the message
for (uint8_t i = 0; i < sizeof(nitro); i++ ) mod.write( nitro[i] );
// wait for the transmission to complete
mod.flush();
// switch RS-485 to receive mode
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
// crude delay to allow response bytes to be received!
delay(100);
// read in the received bytes
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}
byte phosphorous() {
mod.flushInput();
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);
for (uint8_t i = 0; i < sizeof(phos); i++ ) mod.write( phos[i] );
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay(100);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}
byte potassium() {
mod.flushInput();
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(1);
for (uint8_t i = 0; i < sizeof(pota); i++ ) mod.write( pota[i] );
mod.flush();
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay(100);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
Serial.print(' ');
}
return values[4];
}
and only recive this
Nitrogen: FF FF FF FF FF FF FF = 255 mg/kg
Phosphorous: FF FF FF FF FF FF FF = 255 mg/kg
Potassium: FF FF FF FF FF FF FF = 255 mg/kg
an also tried the code on #176 and doesnt compile for me on this
node.begin(1, swSerial);
and i was thinking to buy the same module as @oswaldoguerra
That code looks like one of my early attempts to communicate with an NPK sensor. That code works with a sensor with N, P & K in registers 0x1E, 0x1F and 0x20.
If your sensor doesn't use these registers, then it likely won't respond and you will see FFs like you are getting.
That code needs the modbusmaster library. You can install it via the library manager.
I may have said this earlier, but if the supplier cannot provide the user manual, then return it to them and look elsewhere for a supplier who will.
thanks man, the code on #176 really works i was using the wrong modbusmaster library

the first one is the correct, i changed it and works
im used this wiring diagram that i found on another post and i made it work really nice

im goin to left the user manual if anyone whant to know how use this NPKPHCTH-S sensor, from comwintop i buy the 6 in 1 without conductivity
NPK type (5Pin probe) manual_V1.4.pdf (483,2 KB)
thank for ur help man @markd833
Hello @bright626. I just stumbled on your post. All thanks to @markd833 for helping lost NPK sensor users xD.
I think you have got the same sensor as mine. I could tell this because of the box. Did you have this box
If this is what you have then I also ran in the same problem as I didn't had any manual given by the supplier. So were you able to identify it's user manual ?
Hello @areebkhan02 . Yes mine came with the exact same box but no user manual. It's been difficult getting the sensor to retrieve sensibe readings so far. I have searched multiple addresses on the internet to work with the code i have for my old sensor from jxct which was working on 9600 baudrate but the only one that makes sense is temperature. I would love to know if you have made any progress on your end with these sensors
@areebkhan02 I bought mine from Alibaba and the specifications on the website were 9-30V operating voltage and working baudrate for data recieval was 9600. Even the name of the company was JXCT on the shop I bought it from on the website so it's very frustrating when I got these ones that does not match the description. Do you know the name of the company that yours is from?
@bright626. So I just got it working tomorrow ran into a few bugs. I will verify each reading independently in a few days so I will update you on this. What I can tell you is that I am using this manual for my reference since I also ordered from JXCT User Manual Ver 2.0 RS485-Soil 7in1 Soil Sensor (2).pdf - Google Drive. This is their latest manual my best bet is that this will work but I am yet to see. Also I couldn't get my sensor to respond on 9600 baud rate I had to change it to 4800 for working maybe you can try that and also please see this manual, if you haven't tried it before enter its inquiry address maybe you arrive at the correct values. Also I red that you are working on ESP32 if that's true can you share its code since currently I am working on Arduino Uno but want to later change it to ESP32.
Topic split from another topic. Please do not add your own questions to the end of other people's topics.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
Thank you for your feedback. I actually have this manual but I lost track of how many manuals I was using for the enquiry addresses so it's possible that I missed it. This is the code that worked for me. It is suited for the 9600 baudrate variant of the 7in1 sensors from JXCT so it will not work for the sensor you currently have but feel free to make any modifications.
#include <SoftwareSerial.h>
#define MODBUS 18
const uint32_t TIMEOUT = 500UL;
unsigned long lastMillis = 0;
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
const byte ph[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0b};
const byte temp[] = {0x01, 0x03, 0x00, 0x13, 0x00, 0x01, 0x75, 0xcf};
const byte moist[] = {0x01, 0x03, 0x00, 0x12, 0x00, 0x01, 0x24, 0x0F};
const byte ec[] = {0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xce};
byte values[11];
byte values_moist[11];
byte values_temp[11];
byte values_ph[11];
byte values_ec[11];
byte values_nitro[11];
byte values_phos[11];
byte values_pota[11];
float val_moist;
float val_temp;
float val_ph;
int val_ec;
int val_ec_adj;
int val_nitro;
int val_phos;
int val_pota;
float temperature = 0.0f;
float humidity = 0.0f;
bool isDataReady = false;
uint16_t error;
float LastMaxHumidity = 0;
int err99 = 99;
int err1 = 1;
int err2 = 2;
int err3 = 3;
SoftwareSerial mod(23,22); // RX, TX ( Creates a new SoftwareSerial object )
void setup()
{
Serial.begin(9600);
mod.begin(9600);
pinMode(MODBUS, OUTPUT);
}
void loop()
{
lastMillis = millis();
Serial.print(" Nitrogen: ");
val_nitro = nitro_call();
Serial.print(" = ");
Serial.print( val_nitro );
Serial.println(" mg/kg");
delay(500);
Serial.print(" Phosphorus: ");
val_phos = phos_call();
Serial.print(" = ");
Serial.print( val_phos );
Serial.println(" mg/kg");
delay(500);
Serial.print(" Potassium: ");
val_pota = pota_call();
Serial.print(" = ");
Serial.print( val_pota );
Serial.println(" mg/kg");
delay(500);
Serial.print(" Moisture: ");
val_moist = moisture();
Serial.print(" = ");
Serial.print( val_moist );
Serial.println(" %");
delay(500);
Serial.print(" Temp: ");
val_temp = temperatura();
Serial.print(" = ");
Serial.print( val_temp );
Serial.println(" °C");
delay(500);
if ( LastMaxHumidity < val_moist ) { LastMaxHumidity = val_moist; }
else {LastMaxHumidity = LastMaxHumidity;}
val_ec_adj = val_ec * ( 1 + ( LastMaxHumidity - val_moist ) / 100 );
Serial.print(" PH: ");
val_ph = ph_call();
Serial.print(" = ");
Serial.print( val_ph );
Serial.println();
delay(1000);
Serial.print(" EC: ");
val_ec = ec_call();
Serial.print(" = ");
Serial.print( val_ec );
Serial.println(" uS/m");
delay(1000);
Serial.println();
}
float nitro_call(){
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(nitro,sizeof(nitro));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_nitro) ) {
values_nitro[byteCount++] = mod.read();
}
}
uint16_t combined = ((values_nitro[3]<<8)|values_nitro[4]);
return combined;
}
float phos_call(){
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(phos,sizeof(phos));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_phos) ) {
values_phos[byteCount++] = mod.read();
}
}
uint16_t combined = ((values_phos[3]<<8)|values_phos[4]);
return combined;
}
float pota_call(){
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(pota,sizeof(pota));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_pota) ) {
values_pota[byteCount++] = mod.read();
}
}
uint16_t combined = ((values_pota[3]<<8)|values_pota[4]);
return combined;
}
float ph_call(){
float PH3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(ph,sizeof(ph));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_ph) ) {
values_ph[byteCount++] = mod.read();
}
}
// PH3and4 = (((values_ph[3] * 256.0) + values_ph[4])/10); // converting hexadecimal to decimal
PH3and4 = (( (values_ph[3]<<8)|values_ph[4])+0.0)/100;
// uint16_t combined = ((values_ph[3]<<8)|values_ph[4])/10;
return PH3and4;
}
float temperatura(){
float TEMP3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(temp,sizeof(temp));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_temp) ) {
values_temp[byteCount++] = mod.read();
}
}
//TEMP3and4 = (((values_temp[3] * 256.0) + values_temp[4])/10); // converting hexadecimal to decimal
TEMP3and4 = (( (values_temp[3]<<8)|values_temp[4])+0.0)/10;
//float combined = ((values_temp[4])/10);
return TEMP3and4;
}
float moisture(){
float MOIST3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(moist,sizeof(moist));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_moist) ) {
values_moist[byteCount++] = mod.read();
//printHexByte(values_moist[byteCount-1]);
}
}
// MOIST3and4 = (((values_moist[3] * 256.0) + values_moist[4])/10); // converting hexadecimal to decimal
MOIST3and4 = (( (values_moist[3]<<8)|values_moist[4])+0.0)/10;
// float combined = (((values_moist[3]<<8)|values_moist[4])/10 + 0.0);
return MOIST3and4;
}
float ec_call(){
float EC3and4;
uint32_t startTime = 0;
uint8_t byteCount = 0;
digitalWrite(MODBUS,HIGH);
delay(10);
mod.write(ec,sizeof(ec));
mod.flush();
digitalWrite(MODBUS,LOW);
startTime = millis();
while ( millis() - startTime <= TIMEOUT ) {
if (mod.available() && byteCount<sizeof(values_ec) ) {
values_ec[byteCount++] = mod.read();
}
}
// EC3and4 = (((values_ec[3] * 256.0) + values_ec[4])/10); // converting hexadecimal to decimal
uint16_t combined = (values_ec[3]<<8)|values_ec[4];
return combined;
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

