Sensor shows the same value - A02YYUW

Hi everybody,

I am completely new in this Arduino environment and I have a project that I’m gonna use waterproof ultrasonic sensor A02YYUW.

I am using Arduino Nano. When I upload the code below, I am getting the same values. Even the location of the sensoris constant, the values are same and I am getting the value of 0 cm mostly. I dont know how it is possible.

I did the same connections as sample project.

Could you please check and give me some support on my project?

Thanks in advance!

Can I know some details of your project. Is it the waterproof sensor and you are measuring the values in the water right ?

I am building a robotic fish. Yes it is a waterproof sensor. It is strange but I got the same values even if i put the sensor in the water.

That code appears to be for a standard ultrasonic distance sensor.
The sensor you have has a special serial interface. Here is a description which includes a code sample: A02YYUW Waterproof Ultrasonic Sensor Wiki - DFRobot

Hi 6v6gt,

I have tried that sample code as well. But the sensor gives strange values. You may see below. I do not understand what is wrong. :pensive:

Change the baud rate on your serial console from 9600 to this 57600 . If that fails, post the code you used for that test.

I got this ERROR message when I changed the baud rate.

Here is the code that I am using:

/*
*@File : DFRobot_Distance_A02.ino
*@Brief : This example use A02YYUW ultrasonic sensor to measure distance
* With initialization completed, We can get distance value
*@Copyright [DFRobot](http://www.dfrobot.com),2016
* GUN Lesser General Pulic License
*@version V1.0
*@data 2019-8-28
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A0,A2); // RX, TX
unsigned char data[4]={};
float distance;
void setup()
{
Serial.begin(57600);
mySerial.begin(9600);
}
void loop()
{
do{
for(int i=0;i<4;i++)
{
data[i]=mySerial.read();
}
}while(mySerial.read()==0xff);
mySerial.flush();
if(data[0]==0xff)
{
int sum;
sum=(data[0]+data[1]+data[2])&0x00FF;
if(sum==data[3])
{
distance=(data[1]<<8)+data[2];
if(distance>30)
{
Serial.print("distance=");
Serial.print(distance/10);
Serial.println("cm");
}else
{
Serial.println("Below the lower limit");
}
}else Serial.println("ERROR");
}
delay(100);
}

Try changing this line:

else Serial.println("ERROR");

To:

else { 
   Serial.println("ERROR");
   Serial.print( data[0] ,HEX ); Serial.print( data[1] ,HEX ); Serial.print( data[2] ,HEX ); Serial.println( data[3] ,HEX ) ;
}
   

And post the output.

Nothing changed. :pensive:

Yes, the results don't look very good.

  1. Are you sure the model of the sensor is A02YYUW and it resembles that in the link in post #4 ?
  2. How have you wired it. Exactly as in the schematic in the linked documentation ?
  1. I am positive. I have bought this sensor through the link below. I have checked the datasheet which is in the link and did the wiring according to this.
  1. I have wired the sensor as below.

I can't see what colour wires go into the sensor, but these must match your pin definitions iny our code here:

The Green wire appears to be RX from the illustration in the documentation, but it is not clear if that is a standard. It appears to be different to your wiring. Anyway, just check it again.

You are right, my wiring was not correct :sweat_smile:

Anyway, I am getting these values right now. It does not seem stable. Is it normal or is there still a problem?


ı

A couple of random thoughts after looking around for more details on this sensor ...

  1. It seems that the Rx input to the sensor is not a serial input but a discrete signal which appears to alter the amount of signal processing the module does before outputting the result.

From the previous link to the product: "When "RX" floats or input High level, the module outputs processed value, the data is more steady, response time: 100-300ms; when input Low level, the module outputs real-time value, response time: 100ms."

  1. I wonder if the software serial port is losing track of the start of each message from the sensor?

When you get valid readings from the sensor, do they tie in with the distance to the object in front of the sensor?

  1. you can now remove the additional debug code suggested in post #8
  2. did you make any changes to the positioning of the sensor or the object in front of it. ? The jump from around 7cm to around 60cm would otherwise be difficult to explain.

The "waterproof" ultrasonic sensor A02YYUW is really just rainproof, and will work only in air.

For underwater distance measurements, very different transducers and circuitry are required (fish finders, for example).

This is the English language link..
Paul