Communica

How to Use BMT Ultrasonic Sensor HC-SR04 in Robotics (South Africa Guide)

Learn how to wire, program and mount the BMT HC-SR04 ultrasonic sensor for robotics. Includes formulas, wiring examples, troubleshooting and South Africa buying notes.

sensors and semiconductors
January 12, 2026
5 min read

Wiring & Level Shifting

Use a resistor divider or level shifter for 3.3V GPIO; VCC should be 5V.

Distance Formula

Distance(cm) = Echo_time(us) * 0.01715 (adjust for temperature).

Practical Tips

Stagger sensors to avoid cross-talk and apply filtering for stable reads.

Overview: HC-SR04 in Mobile Robotics

The BMT ultrasonic sensor HC-SR04 is a low-cost, widely used module for short-range distance measurement (roughly 2 cm to 400 cm). In robotics it serves for obstacle detection, simple mapping, parking aids, and height/level sensing. This guide explains wiring, timing, calculations, mounting tips, and South Africa-relevant notes on availability and selection.

Key specs at a glance

Parameter Typical Value
Supply voltage 5 V
Operating range 2 cm - 400 cm (practical: 3-320 cm)
Measurement resolution ~3 mm
Trigger pulse 10 us pulse to TRIG
Echo output Pulse width proportional to distance

Why choose the HC-SR04 for robotics

  • Simple digital interface (TRIG/ECHO) integrates with microcontrollers (Arduino, ESP32) and single-board computers via a level shifter for 3.3 V GPIO.
  • Fast measurements (tens of ms) suitable for reactive navigation and obstacle avoidance.
  • Cost-effective and readily available through component distributors and maker stores in South Africa; typical module price ranges from ZAR 30 to ZAR 120 depending on brand and packaging (estimate).

Standards, Timing & Measurement Formula

Distance is derived from the echo pulse duration. Sound speed in air at 20 degreesC is about 343 m/s; adjust for temperature if precision is required. Use the standard formula below.

Distance calculation

Distance (cm) = (Echo time in microseconds) * (Speed of sound in cm/us) / 2

With speed of sound ~0.0343 cm/us at 20 degreesC:

Distance (cm) = Echo_time(us) * 0.01715

Example: 1500 us echo -> 1500 * 0.01715 = 25.7 cm

Trigger and timeout

  • Send a 10 microsecond pulse on TRIG to start a measurement.
  • Measure pulse width on ECHO. If ECHO stays low beyond expected max, implement a timeout to avoid blocking (e.g., 25 ms for ~4 m max range). For common problems and debugging see troubleshooting common issues with HC-SR04 sensors.

Related Sensors & Semiconductors Products

Discover quality sensors & semiconductors products related to How to Use BMT Ultrasonic Sensor HC-SR04 in Robotics (South Africa Guide)

Acm Mq2 Gas Sensor

Acm Mq2 Gas Sensor

CommunicaSensors
ZAR39.00

Acm Mq2 Gas Sensor

Dfrobot Sen0114 Arduino Compatible Soil Moisture Sensor

Dfrobot Sen0114 Arduino Compatible Soil Moisture Sensor

DFRobotSensors
ZAR69.00

Dfrobot Sen0114 Arduino Compatible Soil Moisture Sensor

Rfid Contactless Smart Reader & Writer - 13.56mhz Nfc Acr122u

Rfid Contactless Smart Reader & Writer - 13.56mhz Nfc Acr122u

CommunicaSensors
ZAR640.00

Rfid Contactless Smart Reader & Writer - 13.56mhz Nfc Acr122u

Electronic Load Cell Sensor 10kg

Electronic Load Cell Sensor 10kg

CommunicaSensors
ZAR42.00

Electronic Load Cell Sensor 10kg

Unassembled Diy Heatsink And Fan Cooler Kit For Use With A Thermoelectric Peltier Module

Unassembled Diy Heatsink And Fan Cooler Kit For Use With A Thermoelectric Peltier Module

CommunicaSensors
ZAR165.00

Unassembled Diy Heatsink And Fan Cooler Kit For Use With A Thermoelectric Peltier Module

Sen0098 Arduino Interface Ac/dc Hall Effect Current Sensor 50a

Sen0098 Arduino Interface Ac/dc Hall Effect Current Sensor 50a

CommunicaSensors
ZAR169.00

Sen0098 Arduino Interface Ac/dc Hall Effect Current Sensor 50a

Ir Obstacle Avoidance Sensor Module - 2~4cm Detection Range

Ir Obstacle Avoidance Sensor Module - 2~4cm Detection Range

CommunicaSensors
ZAR13.00

Ir Obstacle Avoidance Sensor Module - 2~4cm Detection Range

Ky-008 Laser Transmitter Module

Ky-008 Laser Transmitter Module

CommunicaSensors
ZAR13.00

Ky-008 Laser Transmitter Module

Am2301 Digital Temperature & Humidity Sensor

Am2301 Digital Temperature & Humidity Sensor

CommunicaSensors
ZAR115.00

Am2301 Digital Temperature & Humidity Sensor

Mini Camera Module For Raspberry Pi - 5mp, 1080p Video, Tiny Board

Mini Camera Module For Raspberry Pi - 5mp, 1080p Video, Tiny Board

CommunicaSensors
ZAR135.00

Mini Camera Module For Raspberry Pi - 5mp, 1080p Video, Tiny Board

Sw-420 Arduino Compatible Digital Vibration Sensor Module Using Lm393 Comparator

Sw-420 Arduino Compatible Digital Vibration Sensor Module Using Lm393 Comparator

CommunicaSensors
ZAR18.00

Sw-420 Arduino Compatible Digital Vibration Sensor Module Using Lm393 Comparator

Electronic Load Cell 1kg

Electronic Load Cell 1kg

CommunicaSensors
ZAR42.00

Electronic Load Cell 1kg

Wiring & Interfacing Examples

The HC-SR04 runs on 5 V logic. Use a logic-level converter or simple resistor divider on the ECHO line when connecting to 3.3 V microcontrollers (ESP32, Raspberry Pi). Do not power the sensor from 3.3 V if the module requires 5 V.

Basic wiring (Arduino, 5 V MCU)

VCC -> 5V
GND -> GND
TRIG -> Digital pin (e.g., D9)
ECHO -> Digital pin (e.g., D10)

Wiring to Raspberry Pi (3.3 V GPIO)

Use a simple resistive divider on ECHO: ECHO -> R1 (1k) -> node -> R2 (2k) -> GND. Node connects to Pi GPIO. TRIG can be driven from Pi 3.3 V output; ensure VCC is 5 V and common GND is present.

5V VCC --- HC-SR04 --- GND
RPi GND ---------------------------
RPi GPIO TRIG -> HC-SR04 TRIG (3.3V drive ok)
HC-SR04 ECHO -> resistor divider -> RPi GPIO ECHO

Sample Arduino pseudocode

digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long duration = pulseIn(ECHO, HIGH, 25000); // timeout 25 ms
if (duration == 0) { /* no echo */ }
float distance_cm = duration * 0.01715;

Mounting, Filtering & Practical Tips

  • Avoid mounting the HC-SR04 behind curved or perforated materials; ultrasonic beams are directional and reflect poorly off soft/angled surfaces.
  • Use multiple sensors with staggered firing to prevent cross-talk. Stagger trigger timing by at least the max expected echo time (e.g., 30 ms for 5 m round-trip) when using several sensors.
  • Apply simple median or moving-average filtering in software to reduce spurious readings from specular reflections.
  • For mobile robots, mount sensors near the centerline, shield from wind and motor turbulence, and test at expected operating speeds to verify update rate suffices for avoidance decisions.

Troubleshooting

  • No echo or constant zero: check wiring, common ground, and that TRIG pulse reaches 10 us. Verify module VCC = 5 V.
  • Unstable readings: add averaging, ensure stationary target during test, and remove nearby ultrasonic sources or fans that cause interference.
  • Short range inconsistency: most HC-SR04 modules struggle closer than 4 cm; use complementary IR or time-of-flight sensors for very short distances.
  • False long readings: check for angled surfaces causing no return; increase sample rate or add side sensors for redundancy.

Local selection & availability notes

Communica stocks ultrasonic modules, related transducers and alternative proximity sensors. In South Africa, expect lead times to vary by brand and pack size; for student projects buy a few spare modules (ZAR estimate: 30-100 each) to allow for mounting mistakes or damaged pins. Check branch stock at the Samrand warehouse or Pretoria/Cape Town branches before planning a lab session.

Application Examples & Calculations

Example: a line-following robot needs to stop when an obstacle is detected closer than 20 cm. Using the distance formula above, compute the trigger frequency and processing loop to ensure reaction time:

  • If you poll sensor every 50 ms, max update rate is 20 Hz. With robot speed 0.3 m/s, stopping distance require reaction time + braking; test in real conditions and include a safety margin.
  • For multiple sensors, schedule triggers to avoid overlap: trigger A, wait 30 ms, read A; trigger B, wait 30 ms, read B, etc.

Sources

Communica Samrand — Electronic Component Experts

Communica supplies semiconductors and electronic components to industries such as automotive, electrical, automation, mining, and education.

Last updated: January 12, 2026

Disclaimer: This content is for educational purposes only. Product availability, pricing, and specifications are subject to change. Always verify current details on the retailer's website before making a purchase. We may earn affiliate commissions from qualifying purchases.

Frequently Asked Questions

Get answers to common questions about Sensors And Semiconductors

Why Choose Communica?

*Free Shipping

Free shipping for orders over ZAR 1,000.00.

7-Day Returns

Get a full refund if you had the product for less than 7 days.

Quick Delivery

Nationwide delivery within 2 - 4 working days.