

The M5Stack Ultrasonic is a compact sensor module designed to measure distances using ultrasonic waves. It emits high-frequency sound waves and calculates the time it takes for the echo to return, providing accurate distance measurements. This module is widely used in robotics, automation, and IoT projects for tasks such as obstacle detection, proximity sensing, and distance measurement.








The M5Stack Ultrasonic module is designed for ease of use and reliable performance. Below are its key technical details:
The M5Stack Ultrasonic module has a simple 4-pin interface. Below is the pinout:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin (3.3V to 5V) |
| 2 | TRIG | Trigger pin. Sends a 10µs pulse to initiate distance measurement. |
| 3 | ECHO | Echo pin. Outputs a pulse width proportional to the measured distance. |
| 4 | GND | Ground pin. Connect to the ground of the power supply. |
The M5Stack Ultrasonic module is straightforward to use in a circuit. Below are the steps and best practices for integrating it into your project.
Connect the Pins:
Trigger the Sensor:
Read the Echo:
Calculate the Distance:
Below is an example code snippet to use the M5Stack Ultrasonic module with an Arduino UNO:
// Define pins for the ultrasonic sensor
const int trigPin = 9; // TRIG pin connected to digital pin 9
const int echoPin = 10; // ECHO pin connected to digital pin 10
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set TRIG pin as output and ECHO pin as input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Send a 10µs HIGH pulse to the TRIG pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the duration of the HIGH pulse on the ECHO pin
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in cm
float distance = (duration * 0.034) / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Wait for a short period before the next measurement
delay(500);
}
No Output or Incorrect Readings:
Fluctuating Distance Measurements:
Sensor Not Responding:
Inaccurate Measurements:
By following this documentation, you can effectively integrate the M5Stack Ultrasonic module into your projects and troubleshoot common issues with ease.