ESP32

A02YYUW Waterproof Ultrasonic Sensor UART and PWM

A02YYUW UART and PWM:

A02YYUW Waterproof Ultrasonic Sensor UART and PWM- If I made this mistake, then I’m sure it’s something that could happen to you at some point too. These are both A02YYUW waterproof ultrasonic sensors; but still, they are not the same. Because one of them is a UART type and the other one is PWM. Which one is the best out of these two, I will explain in just a bit.

A02YYUW UART and PWM

Design-wise, they are exactly the same, their front, their backside, even their wires are the same. Just by looking at these sensors, you can’t tell which one is the UART and which one is the PWM.

How did I find out, well let me tell you. I had already made a detailed video and I have also written quite a detailed article about the UART version of the A02YYUW Waterproof ultrasonic sensor.




After a few days, I needed some more Ultrasonic Sensors so I went on Amazon and purchased 5 ultrasonic sensors. At that time, I didn’t even know there was a PWM version of this Ultrasonic sensor. So, I placed the order without checking.

A02YYUW UART and PWM

Anyway, when I received the ultrasonic sensors and connected them to the board, the Serial monitor was not giving me any output.

A02YYUW UART and PWM

At first, I thought maybe the ultrasonic sensor was faulty. So, I tried another Ultrasonic sensor, but I didn’t get any output from that one either. Just like this, I tested all the Ultrasonic sensors one by one.

And when I would connect the UART version of the A02YYUW Ultrasonic Sensor, it would work perfectly.

A02YYUW UART and PWM



Anyway, to confirm those ultrasonic sensors, I went back to Amazon and when I saw, there were two types: PWM and UART. So, it was totally my mistake because I wasn’t aware of the versions.

A02YYUW UART and PWM

Anyway, for the PWM version of the A02YYUW waterproof ultrasonic sensor, I wrote another program and then it started to work.

Now, let me explain which one is the best; the UART or the PWM version.

Amazon Links:

A02YYUW Waterproof Ultrasonic Sensor

ESP32 WiFi + Bluetooth Module(Recommended)

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



A02YYUW UART Vs PWM:

The A02YYUW waterproof ultrasonic sensor comes in two versions that differ primarily in their communication methods: PWM (Pulse Width Modulation) and UART (Universal Asynchronous Receiver/Transmitter). Here’s a basic overview of the differences between the PWM and UART versions, how distance calculations are handled, and insights into which might be best depending on your application.

PWM Version

Communication Method: The PWM version outputs distance measurements as the width of a pulse signal. The duration of the pulse width directly correlates to the distance measured by the sensor.

Distance Calculation: In the PWM version, the sensor itself calculates the distance based on the time it takes for the ultrasonic pulse to travel to an object and back. The microcontroller or receiving device then measures the pulse width to determine the distance. The formula for calculating distance generally involves the speed of sound and the time of flight of the ultrasonic pulse.

UART Version

Communication Method: The UART version communicates over a serial interface, sending distance measurements as serial data. This allows for more complex data transmission compared to PWM and can include additional information such as error codes or sensor status.

Distance Calculation: Just like the PWM version, the UART version calculates distance using the time of flight principle. However, with UART, the distance calculation is often done on the sensor, and the result is sent to the microcontroller or receiving device as a digital value. This can simplify the integration process, as the receiving device does not need to measure pulse widths but simply reads the digital data sent from the sensor.



Which is Best and Why?

The “best” choice between PWM and UART versions of the A02YYUW waterproof ultrasonic sensor depends on your specific application requirements:

Simplicity and Ease of Integration: If your project or device has limited pins or you prefer a simpler integration, the UART version might be more suitable. It communicates via serial communication, which is straightforward to implement in most microcontrollers and allows for easy interpretation of data.

Real-Time Performance: If your application requires direct and real-time distance measurements without much processing overhead, the PWM version could be advantageous. It provides a direct measurement in the form of pulse width, which can be quickly interpreted by measuring the time the pulse is high.

Complexity and Flexibility: If you need more complex data or wish to implement error handling based on sensor feedback, the UART version provides a more flexible communication protocol. This can be particularly useful in applications where sensor status and diagnostic information are critical.

Distance Calculation

Both versions calculate distance using the ultrasonic time-of-flight principle. The sensor emits an ultrasonic pulse that travels through the air, hits an object, and reflects back to the sensor. The sensor measures the time it takes for the pulse to return. Given that the speed of sound in air is approximately 343 meters per second (at room temperature), the sensor calculates the distance to the object by using the formula:

Distance = (Speed of Sound×Time of Flight) / 2

The division by 2 accounts for the fact that the sound wave travels to the object and back, effectively doubling the travel time for the measured distance.




My personal analysis:

The UART version of the sensor typically performs distance calculations internally and sends the result to the microcontroller or another receiving device as a digital value. This approach can significantly simplify the integration process. Unlike the PWM version, which requires the receiving device to measure pulse widths—a process that involves accurately timing the duration of signal highs—the UART version communicates the calculated distance directly via serial data. This direct communication not only simplifies programming by eliminating the need for code that measures time intervals but also conserves processing resources on the microcontroller. Since the microcontroller or receiving device no longer needs to allocate cycles to capture and calculate pulse widths, it can use these resources for other tasks or enter a low-power state to save energy.

Additionally, having the sensor handle distance calculations can increase measurement accuracy and reliability. Since the sensor is designed specifically for ultrasonic distance measurement, it can apply precise timing and correction algorithms that might be difficult to implement accurately on a general-purpose microcontroller. Factors such as temperature variations, which affect the speed of sound, and other environmental conditions can be more accurately accounted for within the sensor’s firmware. Moreover, digital communication via UART reduces the risk of errors associated with signal timing and interpretation, further enhancing the reliability of the distance measurements.

In essence, while both PWM and UART versions serve the primary function of measuring distances using ultrasonic waves, the UART version’s approach to data communication offers distinct advantages in ease of integration, programming simplicity, processing efficiency, and potential accuracy of measurements. These benefits make the UART version particularly appealing for complex applications or when multiple sensors need to be managed simultaneously, as it streamlines both the hardware and software aspects of sensor integration.

So, my choice is the UART version of the A02YYUW Waterproof Ultrasonic Sensor. If you have never used this sensor before then I highly recommend you should watch my getting started video. Because, in that video, I have explained all the technical specification and how to use it with Arduino, ESP32, and Nodemcu ESP8266 WiFi module.

A02YYUW UART and PWM

Right now, I have connected the UART version of the A02YYUW waterproof ultrasonic sensor. And don’t get confused with the board; its just a development board. Actually, I designed it for the SIM7600G 4G LTE module. I will add a link in the description if you would like to make the same development board. Anyway, you can also do the same exact connections on a breadboard.



Anyway, for the connections you can follow this circuit diagram.

A02YYUW UART and PWM

A02YYUW UART Version Programming:



A02YYUW PWM Version Programming:

Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button