Problem with collecting data from F300 Liquid Level Sensor using RS232 Shield

Hi everyone,

This is my first time posting here. I am a newbie to arduino and I really hope that you all can help me. I am tasked with collecting data from a liquid (in my case water) level sensor. It measures the percentage of the water level and outputs using RS232 signal. The manual for the sensor is attached with this post.

I decided to buy a RS232 shield which can interface with the sensor. I bought the linksprite RS232 shield available at linksprite.com. I plugged in the shield on top of Arduino Uno. And connected the Tx and Rx of the sensor to the Rx and Tx of the shield respectively.

Now comes the diffcult part. The sensor uses its own protocol for communication and the concerning document is also attached with this post. The protocol for reading level percent is given below.

Request: From device to sensor.
ASCII: $!DO0139
Hex: 24 21 44 4F 30 31 33 39 0D 0A
$! is header, DO is command, 01 is sensor id, 39 is end.
Reply: From sensor to device
ASCII: *RFV01000.0198
Hex: 2A 52 46 56 30 31 30 30 30 2E 30 31 39 38 0D 0A

  • is header, RFV is reply command. 01 is sensor id. 000.01 is the level value in percent. Max is
    100.00.

To keep it simple I decided to open a serial port and communicate with the sensor by sending the ASCII text. In the serial monitor I am unable to get any data in return. I am also using an LED to indicate whether serial is available or not. Please find my code below

/*
  Communication with the F300 level sensor over RS232 shield
 */
 
int led = 12; //Led turns on and off to indicate serial working
char temp; // initialize variable
 
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
  digitalWrite(led, LOW); // Switch off the LED
  Serial.begin(9600);  // set baud rate for serial communication
  
  establishContact();
}

// the loop routine runs over and over again forever:
void loop() {
  
  Serial.println('$!DO0139');
   
  if(Serial.available() > 0)
  {
    
    temp = Serial.read();
    Serial.println(temp);
    
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);  // wait for a second
    
    
  }
                  
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);     // wait for a second

  
}


void establishContact(){
  while(Serial.available() <= 0){
    Serial.println('$!DO0139');
    delay(500);
  }
}

I know I am missing a step or doing something wrong. Your help is much appreciated.

F300ManualV3.pdf (483 KB)

LevelSensorProtocol.pdf (72.1 KB)

    Serial.println('$!DO0139');

That is one mistake. For a character string you need to use double-quotes:

    Serial.println("$!DO0139");

Because of the two delay(1000) calls you will be displaying one character every two seconds. Because you are using .println() you will also be showing one character per line.

You appear to be using Serial to send to both the sensor and Serial Monitor. That's going to confuse your sensor when you send its data back at it. Most people use SoftwareSerial to connect to a device and Serial to connect to Serial Monitor. That means the RS232 shield has to be configurable to use pins other than 0 and 1 for communication.

Thank you for your quick response. I was starting to get worried that no one would reply.

I don't think that this shield is configurable. Any idea how to move forward?

I will make the aforementioned change in code and test.

Thanks once again.

OK I have made some changes to the code. I bent the RS-232 shields pin i.e. 0 and 1 and using wires connected them to 8 and 9 (as per AltSoftSerial). The modified code is below:

/*
  Communication with the F300 level sensor over RS232 shield
 */
#include <AltSoftSerial.h>

AltSoftSerial sensorSerial; //
int led = 12; //Led turns on and off to indicate serial working
char to_sensor[10] = "$!DO0139"; 
char temp; // initialize variable

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
  digitalWrite(led, LOW); // Switch off the LED

  Serial.begin(9600);  // set baud rate for serial communication
  Serial.println("USB Computer Interface Begin");

  sensorSerial.begin(9600);
  Serial.println("Sensor RS-232 Interface Begin");

  establishContact();   //Establish handshaking
}

// the loop routine runs over and over again forever:
void loop() {

  sensorSerial.write(to_sensor);

  if(sensorSerial.available() > 0){
    temp = sensorSerial.read();
    Serial.println(temp);

    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  }

  delay(10);  // wait for half a second

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);     // wait for half a second
}


void establishContact(){                      //for handshaking
  while(sensorSerial.available() <= 0){
    sensorSerial.write(to_sensor);
    delay(500);
  }
}

The good news is that I am now receiving something. But I can't make sense of it. The output is below:

USB Computer Interface Begin
Sensor RS-232 Interface Begin
þ
P
ø

Does anyone have any idea how to properly capture the response in ASCII or HEX?