Ultrasonic distance sensors are among the most popular components in any maker’s toolkit. Whether you are building an obstacle-avoidance robot, a smart parking system, a water level monitor, or a staircase safety alarm, chances are you have considered the HC-SR04 or its waterproof cousin, the JSN-SR04T. Both sensors use the same 40 kHz ultrasonic pulse principle, yet they serve very different environments and project requirements.
In this detailed comparison guide, we break down every specification, explain real-world strengths and limitations, provide wiring diagrams and Arduino code, and ultimately help you decide which ultrasonic sensor to buy in India for your specific application.
1. How Ultrasonic Sensors Work
Both sensors operate on the same fundamental principle: the module emits a burst of 40 kHz sound waves from a transmitter transducer and then listens for the echo on a receiver transducer. The microcontroller measures the time elapsed between the transmitted pulse and the returning echo. Since sound travels at approximately 343 m/s at room temperature (20 degrees C) the calculation is:
Distance (cm) = (Echo pulse duration in µs) x 0.034 / 2
The division by 2 accounts for the round trip: sound travels to the object and back. A TRIG pin receives a 10 µs HIGH pulse from the Arduino to initiate measurement; the ECHO pin goes HIGH for a duration proportional to the measured distance.
One important factor: the speed of sound changes with temperature (roughly +0.6 m/s per degree C). For precision applications, adding a temperature sensor like the DS18B20 and applying a correction factor dramatically improves accuracy.
2. HC-SR04: The Maker’s Workhorse
The HC-SR04 is arguably the most ubiquitous sensor in hobbyist and educational electronics. Introduced over a decade ago, it remains the default choice for Arduino distance projects because of its extremely low price, straightforward 4-pin interface, and extensive community support.
Key Characteristics
- Operating Voltage: 5 V DC (not 3.3 V tolerant without a voltage divider on the ECHO pin)
- Measuring Range: 2 cm to 400 cm (practically reliable up to about 250 cm)
- Accuracy: +/-3 mm under ideal conditions
- Frequency: 40 kHz
- Beam Angle: approximately 15 degrees effective cone
- Quiescent Current: 2 mA; measuring current: 15 mA
- Trigger Input: 10 µs HIGH pulse on TRIG pin
- Form Factor: PCB with two exposed transducer cylinders
- IP Rating: None — not splash-proof
Strengths
The HC-SR04 wins on price and availability. You can find it at virtually every Indian electronics shop, both online and offline. Its PCB module format means no soldering; you plug in four Dupont wires and you are done. The 15 degree beam angle is narrow enough to point at specific objects without excessive reflections from surroundings.
Limitations
The sensor has no protection against moisture, dust, or debris. Objects that are very close (under 2 cm), very soft, or at steep angles may not reflect enough sound back to register. False readings appear frequently when used outdoors in wind or rain. The 5 V requirement means you need a voltage divider or a logic-level shifter when working with 3.3 V boards like the ESP32, Raspberry Pi Pico, or Arduino Due.
A86 JSN-SR04T Waterproof Ultrasonic Rangefinder Module v3.0
IP67-rated waterproof ultrasonic module — ideal for outdoor water tanks, underground sensor pits, and humid industrial environments.
3. JSN-SR04T: Waterproof & Industrial
The JSN-SR04T (and its v3.0 iteration) was designed specifically to overcome the HC-SR04’s biggest shortcoming: fragility in real environments. Instead of two exposed transducer cylinders on a PCB, the JSN-SR04T separates the transducer into a single, sealed probe connected to a control board by a cable. This physical separation is everything — the probe can sit submerged or mounted in a pipe while the electronics stay dry.
Key Characteristics
- Operating Voltage: 3.3 V to 5.5 V (the v3.0 board is 3.3 V safe)
- Measuring Range: 25 cm to 450 cm
- Accuracy: +/-1 cm
- Frequency: 40 kHz
- Beam Angle: approximately 60 degrees (wider beam due to single transducer design)
- IP Rating: IP67 (probe only; control board not waterproof)
- Probe Cable Length: approximately 2.5 m (varies by supplier)
- Interface: Same TRIG/ECHO/VCC/GND as HC-SR04
Strengths
The IP67-rated probe makes the JSN-SR04T the go-to choice for water level sensing in tanks, outdoor installations, basement flood detection, and industrial proximity applications. The wider 60 degree beam is actually useful in liquid level measurement because it reduces the chance of a dead zone if the probe is slightly misaligned. The longer minimum range (25 cm) is acceptable for tank or bin level use-cases where you mount the sensor at the top and measure downward.
Limitations
The 25 cm minimum range is a significant limitation for short-range robotics. The wider beam also means more false readings from container walls if the probe is placed near the side. The control board itself is not waterproof, so it must remain in a dry enclosure. Cost is higher than the HC-SR04, and cable management needs planning.
4. Head-to-Head Spec Comparison
| Feature | HC-SR04 | JSN-SR04T v3.0 |
|---|---|---|
| Supply Voltage | 5 V | 3.3 to 5.5 V |
| Min Range | 2 cm | 25 cm |
| Max Range | 400 cm | 450 cm |
| Accuracy | +/-3 mm | +/-1 cm |
| Beam Angle | 15 deg | 60 deg |
| IP Rating | None | IP67 (probe) |
| Form Factor | PCB module | Probe + control board |
| Typical Price (India) | Rs 40-80 | Rs 200-350 |
| Best For | Indoor robotics, prototyping | Outdoor, tanks, wet areas |
5. Wiring Both Sensors to Arduino
HC-SR04 Wiring (Arduino Uno)
HC-SR04 --> Arduino Uno
VCC --> 5V
GND --> GND
TRIG --> Digital Pin 9
ECHO --> Digital Pin 10
Important: If you are using an ESP32, ESP8266, or any 3.3 V board, put a voltage divider on the ECHO line (10 kOhm from ECHO to pin, 20 kOhm from pin to GND) to avoid damaging the GPIO. The TRIG pin is input-only and tolerates 3.3 V logic fine.
JSN-SR04T Wiring (Arduino Uno)
JSN-SR04T --> Arduino Uno
VCC --> 5V (or 3.3V for v3.0)
GND --> GND
TRIG --> Digital Pin 9
ECHO --> Digital Pin 10
The control board connector pinout is clearly labeled. Connect the sealed probe to the onboard JST/screw connector. Keep the cable away from high-frequency interference sources like servo motors and switching power supplies.
6. Arduino Code Examples
Basic HC-SR04 Distance Measurement
const int trigPin = 9;
const int echoPin = 10;
long duration;
float distanceCm;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) {
Serial.println("Out of range");
} else {
distanceCm = duration * 0.034 / 2.0;
Serial.print("Distance: ");
Serial.print(distanceCm);
Serial.println(" cm");
}
delay(200);
}
JSN-SR04T with Averaged Readings
const int trigPin = 9;
const int echoPin = 10;
float getDistance() {
float total = 0;
int valid = 0;
for (int i = 0; i < 5; i++) {
digitalWrite(trigPin, LOW); delayMicroseconds(2);
digitalWrite(trigPin, HIGH); delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long dur = pulseIn(echoPin, HIGH, 50000);
if (dur > 0) {
total += dur * 0.034 / 2.0;
valid++;
}
delay(50);
}
return (valid > 0) ? (total / valid) : -1;
}
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
float d = getDistance();
if (d < 0) Serial.println("No reading");
else { Serial.print(d); Serial.println(" cm"); }
delay(500);
}
7. Best Use Cases for Each Sensor
Choose HC-SR04 When:
- Building indoor robots, obstacle-avoidance cars, or line-following bots
- Prototyping any distance-sensing project on a breadboard
- Creating parking distance indicators inside a garage
- Making staircase LED lighting triggers
- Experimenting in school or college labs where cost matters most
- Short-range detection under 25 cm is required
Choose JSN-SR04T When:
- Monitoring water or liquid levels in underground sumps, overhead tanks, or aquaculture tanks
- Deploying sensors in outdoor enclosures exposed to rain, condensation, or dust
- Industrial bin-level sensing in factories or warehouses
- Agricultural automation: irrigation tank monitoring
- Septic tank or borewell water level monitoring
- Any permanent installation where long-term reliability matters more than cost
8. Accuracy Tips & Common Mistakes
Temperature Compensation
For the most accurate results, combine your ultrasonic sensor with a temperature sensor. Use the formula: Speed of sound (m/s) = 331.4 + (0.606 x Temperature in degrees C). On a hot Indian summer day at 42 degrees C, sound travels at 356.8 m/s instead of 343 m/s — a 4% error if uncorrected.
Common Mistakes to Avoid
- No timeout on pulseIn: Without a timeout argument, pulseIn blocks forever if there is no echo. Always use pulseIn(echoPin, HIGH, 30000).
- Measuring too fast: Allow at least 60 ms between readings for the echo to decay. Faster loops cause ghost readings.
- Angled surfaces: If the target surface is at more than 45 degrees to the sensor beam, the sound reflects away and you get no reading.
- ECHO voltage on 3.3 V boards: The HC-SR04 drives ECHO high at 5 V. Connect directly to an ESP32 and you risk permanently damaging the GPIO.
- Foam or fabric targets: Soft materials absorb ultrasound. You may get shorter apparent range or no reading at all.
9. Price & Availability in India
The HC-SR04 is available almost everywhere for Rs 40-80 per piece. Buy in bulk (10 pieces) and you can get them below Rs 40 each. The JSN-SR04T v3.0 costs Rs 200-350 for the probe plus board combo. Both are stocked at Zbotic with fast shipping across India. Zbotic also stocks specialty ultrasonic transducers like the 25 kHz T25 transmitter and receiver pair for custom ultrasonic systems operating at lower frequencies.
25kHz Ultrasonic Sensor Transmitter T25 16mm
Discrete 25 kHz transmitter transducer for custom ultrasonic circuits, flow meters, and specialized industrial projects.
10. Final Verdict: Which Should You Buy?
The answer is almost always both — and here is why:
Get the HC-SR04 for every breadboard prototype, robotics project, indoor alarm, and classroom experiment. At under Rs 80, it is practically disposable and the learning curve is zero. Keep a handful in your component box.
Get the JSN-SR04T the moment your project leaves the desk and goes into the real world. Rain, humidity, dust, and condensation will destroy an HC-SR04 within weeks. The JSN-SR04T’s IP67 probe survives years of outdoor service. For water tank level monitoring, septic systems, and any permanent outdoor installation in India’s monsoon-heavy climate, there is no alternative.
The code interface is identical for both sensors, so you can prototype with the HC-SR04 and swap to the JSN-SR04T for deployment without changing a single line of code.
Frequently Asked Questions
Can I use HC-SR04 with ESP32?
Yes, but you must use a voltage divider on the ECHO pin. The ESP32 GPIO is 3.3 V tolerant and the HC-SR04 drives ECHO at 5 V. Use a 10 kOhm / 20 kOhm resistor divider or a dedicated level shifter. Alternatively, use a 3.3 V-compatible ultrasonic module like the HC-SR04P.
What is the maximum range of HC-SR04 in real conditions?
The datasheet says 400 cm, but reliable readings in typical indoor environments top out around 200-250 cm. At longer distances, beam spreading and multipath reflections introduce errors. For ranges beyond 2 m, averaging 5-10 readings significantly helps stability.
Is the JSN-SR04T fully submersible?
The probe itself carries an IP67 rating, meaning it can be submerged in up to 1 metre of water for 30 minutes. This covers most liquid-level sensing applications. The control PCB is not waterproof and must remain in a sealed enclosure.
Why does my HC-SR04 give random readings?
Common causes: (1) power supply noise — add a 100 µF electrolytic capacitor across VCC/GND near the module; (2) too-fast reading loop — add 60 ms delay between measurements; (3) nearby surfaces causing echoes — check beam angle; (4) 5 V power from an Arduino pin — better to power from the board’s 5 V rail directly.
Can both sensors measure liquid levels in a sealed tank?
Yes. The JSN-SR04T is specifically designed for this. Mount the probe at the top of the tank pointing downward and measure the air gap above the liquid. For a 1 m tall tank: water level (cm) = tank height (cm) minus measured distance (cm). The HC-SR04 can work in open-top tanks but will fail if splashed.
Do I need any library to use these sensors?
No library is strictly necessary — the code above uses only standard Arduino functions. However, if you prefer a library, NewPing by Tim Eckel is excellent for both sensors. Install it via the Arduino Library Manager and enjoy built-in timeouts, averaging, and ping_cm() convenience methods.
Add comment