A Better Ultrasonic Sensor for the Arduino? JSN-SR04T
- Brainy-Bits

- Oct 26, 2020
- 4 min read
Updated: Oct 31, 2020

OVERVIEW
If you have been experimenting with the Arduino platform, I’m sure you have at some point played around with the HC-SR04 Ultrasonic sensor module.

It’s easy to use, pretty inexpensive and easy to find.
But it does have a downside….. the form factor…
All the components, connections and the ultrasonic sensors (2 of them) are on the same PCB.
That can be an issue in some projects.
You see the ultrasonic sensors need to be positioned in a way that makes sense to calculate the distance, and that means that the whole board itself needs to come along with it.
The board also requires 4 connections to the Arduino, GND, Voltage, Trigger and Echo.
So if you don’t want 4 long wires running from the HS-04 to your Arduino, power supply and any other parts in your project need to tag along as well.
Now… What if I told you that there’s another option that might take care of these problems?

Today we will have a look at the JSN-SR04T (version 2) and see if it’s any good and can replace the HC-SR04.
PARTS USED
Arduino NANO
JSN-SR04T Ultrasonic Sensor
These are Amazon affiliate links...
They don't cost you anything and it helps me keep the lights on
if you buy something on Amazon. Thank you!
QUICK OVERVIEW OF THE JSN-SR04T
The JSN-SR04T is kinda new (to me anyway), and it brings some improvements compared to the HC-SR04.
First of course is the actual ultrasonic sensor is not soldered onto the PCB, instead it’s connected with a pretty long external cable (2.5 Meters).
Second instead of having 2 separate sensor (one to send and one the receive) it has only one that includes both. Kinda like the ones you see on car bumpers.
Third the sensor itself is incased in a waterproof enclosure, which might be useful if you want to locate it outside.
So those are the main advantages, but of course like anything else, it does have some downsides.
This sensor being fairly new, doesn’t seem to play well with the popular Arduino libraries used for the HC-SR04.
The quality control, from my research, seems to be hit or miss… Mine does send off some zero readings sometimes?
The minimum distance this sensor can measure, is 20cm… Compared to the 2cm of the HC-SR04.
It’s a bit more expensive than the HS-S04 (around 15$ CND).
Now the library problem, is not a big deal, since it’s pretty easy to write some Arduino code to use this thing.
But I will be testing a bunch of libraries in the next tutorial to see if any play nice with this sensor.
The quality control is a little worrying, but like I talked about in another video (here) you should always get two of anything.
That way if you do receive a bad one out of two, you can send it back without having to wait to start your project.
Finally, yes it is more expensive, but the reason is obvious why… The sensor has a waterproof case and that long connecting wire.
The fact that you can locate the sensor far away from the rest of your project, might be worth it!
CONNECTION DIAGRAM

As you can see, the HS-S04 and the JSN-SR04T connections are the same.
Even the order of the pins are shared: V+, TRIGGER, ECHO, GND
I’m using the Arduino NANO for this tutorial but you can use pretty much any standard Arduino (UNO, MEGA, etc…)
Connections for this tutorial: V+ is connected to the 5V pin of the Arduino GND is connected to the GND pin of the Arduino TRIG is connected to pin 9 of the Arduino ECHO is connected to pin 10 of the Arduino
THE CODE
This will be a simple tutorial on how to create some code to use the sensor and display the results on the Serial Monitor window.
In the next tutorial I will use the sensor in a more involved project, so stay tuned for that one
Keep in mind that this sensor cannot calculate distance below 20cm or above 600cm.
The seller of this sensor included some code, but with mine I had to change a value to make it work correctly.
Those values are the delay()’s between sending and receiving.
Originally it was delay(2) and delay(10), it wasn’t stable with those, when I changed it to delay(2) and delay(15) the results were much better.
As always please check out the tutorial video for more information.
#define ECHOPIN 10
#define TRIGPIN 9
void setup() {
Serial.begin(9600);
pinMode(ECHOPIN,INPUT_PULLUP);
pinMode(TRIGPIN, OUTPUT);
digitalWrite(ECHOPIN, HIGH);
}
void loop() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(15);
digitalWrite(TRIGPIN, LOW);
int distance = pulseIn(ECHOPIN, HIGH, 26000);
distance=distance/58;
Serial.print(distance);
Serial.println(" cm");
delay(50);
}CONCLUSION

So what do I think about this sensor?
I believe that for some projects this sensor is much better suited compared to the HC-SR04.
Not having to locate the whole PCB where you want to position the sensor is great!
The waterproof case can open up a lot of possibilities when it comes to placement.
The quality control is a little worrying, but with time that might get better, as well as the library compatibility.
The price, although more expensive, is okay when you think of the extras you are getting.
In conclusion this sensor will not completely replace the HS-S04 in all projects, but it’s great to have options, and the JSN-SR04T has a place for those projects that need the capabilities that it brings to the table.
Hope you found this interesting and stay tuned for a bigger project using this sensor coming soon.
Cheers!
TUTORIAL VIDEO
DOWNLOAD
Copy and Paste the above code/sketch in your Arduino IDE software.
No libraries needed.




Mình không phải người theo dõi kèo mỗi ngày, nhưng đôi khi mở ra để xem nhịp biến động trong các trận lớn. Khi xem tỷ lệ kèo nhà cái hôm nay, mình nhận ra cách nhà cái điều chỉnh kèo cũng phản ánh thông tin ngoài sân cỏ, như cầu thủ chấn thương hay thay đổi đội hình. Chỉ cần quan sát vài thay đổi nhỏ là biết trận đấu có khả năng biến động thế nào. Mình thấy cách này giúp hình dung thị trường bóng đá một cách trực quan, không chỉ nhìn vào kết quả cuối cùng. Nó giống như đọc “tâm lý trận đấu” qua số liệu, vừa thú vị vừa hữu ích khi muốn…
Mình thường để ý khá kỹ phần bảo mật khi sử dụng các nền tảng dạng này, nhất là những nơi có liên quan đến giao dịch. Khi trải nghiệm tại game bài đổi thưởng uy tín có thể thấy hệ thống có các bước xác thực khi đăng nhập và xử lý nạp rút khá rõ ràng. Ngoài ra, thông tin tài khoản và giao dịch cũng được kiểm soát theo từng bước thay vì xử lý tự do. Những điểm này không quá nổi bật nhưng dễ nhận ra khi dùng một thời gian. Về lâu dài, cách vận hành như vậy giúp hạn chế các vấn đề liên quan đến tài khoản hoặc sai lệch trong giao dịch.
Mình thường thích những trò chơi có phần thưởng hấp dẫn, nhưng không muốn chỉ nghe thông tin chung. Mình tải hitclub để tham gia event Tài Xỉu giải thưởng lớn. Khi chơi vài lượt, thao tác mượt, load nhanh, cảm giác hồi hộp đúng kiểu thử vận may thật. Kiểu trải nghiệm này giúp mình mở app vài phút mỗi ngày, vừa thư giãn vừa có thêm hứng thú. Với mình, việc tải app trực tiếp để tham gia event làm trải nghiệm sống động hơn, không chỉ là chơi game mà còn thử vận may thực tế.
Khi trải nghiệm các nền tảng có nội dung đá gà, mình thường quan tâm đến độ chân thực của hình ảnh và tính minh bạch khi theo dõi trận đấu. Trong quá trình sử dụng tại https://net88.menu/, mình nhận thấy các trận đá gà được livestream trực tiếp từ trường đấu quốc tế như Philippines và Campuchia, tạo cảm giác khá thực tế. Hình ảnh rõ nét, chuyển động mượt và có trọng tài điều hành giúp mình dễ theo dõi diễn biến. Mỗi ngày có khá nhiều trận với nhiều hình thức khác nhau nên không bị nhàm chán. Theo mình, việc phát sóng trực tiếp và tổ chức rõ ràng như vậy giúp trải nghiệm trở nên…
Using technology to increase access to youth mental health support may offer a practical way for young people to reach guidance, safe-spaces, and early help without feeling overwhelmed by traditional systems. Digital platforms, helplines, and apps could give them a chance to seek support privately, connect with trained listeners-orexplore resources that might ease their emotional load. This gentle shift toward tech-based support may encourage youth to open-up at their own pace, especially when in-person help feels too heavy to approach.
There is always a chance that these tools-quietly make support feel closer than before, creating moments where help appears just a tap-Berlinintim away. Even a small digital interaction might bring a sense of comfort. And somewhere in that space, you…