A02YYUW Waterproof Ultrasonic Distance Sensor

View on Amazon
Overview
About A02YYUW Waterproof Ultrasonic Distance Sensor
The A02YYUW is a waterproof ultrasonic sensor designed for precise distance measurement in harsh environments. With an IP67-rated enclosure, it is dustproof and waterproof, making it ideal for outdoor and industrial applications.
⚡ Key Features
- Wide Measurement Range – Detects distances from 3 cm to 450 cm.
- IP67 Waterproof & Dustproof – Built for moist, outdoor, and industrial environments.
- Reliable UART Communication – Provides stable distance readings via a UART interface.
- Versatile Applications – Used in liquid level detection, obstacle avoidance, and proximity sensing.
The A02YYUW is a great choice for rugged IoT applications, ensuring reliable performance in challenging conditions. 🚀
Get Your A02YYUW
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
A02YYUW Specifications
Complete technical specification details for A02YYUW Waterproof Ultrasonic Distance Sensor
📊 Technical Parameters
A02YYUW Pinout
The A02YYUW pinout includes four pins: VCC (power), GND (ground), TX (UART transmit), and RX (UART receive). The sensor communicates distance data via UART protocol.
Visual Pinout Diagram

Pin Types
Quick Tips
ultrasonic distance sensor with IP67 rating,Measurement range: 3 cm to 450 cm,Resolution: 1 mm
±1 cm,UART baud rate: 9600 bps (8N1: 8 data bits, no parity, 1 stop bit),Operating voltage: 3.3V to 5.5V (5V recommended)
temperature: -15°C to +70°C,Waterproof and dustproof (IP67) for outdoor use
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply input (3.3V to 5.5V) | Recommended 5V for optimal performance |
2 GND | Ground | Ground connection | Connect to common ground |
3 TX | UART TX | UART Transmit Data (sensor output) | Connects to microcontroller RX pin |
4 RX | UART RX | UART Receive Data (sensor input) | Connects to microcontroller TX pin (optional) |
Wiring A02YYUW to ESP32
Connect the A02YYUW to your ESP32 via UART. The sensor transmits distance readings automatically via the TX pin. Power the sensor with 5V for best performance, though 3.3V operation is supported.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| A02YYUW Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 5V or 3.3V | Power supply (5V recommended) | |
2 GND Required | GND | Ground connection | |
3 TX Required | GPIO16 (RX2) | Sensor TX to ESP32 RX (distance data) | |
4 RX Optional | GPIO17 (TX2) | Sensor RX to ESP32 TX (optional) |
communication: 9600 baud, 8 data bits, no parity, 1 stop bit
transmits distance data automatically every 100-300ms
format: 4-byte frame (0xFF start byte + 2 distance bytes + checksum)
pin is optional - sensor works in output-only mode
power recommended for maximum range and accuracy
waterproof rating - suitable for outdoor installations
placing sensor near other ultrasonic devices (interference)
sensor perpendicular to target surface for best accuracy
or angled surfaces may affect accuracy
changes affect speed of sound - consider compensation
A02YYUW Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The A02YYUW ultrasonic sensor provides constant or incorrect distance measurements, regardless of the actual distance to the target.
Possible causes include incorrect wiring, insufficient power supply, or improper sensor configuration.
Solution: Ensure that the sensor is connected to a stable 5V power source, as it requires 5V for proper operation. Verify that the sensor's TX (transmit) and RX (receive) lines are correctly connected to the corresponding RX and TX pins on the microcontroller, respectively. Confirm that the baud rate for serial communication is set to 9600 bps, as required by the sensor.
Issue: The sensor outputs distance readings that vary significantly, even when the target distance remains constant.
Possible causes include environmental factors such as temperature variations, soft or angled target surfaces, or electrical noise.
Solution: Position the sensor perpendicular to a hard, flat target surface to ensure accurate reflections. Be aware that temperature changes can affect the speed of sound; consider implementing temperature compensation if precise measurements are required. Implement averaging of multiple readings in your code to mitigate occasional erroneous data.
Issue: The microcontroller fails to detect the A02YYUW sensor, or the sensor does not respond to trigger signals.
Possible causes include incorrect pin assignments in the code, lack of proper initialization, or defective sensor module.
Solution: Double-check the pin assignments in your code to ensure they match the physical connections. Confirm that the sensor is properly initialized in the setup section of your code. If the issue persists, test the sensor with a known working setup or replace it to rule out hardware failure.
Issue: External factors cause the sensor to produce unreliable readings.
Possible causes include high ambient noise levels, temperature variations, or obstacles in the sensor's field of view.
Solution: Operate the sensor in a controlled environment to minimize acoustic and electrical noise. Be aware that temperature changes can affect the speed of sound; consider implementing temperature compensation if precise measurements are required. Ensure that there are no unintended obstacles within the sensor's detection range that could cause false readings.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
A02YYUW Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Arduino.h>
// Define ESP32 hardware serial port for the A02YYUW sensor
#define A02YYUW_TX 18 // ESP32 TX connected to Sensor RX
#define A02YYUW_RX 5 // ESP32 RX connected to Sensor TX
// Initialize hardware serial for A02YYUW
HardwareSerial mySerial(2);
void setup() {
Serial.begin(115200); // Initialize Serial Monitor
mySerial.begin(9600, SERIAL_8N1, A02YYUW_RX, A02YYUW_TX); // Initialize UART2
Serial.println("A02YYUW Distance Sensor Example");
}
void loop() {
if (mySerial.available() >= 4) {
uint8_t data[4];
for (int i = 0; i < 4; i++) {
data[i] = mySerial.read();
}
if (data[0] == 0xFF) { // Check packet start byte
int sum = (data[0] + data[1] + data[2]) & 0xFF;
if (sum == data[3]) { // Validate checksum
int distance = (data[1] << 8) + data[2]; // Calculate distance
if (distance > 30) { // Ensure valid reading
Serial.print("Distance: ");
Serial.print(distance / 10.0);
Serial.println(" cm");
} else {
Serial.println("Below the lower limit");
}
} else {
Serial.println("Checksum error");
}
}
}
delay(100);
}#include <stdio.h>
#include "driver/uart.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define RXD_PIN 16
#define TXD_PIN 17
#define UART_NUM UART_NUM_1
#define UART_BUFFER_SIZE (1024 * 2)
#define UART_TIMEOUT_MS 20
static const char *TAG = "UART_SENSOR";
void init_uart(void) {
// Configure UART parameters
const uart_config_t uart_config = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
// Apply UART configuration
ESP_ERROR_CHECK(uart_param_config(UART_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(UART_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
// Install UART driver with RX buffer and a small TX buffer
ESP_ERROR_CHECK(uart_driver_install(UART_NUM, UART_BUFFER_SIZE, 512, 0, NULL, 0));
// Set UART mode explicitly
ESP_ERROR_CHECK(uart_set_mode(UART_NUM, UART_MODE_UART));
}
void uart_task(void *pvParameters) {
uint8_t data[4];
while (1) {
// Read 4 bytes from UART
int len = uart_read_bytes(UART_NUM, data, 4, pdMS_TO_TICKS(UART_TIMEOUT_MS));
if (len == 4 && data[0] == 0xFF) {
// Calculate checksum
int sum = (data[0] + data[1] + data[2]) & 0xFF;
if (sum == data[3]) {
// Convert distance to centimeters
int distance = (data[1] << 8) | data[2];
if (distance > 30) {
ESP_LOGI(TAG, "Distance: %.2f cm", distance / 10.0);
} else {
ESP_LOGW(TAG, "Below the lower limit");
}
} else {
ESP_LOGE(TAG, "Checksum error (Received: 0x%02X, Expected: 0x%02X)", data[3], sum);
}
} else if (len > 0) {
ESP_LOGW(TAG, "Invalid data received");
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void app_main(void) {
init_uart();
xTaskCreate(uart_task, "UART Task", 4096, NULL, 5, NULL);
}uart:
tx_pin: GPIO5
rx_pin: GPIO18
baud_rate: 9600
sensor:
- platform: a02yyuw
name: "A02YYUW Distance"
update_interval: 100ms
timeout: 2suart platform to interface with the A02YYUW sensor. The tx_pin and rx_pin specify the GPIO pins used for UART communication. The baud_rate is set to 9600 to match the sensor's communication protocol. The sensor component configures the A02YYUW as the distance sensor, with a user-friendly name 'A02YYUW Distance.' The update_interval specifies that measurements are taken every 100 ms, and the timeout ensures reliable communication by preventing prolonged wait times for data.platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200main.cpp
#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 18); // RX, TX
void setup() {
Serial.begin(115200);
mySerial.begin(9600);
Serial.println("A02YYUW Distance Sensor Example");
}
void loop() {
if (mySerial.available() >= 4) {
uint8_t data[4];
for (int i = 0; i < 4; i++) {
data[i] = mySerial.read();
}
if (data[0] == 0xFF) {
int sum = (data[0] + data[1] + data[2]) & 0xFF;
if (sum == data[3]) {
int distance = (data[1] << 8) | data[2];
if (distance > 30) {
Serial.print("Distance: ");
Serial.print(distance / 10.0);
Serial.println(" cm");
} else {
Serial.println("Below the lower limit");
}
} else {
Serial.println("Checksum error");
}
}
}
delay(100);
}from machine import UART
from time import sleep
# Configure UART
uart = UART(2, baudrate=9600, tx=5, rx=18)
def read_distance():
if uart.any() >= 4:
data = uart.read(4)
if data[0] == 0xFF:
checksum = (data[0] + data[1] + data[2]) & 0xFF
if checksum == data[3]:
distance = (data[1] << 8) | data[2]
if distance > 30:
return distance / 10.0
else:
return "Below the lower limit"
else:
return "Checksum error"
return None
print("A02YYUW Distance Sensor Example")
while True:
result = read_distance()
if result:
print(f"Distance: {result} cm")
sleep(0.1)read_distance() function reads 4 bytes of data from the UART buffer, validates the header and checksum, and calculates the distance in millimeters. The result is converted to centimeters and returned. The main loop continuously calls this function every 100 ms to print the distance to the console. If the sensor detects an issue, such as a checksum error or a distance below the minimum threshold, appropriate messages are displayed.Wrapping Up A02YYUW
The ESP32 A02YYUW Waterproof Ultrasonic Distance Sensor is a powerful distance sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the A02YYUW into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the A02YYUW? Check out these similar sensors that might fit your project needs.

VL53L1X Time-of-Flight Sensor
The VL53L1X is a high-accuracy long-distance laser-ranging sensor from STMicroelectronics. It uses a 940nm VCSEL emitter and advanced SPAD...

HC-SR04 Ultrasonic Distance Sensor
The HC-SR04 is a versatile ultrasonic distance sensor capable of measuring distances up to 4 meters with high precision. It is widely used...

TOF050C Time-of-Flight Sensor
The TOF050C is a short-range laser-ranging sensor using the VL6180 chip, offering highly accurate distance measurements up to 50 cm. It is...





