# A0221AU ultrasound distance sensor

**URL:** <https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864>\
**Category:** Sensors\
**Created:** [June 5, 2025, 8:31am UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864 "2025-06-05T08:31:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![geert\_borloo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geert_borloo/32/1127292_2.png) [@geert\_borloo](https://forum.arduino.cc/u/geert_borloo)\
**Post date:** [June 5, 2025, 8:31am UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/1 "2025-06-05T08:31:36Z")

</div>

Hi all,  
I bought 2 A0221AU UART ultrasonic distance sensors.  
I tried both with the official arduino code on an Arduino Uno R3, checked the code several times, ... but the sensors (both were tested repeatedly) does not measure the correct distance.  
Most of the time, the same distance is given (value around 1467mm), and at random moments other distances are given but never the correct distance.

I ordered both via Amazon, in reality I ordered the A02yyuw but they delivered the A0221AU instead.

Did anyone over here have the same problem and has a solution?  
Thanks  
G.

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [June 5, 2025, 9:21am UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/2 "2025-06-05T09:21:59Z")

</div>

> [@geert\_borloo](#):
>
> tried both with the official arduino code on an Arduino Uno R3,

Please show the code and your connection diagram.

[Read the forum guidelines](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems) to see how to properly ask a question and some good information on making a good post. You will get faster and better help if you post all your code as requested by the forum guidelines.

---

<div class="post-metadata">

**Author:** ![geert\_borloo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geert_borloo/32/1127292_2.png) [@geert\_borloo](https://forum.arduino.cc/u/geert_borloo)\
**Post date:** [June 6, 2025, 6:12am UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/3 "2025-06-06T06:12:16Z")

</div>

Hello,

Below the code I used for testing both sensors.

#include \<SoftwareSerial.h\>  
int distance = 0;  
int pinRX = 10;  
int pinTX = 11;  
unsigned char data\_buffer[4] = {0};  
unsigned char CS;

// Object to represent software serial port  
SoftwareSerial mySerial(pinRX, pinTX);

void setup() {  
// put your setup code here, to run once:  
Serial.begin (9600);

// Set up SoftwareSerial port  
mySerial.begin(9600);  
}

void loop() {

// Check if data available on mySerial port  
if (mySerial.available() \> 0) {  
delay (4);

```
if (mySerial.read() == 0xff) { // detect 0xff (= delimiter) before reading the 4 data bytes
  data_buffer[0] = 0xff;
  for (int i = 1; i < 4; i++) { // Read 4 data bytes
    data_buffer[i] = mySerial.read();
  }

  // compute CheckSum
  CS = data_buffer[0] + data_buffer[1] + data_buffer[2];
  if (data_buffer[3] == CS) {
    distance = (data_buffer[1] << 8) + data_buffer[2];
  }
}

```

}

if (distance \>= 4000 || distance \<= 30) {  
Serial.println("OutOfRange");  
}  
else {  
// Serial.print (Dip1); Serial.print (Dip2);  
Serial.print (distance);  
Serial.println (" mm");  
}  
delay(2000);  
}

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [June 6, 2025, 6:16am UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/4 "2025-06-06T06:16:40Z")

</div>

Please edit the code using a code tags. If you don't know how to insert the code, read the link that I posted in #2

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [June 6, 2025, 1:37pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/5 "2025-06-06T13:37:24Z")

</div>

> [@geert\_borloo](#):
>
> Did anyone over here have the same problem and has a solution?

here I have an example for the A02YYUW:

[A02YYUW Ultrasonic Sensor readout with Arduino (Serial)](https://werner.rothschopf.net/microcontroller/202201_a02yyuw_ultrasonic_sensor_en.htm)

it seems it has the same protocol.

---

<div class="post-metadata">

**Author:** ![geert\_borloo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geert_borloo/32/1127292_2.png) [@geert\_borloo](https://forum.arduino.cc/u/geert_borloo)\
**Post date:** [June 6, 2025, 8:33pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/6 "2025-06-06T20:33:45Z")

</div>

Hello noiasca,  
Thanks for the link.  
I have used that example as well, but the A0221AU sensors I have OR do not work with this code OR do not seem to work properly at all.  
They both give a distance of about 1460mm - whatever I do with the sensor itself - and then for no reason start to give more realistic measurements for a while, but never a very precise measurement.  
I wonder if the A0221AU sensor and the A02YYUW are exactly the same, or if there are some differences, but I cannot find any information on this question.  
thanks for helping and regards,  
G.

---

<div class="post-metadata">

**Author:** ![geert\_borloo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geert_borloo/32/1127292_2.png) [@geert\_borloo](https://forum.arduino.cc/u/geert_borloo)\
**Post date:** [June 6, 2025, 8:37pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/7 "2025-06-06T20:37:05Z")

</div>

```arduino
// LCD I²C library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // creation of lcd instance with address, #characters, #lines

#include <SoftwareSerial.h>
int distance = 0;
int pinRX = 10;
int pinTX = 11;
unsigned char data_buffer[4] = {0};
unsigned char CS;

// Object to represent software serial port
SoftwareSerial mySerial(pinRX, pinTX);

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);

  // Set up SoftwareSerial port
  mySerial.begin(9600);
}

void loop() {
  
  // Check if data available on mySerial port
  if (mySerial.available() > 0) {
    delay (4);
    
    if (mySerial.read() == 0xff) { // detect 0xff (= delimiter) before reading the 4 data bytes
      data_buffer[0] = 0xff;
      for (int i = 1; i < 4; i++) { // Read 4 data bytes
        data_buffer[i] = mySerial.read();
      }

      // compute CheckSum
      CS = data_buffer[0] + data_buffer[1] + data_buffer[2];
      if (data_buffer[3] == CS) {
        distance = (data_buffer[1] << 8) + data_buffer[2];
      }
    }
  }

  if (distance >= 4000 || distance <= 30) {
    Serial.println("OutOfRange");
    }
  else {
    // Serial.print (Dip1); Serial.print (Dip2); 
    Serial.print (distance);
    Serial.println (" mm");
  }
  delay(2000);
}

```

---

<div class="post-metadata">

**Author:** ![geert\_borloo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geert_borloo/32/1127292_2.png) [@geert\_borloo](https://forum.arduino.cc/u/geert_borloo)\
**Post date:** [June 6, 2025, 8:38pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/8 "2025-06-06T20:38:35Z")

</div>

Hi b707,  
I added the code in 'code tags' in #7.  
Sorry for my mistake, it's the first time that I'm using the forum to get some help.  
So thanks for your patience and the guidance !  
regards  
G.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 8, 2025, 6:03pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/9 "2025-06-08T18:03:19Z")

</div>

> [@geert\_borloo](#):
>
> first time that I'm using the forum

Just letting you re-re-know that the link in Post #2 points you to one place that lets you re-know the procedure to post code in a topic that you agreed to when you signed up for this account. You got it right on the fourth try. As you learn Arduino, programming and electronics (and a bicycle or a swing set), instructions are made to be followed the first time... or things don't happen... or bad things do happen. Be well.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 8, 2025, 7:06pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/10 "2025-06-08T19:06:53Z")

</div>

> [@geert\_borloo](#):
>
> They both give a distance of about 1460mm - whatever I do with the sensor itself - and then for no reason start to give more realistic measurements for a while, but never a very precise measurement.

Erratic behavior could be due to a wiring problem, poorly soldered joints, power problem etc. Please post a wiring diagram, a photo of your setup and links to the product pages for the parts.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 5, 2025, 7:07pm UTC](https://forum.arduino.cc/t/a0221au-ultrasound-distance-sensor/1386864/11 "2025-12-05T19:07:34Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
