Hi everyone, I need your help! I'm currently using serial communication with my sensor which I brought from atlas scientific , However there's some issue I faced and I need your help!
I'm using a Arduino Mega, Electrical embedded chips from Atlas Scientific , Sensor probe from there as well. I manage to code and everything is fine as I can't suspect any problem with the code, however there's no string coming out from it and I find it very weird.
Here's the following references with codes
#include <SoftwareSerial.h>
#include <stdlib.h>
#include <string.h>
#include <LiquidCrystal.h>
#define rxpin 10
#define txpin 11
SoftwareSerial myserial(rxpin,txpin);
LiquidCrystal lcd(53,51,47,45,43,41);
String inputstring = "";
String sensorstring = "";
String TDSsensorstring="";
//String Makeupstring = "";
//String Blowoffstring ="";
String phValue = "";
String Colorstring ="";
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;
//boolean Makeup_stringcomplete = false;
//boolean Blowoff_stringcomplete = false;
boolean TDS_stringcomplete = false;
boolean Color_stringcomplete = false;
// set PWM output for respective pin
//TDS
int TDSpwm = 2;
//pH
int pHpwm = 3;
//Color
int Colorpwm = 4;
//Led
int uvLed =13;
//value
char string_received = 0;
float ph = 0;
void setup()
{
Serial.begin(38400);
Serial1.begin(38400);
Serial2.begin(38400);
Serial3.begin(38400);
myserial.begin(38400);
inputstring.reserve(5);
sensorstring.reserve(30);
//pH
Serial2.print("e\r");
delay(50);
Serial2.print("e\r");
delay(50);
Serial2.print("f\r"); //call the function to change the calibration mode of the pH value
delay(50);
//tds
Serial1.print("O,SG,0\r");
delay(50);
Serial1.print("O,S,0\r");
delay(50);
Serial1.print("O,TDS,0\r");
delay(50);
Serial1.print("O,EC,1\r");
delay(50);
Serial1.print("C,1\r");
delay(50);
pinMode(TDSpwm,OUTPUT);
pinMode(pHpwm,OUTPUT);
pinMode(uvLed,OUTPUT);
pinMode(Colorpwm,OUTPUT);
digitalWrite(uvLed,HIGH);
lcd.begin(16, 2);
}
int PWMTDS(float x )
{
int result = x * 0.1275 ; // 0 - 255 is within 0 to 2000 uS/cm
result = constrain(result,0,255);
/* Thus, 2.5V would open the relay and switch on the bleed off valve */
return result;
}
int PWMPH(float x )
{
int result = x * 21.25 ; // 0-255 is within 0 to 12 pH
result = constrain(result,0,255);
return result;
}
int PWMCOLOR(int x )
{
int result = x * 0.127 ; // 0 - 255 is within from 0 to 2000
result = constrain(result,0,255);
return result;
}
void loop()
{
Serial.println("");
//tds
while(Serial1.available())
{
char inchar =(char)Serial1.read();
TDSsensorstring += inchar;
if(inchar =='\r')
{
TDS_stringcomplete = true;
}
}
char carray[TDSsensorstring.length() + 1]; //determine size of the array
TDSsensorstring.toCharArray(carray, sizeof(carray)); //put readStringinto an array
Serial.print("TDS value :'");
Serial.print(TDSsensorstring);
Serial.println("'");
char *EC=strtok(carray,",");
float EC_float=atof(carray);
int value = PWMTDS(EC_float);
Serial.print("TDS PWM Value for reference:'");
Serial.print(value);
Serial.println("'");
Serial.print(EC_float);
value = 0;
analogWrite(TDSpwm, value);
TDSsensorstring = "";
delay(30);
//LCD for TDS
lcd.setCursor(0,0);
lcd.print("EC:");
lcd.setCursor(3,0);
lcd.print(EC_float);
lcd.setCursor(8,0);
lcd.print("uS/cm");
//pH Sensor
Serial2.print("R\r");
while(Serial2.available()){ //if we see that the pH Circuit has sent a character.
char inchar = (char)Serial2.read();
phValue += inchar;
string_received=1; //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
}
if(string_received==1){ //did we get data back from the ph Circuit?
Serial.print("pH Value:'");
Serial.print(phValue);
Serial.println("'");
char carray[phValue.length() + 1]; //determine size of the array
phValue.toCharArray(carray, sizeof(carray)); //put readStringinto an array
char *PH=strtok(carray,",");
ph=atof(carray);
if(ph>=7.5){
Serial.println("high\r");
} //This is the proof that it has been converted into a float.
if(ph<7.5){
Serial.println("low\r");
} //This is the proof that it has been converted into a float.
phValue ="";
string_received=0;
} //reset the string received.
int pHoutput = PWMPH(ph); // set int value for the pwm
Serial.print("Pwm ph value is : ' ");
Serial.print(pHoutput);
Serial.println("'");
analogWrite(pHpwm, pHoutput); // output analog write out
delay(30); // delay a few second to let the Hobo absorb the data
//LCD for pH
lcd.setCursor(0,1);
lcd.print("pH:");
lcd.setCursor(3,1);
lcd.print(ph);
}

Thank you very much!