top of page

Safari browser sometimes has issues displaying images...

I.e: *you have to click on the images to see them...

​

For a better browsing experience on Brainy-Bits

Please use Chrome, Edge or Firefox browser.

A Better Ultrasonic Sensor for the Arduino? JSN-SR04T

Writer: Brainy-Bits
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.

 
 
 

48 Comments


mikaela mirae
mikaela mirae
5 days ago

Quality assurance and quality control are related but serve different purposes within a quality management system. When exploring quality assurance meaning, it is useful to understand that quality assurance focuses on the processes used to prevent problems, while quality control involves checking outputs to identify defects. Both activities contribute to maintaining consistent standards. Using them together can help organisations improve processes and address issues more effectively.

Like

CandyMay Zalfe
CandyMay Zalfe
Nov 03

The Tip-Top Roofing using the time-of-flight principle. First, it sends an ultrasonic sound wave toward an object. When the sound wave hits a surface, part of it reflects toward the sensor.

Like

aurora fisher
aurora fisher
Oct 16

Selecting reliable sensor modules for outdoor embedded hardware projects requires accounting for physical durability, voltage limits, and environmental exposure. In electronics engineering and system integration, understanding project constraints through the College of Contract Management highlights how engineers and technical leads evaluate hardware parameters, cost boundaries, and power limits to ensure long-term operational success. A very detailed and practical guide to integrating waterproof ultrasonic sensors with Arduino!

Like

Efra Store
Sep 17

The practical side of ultrasonic sensing is often less about getting a reading and more about making that reading reliable in the environment where the device will actually operate. Things like mounting angle, surface shape, cable length, and the way noisy readings are filtered can make a noticeable difference, especially when the sensor is being used for distance-based automation rather than a simple demonstration. Another useful consideration is how the software handles invalid or fluctuating measurements, since a single bad value can trigger an unwanted action if there is no basic validation in place. This kind of thinking also applies outside electronics, where technical subjects often benefit from combining theory with realistic examples and hands-on application. For anyone developing learning…

Like

melisa jordan
melisa jordan
Sep 16

Really enjoyed reading this! Thanks for sharing such valuable insights, I’ve always loved chuck taylors  they’re the most reliable footwear converse has ever made. My first pair was white low top converse shoes, and since then, I’ve collected everything from the chuck taylor sneaker to the american converse shoes line. I even own some converse trainers from Europe along with a pair of converse original.


Like

All my content is and will always be Free.

​

If you feel that my Videos / Tutorials are helping, and you would like to contribute...

 You can toss some coins in the Tip Jar via PayPal.

​

Select amount then click the “Donate” button.

©2020 by Brainy-Bits

bottom of page