Thumbnail

Ultrasonic Collision Detection

Stops robot movement (no steering) when an EZB-connected ultrasonic sensor detects an object within a set range; integrates with scripting and paused polling.

How to add the Ultrasonic Collision Detection robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the Ultrasonic category tab.
  5. Press the Ultrasonic Collision Detection icon to add the robot skill to your project.

Don't have a robot yet?

Follow the Getting Started Guide to build a robot and use the Ultrasonic Collision Detection robot skill.


How to use the Ultrasonic Collision Detection robot skill

Ultrasonic sensors measure distance using sonar (sound navigation and ranging). The sensor sends out a high‑frequency “ping” and listens for the echo. The time it takes for the echo to return is converted into a distance reading—similar to how bats and dolphins “see” with sound.

When an HC-SR04 (or equivalent) Ultrasonic Distance Sensor is connected to an EZB, the Ultrasonic Collision Detection skill can automatically send a Stop command to a Movement Panel when an object is too close.


How It Works (Beginner Explanation)

  • The sensor constantly (or periodically) measures distance.
  • The skill compares the measured value to your Minimum Distance setting.
  • If the sensor reports an object inside that minimum range, the skill:
    • Turns the distance indicator red
    • Sends Stop to the configured movement panel(s)

This skill is designed to help prevent collisions when driving forward (or in any direction your movement panel is commanding). It’s especially useful for beginner projects where you want a simple “stop before hitting something” safety behavior.


Scripting Integration (PAUSE + GetPing)

This skill is integrated with ARC scripting. If the PAUSE checkbox is checked, the skill will not continuously poll the sensor. Instead, it updates when your script calls:

GetPing(digitalTriggerPort, digitalEchoPort)

Understanding the Distance Value (0–255)

The distance shown by this skill is a value from 0 to 255. It is not displayed directly in centimeters or inches. The reading can vary based on:

  • Sensor type/model (HC-SR04 vs. other ultrasonic boards)
  • Voltage and wiring
  • Surface type and angle (hard flat wall vs. fabric)
  • Temperature and environment

Main Window

Ultrasonic Collision Detection main window annotated

1) Ultrasonic Distance Value

Shows the current sensor reading (0–255). Green means the object is farther than your minimum distance. Red means the object is within your minimum distance and the skill will stop the movement panel.

2) Bar Display

A visual bar representation of the same distance value. This is helpful for quickly seeing changes as you move closer/farther from an object.

3) Pause Checkbox

When checked, the skill stops continuously reading the sensor. Use this if you only want readings when a script calls GetPing().


Settings

Ultrasonic Collision Detection settings annotated

The name of this skill in your ARC project. You can rename it to match your robot (example: “Front Ultrasonic Stop”).
Note: Renaming also changes the name used by ControlCommand() for this skill.

Choose which EZB you are using (EZB #0, #1, etc.). If you only have one EZB connected, it is usually 0.

Select the digital port where the sensor’s TRIG wire is connected. This is the pin used to send the “ping” signal.

Select the digital port where the sensor’s ECHO wire is connected. This is the pin used to read the returning echo.

Note (3‑wire sensors): If your ultrasonic sensor combines Trigger and Echo into one signal wire, the Echo port must be set to the same digital port as Trigger.

How often the skill samples the sensor (in milliseconds). Range: 100–60000 ms. Default: 250 ms.
  • Lower number = faster updates, more responsive stopping
  • Higher number = fewer reads, less communication usage

The threshold where a “collision” is considered detected. If the sensor reading reaches this value (or closer), the value turns red and the skill sends Stop to the movement panel. Range: 1–255. Default: 30.

Beginner tip: Start with the default, then test slowly. Increase the minimum distance if your robot doesn’t stop early enough.

Wiring Diagram

Ultrasonic distance sensors commonly come in two wiring styles: 3‑wire (Trigger/Echo combined) and 4‑wire (Trigger and Echo separate). Some include a voltage regulator.

Ultrasonic sensor wiring diagram
3‑wire Wiring (with built‑in regulator)
  • Ground: Black wire to GND
  • Power: Red wire to Vin
  • Trigger/Echo: White wire to a Digital port
In ARC settings, set Trigger Port and Echo Port to the same digital port.
4‑wire Wiring (with regulator)
  • Ground: Black wire from regulator to GND
  • Power: Red wire from regulator to Vin
  • Trigger: White wire to a Digital port
  • Echo: Green wire to a second Digital port
In ARC settings, choose the matching digital ports for Trigger and Echo.

Fix: False Positives / Resolution Improvement

If you use an EZ-Robot ultrasonic distance sensor, you may see occasional false positives caused by the ping echoing inside the sensor casing (resonance). A simple fix is to place a few cotton balls inside the case around the sensors to reduce the internal echo.

Tech Detail Video


Resources

Synthiam provides an ultrasonic hardware reference design here.


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!