0
votes


I am trying to read the data from a Ultra Sonic Fuel Sensor(the link).The Baud rate of this device is 9600.The device basically sends data at regular time intervals.I am able to read the output in the PC using Terminal software.Given below is a sample.

Eg:*XD,205B,00,0000,0031,0000,0000,null#

I am trying to connect this device to Arduino through serial port provided in the device and when I see the Serial Monitor,the output is not correct.Given below is the sample.

5320215115451166102572432302302432302302302302432303816623024323023023023024323023023023051822281141463

String incoming_char;      // Will hold the incoming character from the Serial Port.

void setup()
{
  //Initialize serial ports for communication.
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Starting Communication with Fuel Sensor");
}
void loop()
{

 //If a character comes in from the cellular module...

  if(Serial1.available() >0)
  {
    incoming_char=String(Serial1.read());    // Get the character from the cellular serial port.
    Serial.print(incoming_char);  // Print the incoming character to the terminal.
  }
}

The Arduino is powered from USB and the Device from a 12V supply. The voltage levels from the device Tx-GND=-5.44V,Rx-GND=-8.22V.

I initially thought the the issue might be because of the voltage range and made a voltage divider circuit and fed Arduino the proportionate voltage.Even that is not working. So,what is the thing which is going wrong ?Please guide me.

4
You are confuzzling ASCII and binary data. Something is displaying the characters in the string as integers instead of characters.Hans Passant
Ya Hans,I switched to Serial.write and now it is printing junk Characters.Apparently,This character set is the getting converted to numbers.Bviki

4 Answers

0
votes

Since you are using Serial1 I am assuming you are using an Arduino Mega?

From your question I would say the issue isn't voltage etc. but more likely to be how you are reading the data. You are assuming that the sensor will be returning char values. Are there any specifications on what is being returned?

I created a similar project using an Arduino. Except my Ultrasonic device was used as a range finder. There are details here. As you can see in the code the range is returned from the sensor as a two byte integer.

You will need to find out what the what the Ultra Sonic Fuel Sensor is returning and read in a similar fashion.

0
votes

allright i would start by suggesting that you connect this to an analog pin to read. you will have to find the ratio between the fuel hight and voltage by measuring and dividing. then insert the multiplication in the code and you are set it will look like the hight instead of just a voltage

0
votes

This is just a wild guess since I don't own an Arduino Mega (I have Duemilanove and Uno), but I've worked on projects wherein I've encountered issues similar to what you have. Sometimes adding a delay() on your void loop() block helps and gives it enough time for the arduino to read the bytes from the buffer. For 9600 baud rate, it usually takes about 1 ms to read 1 byte so adding a delay is necessary.

void loop()
{

 //If a character comes in from the cellular module...

  if(Serial1.available() >0)
  {
    incoming_char=String(Serial1.read());    // Get the character from the cellular serial port.
    Serial.print(incoming_char);  // Print the incoming character to the terminal.
  }
  delay(100);
}
0
votes

Thank you all ! for your Value inputs.The problem was, I was trying to connect RS232 Serial(Works with Negative Voltages) to TTL serial interface(Works with 0 to some Positive Voltages) used in Arduino. Apparently,I was supplying negative voltages to Arduino whereas it was expected to give Positive voltages. So, got a RS232-to-TTL connector and it worked,finally.