Ultrasonic Sensors Explained
Circuitkar Team · 11 May 2026
Ultrasonic Sensors Explained
The HC-SR04 is one of the most common sensors in electronics projects — cheap, reliable, and accurate enough for most distance measurement needs. Understanding how it works and where it fails saves you debugging time.
How It Works
The HC-SR04 has two transducers: a transmitter and a receiver. When you send a 10 µs HIGH pulse to the Trig pin, the module fires eight 40 kHz ultrasonic pulses. The Echo pin goes HIGH when transmission starts and LOW when the echo returns. Distance = (pulse duration in µs × 0.0343) / 2, where 0.0343 is the speed of sound in cm/µs at 20°C.
Using Arduino/ESP32: pulseIn(ECHO_PIN, HIGH) returns the echo pulse duration in microseconds. Divide by 58 to get distance in cm.
Specs
- Operating voltage: 5V DC
- Current: 15 mA during ping
- Measuring range: 2 cm to 400 cm
- Accuracy: ±3 mm
- Beam angle: ~15°
- Trig and Echo pulse: 5V logic
- Price: ₹40–70
Wiring to ESP32 (3.3V Logic)
The Trig pin accepts a 3.3V pulse — ESP32 GPIO output works directly. The Echo pin outputs 5V — this will damage ESP32 GPIO inputs rated at 3.3V max. Use a voltage divider: 1 kΩ from Echo to GPIO, and 2 kΩ from GPIO to GND. This drops 5V to ~3.3V safely.
Alternatively, use a BSS138 level shifter module for cleaner wiring in permanent installations.
Wiring to Arduino (5V Logic)
Connect directly: Trig to any digital output pin, Echo to any digital input pin. No level shifting needed — both operate at 5V logic.
JSN-SR04T: Waterproof Variant
The JSN-SR04T is the waterproof version — the transducer is sealed in an aluminium housing with a 1.5 m cable. Identical electrical interface to HC-SR04. Range: 20 cm to 450 cm. Price: ₹150–220. Use this for water level monitoring in tanks exposed to moisture, outdoor distance measurement, or any outdoor installation where condensation is a concern.
Limitations
- Soft or sound-absorbing targets: Foam, fabric, and fluffy surfaces absorb ultrasound and return weak echoes. Minimum reliable target surface is ~3 cm × 3 cm of hard material.
- Angle: Targets must be roughly perpendicular to the sensor beam. Objects at more than 45° may not return a readable echo.
- Temperature sensitivity: Speed of sound varies with temperature (0.6 cm/µs per °C). At 35°C Indian summer conditions, uncorrected distance readings are ~2% off. Add a DS18B20 or DHT22 for temperature compensation if accuracy matters.
- Minimum distance: Cannot measure closer than ~2 cm reliably. For short-range precision, use a VL53L0X laser ToF sensor instead.
- Multiple sensors: Running two HC-SR04 sensors simultaneously causes cross-talk — they hear each other's echoes. Use sequential triggering with a 60 ms gap between pings.
Common Applications
Water tank level monitoring, smart dustbin fill detection, robot obstacle avoidance, smart parking slot occupancy detection, blind stick navigation aid, and conveyor object detection.
Find the HC-SR04 and JSN-SR04T at Circuitkar's sensors section.
Related Articles
Home Automation Bill of Materials: Complete Component List with Prices
Full BOM for a 3-room smart home — every component, quantity, price range, and total cost estimate for a DIY home automation installation.
ESP32 for Small Factory Automation: A Practical Starter Guide
How small Indian manufacturers are using ESP32 for basic factory monitoring and control — real use cases, limitations, and what it costs to get started.
Why Cheap Components Fail and What to Buy Instead
The real reasons why no-name ESP32s, clone sensors, and unbranded relay boards fail — and how to identify quality components before buying.