Go Down

Topic: How to read serial data from Non-contact Ultrasonic liquid level sensor  (Read 2333 times) previous topic - next topic

koblaevans

Hello,

I am trying to read data from a liquid level ultrasonic sensor, with the attached specification.

Pin 1 (Red): VCC DC 3.3V
Pin 2 (Black): GND
Pin 3 (White): RX
Pin 4 (Yellow): TX

The output format is RS232. I am using a RS232 to TTL converter to connect to arduino.

How do I read serial data from the sensor in arduino.

Thanks for your support.

wvmarle

Use the hardware Serial pins of your Arduino and the normal Serial library, set to the correct baud rate. Connect the converter's TX to Arduino RX and the other way around.

With the wiring you show you should be using SoftwareSerial.

By the way, are you sure this is an ultrasound sensor, not a capacitive sensor? Please post a link to its data sheet.




Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.


wvmarle

Other than it's shocking price, that's a very interesting sensor.
It is just glued to the bottom of the container, right?
Where's it's data sheet or manual?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

wvmarle

Housing indicates it's weather proof but no claims of that on any of the many sites that sell it.

No information on how to read this sensor, at all. It's also known as DYP-1603.

It apparently can be use as level switch if mounted to the side of a tank, and as absolute level sensor (no word on calibration; unsure whether the wall thickness has any effect) for 50-1000 or even 50-2000 mm liquid depths when mounted on the bottom of (i.e. beneath) the tank.

There are various versions of the sensor: DS1603AQ (analog output), DS1603NF (level switch - only a high/low signal), DS1603DA (UART/Serial output) and finally DS1603L which appears to have UART output, and a fifth wire marked "OUT" - my best guess is that this is meant to be a level switch.

And here you go, something that closely resembles a manual on this page. The UART is apparently 9600 bps TTL compatible (provided you supply it 5V it should never get over that voltage, and it apparently will also work on 3.3V). Quite irritating that the text is in the form of images so Google Translate doesn't work.

Prices on Alibaba/Taobao are RMB85 for single units, and go down to RMB68 in volume which is a lot friendlier price already :-)
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

wvmarle

OK, got some translation done.

It's a slowish sensor: one measurement per second; no liquid detection takes 10 seconds; liquid present 2 seconds. Good enough for most practical purposes.

No word on how to initiate conversion or so. Power with 3.3-12V, typical 5V, TTL compatible UART output. So it should be possible to connect direct to Arduino's RX/TX pins.

9600 bps, 8 data bits, one stop bit, no parity bit.
4 bytes of data:
- header: fixed value 0xFF
- Data_H: high byte of height.
- Data_L: low byte of height.
- SUM: a checksum.

Checksum: (header + Data_H + Data_L) & 0x00FF
Height in mm: Data_H * 256 + Data_L

LED on: sensor powered but no liquid detected.
LED flash (one per second): liquid detected.

No word on how to initiate conversion or communication - my best guess is that the sensor measures continuously and simply transmits every second.

Power consumption: <35 mA. Peak current: 100 mA @5V, ripple max 50 mV, noise max 100 mV.

50-2000 mm level; max. error 3 mm + 0.5% of height.

Use temperature: -15 to 60 C; humidity max 80%; no condensation.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

koblaevans

Thanks for the translation.

I tried reading data from the sensor with this code.



byte byteRead;
#include <SoftwareSerial.h>

#define txPin 3                                         
#define rxPin 2

SoftwareSerial sonarSerial(rxPin, txPin);

void setup() {
  Serial.begin(9600);                                     
  sonarSerial.begin(9600);                                 
  delay(500);                                             
 
}

void loop() {

   while(sonarSerial.available())
      {       
         byteRead  =  sonarSerial.read();
          Serial.println(byteRead);
      } 
}





but it outputs

0
254
2

continuously.


I also tried connecting directly to arduino, and the output is

255
0
0
255

continuously

wvmarle

Oh, continuous stream of data. That's why that header, then. Makes sense.

255 - 0 - 0 - 255 would be a single set of readings (header, data_h, data_l, sum). That's when the sensor is not attached to a container filled with liquid, right?

The first set of numbers doesn't make sense to me. It should for starters be series of four numbers.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

koblaevans

@wvmarle Thanks very much for your contribution.

I connected the sensor directly to arduino and like you said, 255-0-0-255 means no liquid present.
When liquid is detected it outputs a fixed 255 and three other numbers depending on the height of the liquid.

I'll just have to do some calibration with different types of liquids.

The package came with a glue(fluid), which I had to apply on the surface of the container before it could detect the liquid present.

Thanks so much wvmarle!!!  :)  :)  :)

wvmarle

Thanks for reporting back. I am definitely going to try out these sensors myself, too.

If your liquid is water, there's a fair chance little or no calibration is needed. After all the speed of sound in water is fairly constant, and it seems all parameters of the sensor are based on use with water.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

koblaevans

What do u think about using it to measure liquid in propane tank.
How did you determine that the parameters of the sensors are based on water?

wvmarle

Several times the manufacturer talks about measuring the level of water, and calibrating with water.
Water is probably the most common liquid on this planet, it's cheap and readily available, and pretty safe in use. So it makes sense they use water for that.
I suppose it will work just fine with propane, they do talk all the time about "any liquid that can not be touched" such as corrosive and flammable liquids.
The principle seems to be entirely based around bouncing ultrasound waves off the liquid's surface, so I don't see why it wouldn't work for other liquids. You'll have to calibrate for your liquid (though if you look up the speed of sound in water vs. propane you should be able get a reasonable estimate on how to calculate one from the other).
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

wvmarle

Just got one of those sensors myself - reading the data is no problem but I can't get it to detect water. I tried pushing it to the bottom of various containers, but nothing seems to work.

The package did include some kind of adhesive, so maybe its not making good enough contact. How did you fare in this?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

DaveEvans

Too bad you didn't buy two - so you could dissect one and see what's inside. :)




I tried pushing it to the bottom of various containers, but nothing seems to work.
You mean you held it tight up against the bottom (outside) of various containers?  Did you use the adhesive?  Seems like it probably needs the adhesive for proper coupling.

Did you try steel containers?  What wall thickness and size?

But anyway, it is a bit hard to believe this could work (finding fluid depth when mounted on the outside of a vessel)...especially if the wall is thick.


wvmarle

in fact I have two of them.

But not going to dissect any before I got at least one working :-) It seems the problem I have is in the contact with the container. Gotta rig up a test thing with batteries and LCD or so, make it more mobile. At least reading the thing is pretty straightforward, every 2 seconds it will simply transmit a reading.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up