The HC-SR04 is a non-contact ultrasonic distance sensor. It uses high-frequency sound waves (40 kHz) to calculate the distance to an object based on the time of flight of the echo. In Open Maker Studio, it is the primary sensor for obstacle avoidance, rangefinders, and distance monitoring.
1. Hardware Specifications & Pinout
- Operating Voltage: 5.0V (VCC).
- Detection Range: 2cm to 400cm (max ~4m).
- Resolution: 3mm.
- Pin Configuration:
- VCC: Connect to 5V.
- Trig (Trigger): Output pin. Sends the ultrasonic pulse.
- Echo: Input pin. Receives the return signal.
- GND: Common Ground.
[!CAUTION] 3.3V Board Protection: The HC-SR04 Echo pin outputs a 5V logic signal. Connecting it directly to a 3.3V GPIO pin on an ESP32, Pico, or Pico W will damage or destroy the GPIO pin. Use a voltage divider (e.g. 1kΩ from Echo → GPIO, and 2kΩ from GPIO → GND) or a dedicated logic level shifter module to drop the 5V Echo signal to 3.3V before connecting it to your board. Alternatively, use an HC-SR04P variant which natively operates at 3.3V.
2. How it Works & Distance Formula (Real Hardware)
On real hardware, the sensor operates through the following steps:
- The microcontroller holds Trig HIGH for 10 microseconds to transmit an 8-cycle sonic burst.
- The sensor automatically drives the Echo pin HIGH.
- The sonic wave travels out, hits an object, and reflects back.
- When the sensor receives the echo, it pulls the Echo pin LOW.
- The duration (in microseconds) that Echo stays HIGH represents the round-trip travel time of the sound wave.
- Distance Calculation:
Since the speed of sound is (or ), and the wave travels to the object and back, the distance is:
[!WARNING] This is real hardware behavior — see Section 6 for how OMS's simulator actually models this component, which is meaningfully different and affects whether the code below "just works" when tested in the Circuit Canvas.
3. Component Properties (Property Inspector)
When you select the Ultrasonic sensor on the canvas, you can modify the following parameter in the Property Inspector panel:
- Distance (
distance): Simulates the physical distance of the obstacle in front of the sensor.- Default:
50cm - Range:
2cm to400cm (step size1cm)
- Default:

