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)