Hi everyone. I'm guiding myself from tutorial https://how2electronics.com/measure-soil-nutrient-using-arduino-soil-npk-sensor/
and this is the code:
#include <Wire.h>
#include <SoftwareSerial.h> //Library to convert Digital Output pins of the board to transmitter as well as receiver
#define RE 8
#define DE 7
const byte inq[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08};
//And the response data frame are for all those values: hum,temp, ec, ph, n, p, k like in the attach image
byte values[11];
SoftwareSerial mod(2,3); // RX, TX ( Creates a new SoftwareSerial object )
void setup(){
Serial.begin(4800);
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
}
void loop(){
float val1;
val1 = Hum();
Serial.print(" |HUM : ");
Serial.print(val1);
Serial.println();
delay(2000);
}
float Hum(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
if(mod.write(inq,sizeof(inq))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
// When we send the inquiry frame to the NPK sensor, then it replies with the response frame
// now we will read the response frame, and store the values in the values[] arrary, we will be using a for loop.
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();
}
return (values[4]);
}
Image example test response
But in the example the response is only with 1 data frame,
in my case the response is with 7 data frame. Please, can you guide me to read each one with Arduino uno?.
I'll be very greatful.