Arduino Projects

Waterproof Ultrasonic Sensor JSN SR-40T with Arduino for distance measurement

Waterproof Ultrasonic Sensor JSN SR-40T:

Waterproof Ultrasonic Sensor JSN SR-40T with Arduino for distance measurement- I am sure you are already familiar with the most popular HC-SR04 ultrasonic sensor which I have been using in different types of projects. As a beginner, you can start with any of these projects which are given below.

Obstacle detection with HC-SR04 Ultrasonic Sensor

Safe Distance maintaining Robot Car

Bi-directional visitors counter

Hand Washing Timer Project using Arduino and Ultrasonic Sensor

Ultrasonic Sensor with Raspberry Pi

Social distancing project

IoT based Flood Monitoring System using Ultrasonic Sensor and ESP8266

Smart Dustbin using Arduino and Ultrasonic Sensor

Water Level monitoring System

IoT based Water level Monitoring System

You can also ready my article on IoT based Water level monitoring and automatic water pump control system using the ESP32 WiFi + Bluetooth Module, Waterproof Ultrasonic Sensor, and the New Blynk V2.0 more…

All the above projects are based on the HC-SR04 Ultrasonic Sensor. This is not the only type of the sensor which you can use for the distance measurement, level monitoring, or obstacle detection. We also have another type of the distance sensor which uses laser TOF10120 Laser Rangefinder distance sensor. I have also used it with the Arduino and ESP8266.

Distance measurement with ToF10120 Laser RangeFinder and Arduino

IoT Water Level Monitoring using ToF10120 and ESP8266

Car parking system using Arduino and ToF10120 Laser distance sensor

IoT water level monitoring using ESP32 and ToF10120 Sensor

The good thing about the ToF10120 Laser distance sensor is that, it can be waterproofed.  But, anyways, I have already covered these distance measurement sensors. Today, we will be looking at the actual waterproof Ultrasonic Sensor JSN SR-40T module. As usual, before, I am going to use the Waterproof JSN SR-40T Ultrasonic Sensor in some intermediate and advanced level projects, first I am going to cover the extreme basics including the Waterproof Ultrasonic Sensor JSN SR-40T technical specification, its interfacing with the Arduino, and programming. You can use the JSN SR-40T waterproof ultrasonic sensor indoor or outdoor or in a fish tank or anything else. The working range of this waterproof ultrasonic sensor is between 20 centimeter and 600 centimeter. For distance less than 20 centimeter you may get errors and the values are going to fluctuate a lot, so for such low distance you can use the HC-SR04 Ultrasonic sensor or the ToF10120 Laser distance sensor or you can use any other sensor.

Waterproof Ultrasonic Sensor

Waterproof Ultrasonic sensor, the JSN-040T is an easy to use waterproof ultrasonic distance sensor with a range of 25 to 450 centimeters. If you are planning to build a water level monitor system or if you need to take other distance measurements outdoors then this is the sensor for you. When shopping for this sensor you might come across the updated version the JSN-040T – 2.0.This new version works exactly the same but is rated for 3 to 5 volts instead of 5 volts. However some users have found issues while using the sensors at a lower voltage 3 volts using a longer trigger pulse of at least 20 microseconds instead of 10 microseconds seems to help you or having 40 readings that is if you have 40 readings noted then increase the trigger pulse to at least 20 microseconds to get the accurate results from this new sensor.

The sensor comes with a 2.5 meter long cable that connects to a circuit board which controls the sensor and does all the processing of the signal. Note that only the sensor and the cable are waterproof, if you get water onto the circuit board the sensor might stop working.

Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Waterproof Ultrasonic Sensor JSN-040T

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

JSN SR-40T Specifications:

  • With a waterproof sealed emitter. This sensor is suitable for outdoor applications such as car reversing sensors, security alarms, industrial inspection, etc.
  • Integrated with wire enclosed waterproof probe, suitable for wet, harsh measurement occasions. Please note that the device is waterproof, but it couldn’t work underwater.
  • Working voltage: DC 5V,
  • Static current: 5mA,
  • Total current work: 30mA.
  • Working range: 25cm-4M,
  • Working frequency: 40KHZ
  • Detecting angle: 70 degree.
  • Working temperature: -10 to 70 Celsius
  • Storage temperature: -20 to 80 celsius
  • The module has a variety of modes that can be modified manually, suitable for testing and teaching experiments in different occasions.
  • Small size easy to use
  • Low voltage, low power consumption
  • High accuracy
  • Integrated with wire enclosed waterproof probe, suitable for wet, harsh measurement occasions

Working of JSN-SR0T

(1) Using IO port TRIG trigger range, to a minimum of 10us high letter.

(2) Module automatically send 8-40khz square wave, automatically detect whether there is a signal to return;

(3)A signal to return, through the IO port ECHO output a high level, high time is the duration of ultrasound from the launch to the return time. Test distance = (high time * speed of sound (340M / s)) / 2;

(4) Module is triggered after the distance measurement, if you cannot receive the echo (the reason exceeds the measured range or the probe is not on the measured object), ECHO port will automatically become low after 60MS, marking the End of measurement, whether successful or not.

(5) LED indicator, LED non-power indicator, it will receive the signal after the module will be lit, and then the module is working.

Waterproof Ultrasonic Sensor JSN SR-40T Interfacing with Arduino:

Waterproof Ultrasonic Sensor

The circuit board of the JSN-SR0T waterproof ultrasonic sensor module has the same pin as that of HC-SR04, so it can be used as a one to one replacement. The cable of the sensor is plugged into the connector on the back of the sensor (JSN-SR04T) circuit board. So let’s wire our module with Arduino, the module consists of 4 pins which are:

  • VCC
  • Trigger
  • Ground
  • Echo

You can power this sensor from 3 to 5 volts, but I am going to use the 5 volts. Connect the 5V of the Arduino with the VCC of the JSN SR-40T Sensor.

  • Connect the ground of the sensor with the ground of the Arduino.
  • Connect the trigger pin with digital pin 12 of the Arduino.
  • Connect the echo pin of the sensor with the digital pin 11 of the Arduino.

JSN SR-40T Arduino Code:

As we know that every sensor having noise in the sensor data is common and normal especially on low end sensor. In order to filter the noise we will use the filter to remove the noise.

Download the MedianFilter library for Arduino:

After downloading the MedianFilter library, next you will need to add it in the Arduino IDE, I hope you know how to add a library if not then follow these steps.

Click on the Sketch Menu > Include Library > Add .zip Library

Browse to the folder, normally it’s in the downloads folder select the MedianFilter zip folder and that’s it.

Or you can download the same library by going to the Sketch Menu > Include Library > Manage Libraries.

Waterproof Ultrasonic Sensor

Simply type the Median filter as you can see in the image above. Find the MedianFilterLib in the list and click on the install button. Next, you can copy and paste the following code.

#include <NewPing.h>
#include <MedianFilter.h>
#include <Wire.h>
#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 450 // Maximum distance we want to ping for (in centimeters).
//Maximum sensor distance is rated at 400-500cm.
NewPingsonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
void loop() {
delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsignedinto,uS =; // Send ping, get ping time in microseconds (uS).;
  o = filter.out();
Serial.print("Ping: ");
Serial.print( o / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)

After uploading the code to the Arduino board, then you can click on the Serial Monitor and you will be able to see the distance in centimeters if you have done everything correctly. Now you can move your hand or any other object in front of the Ultrasonic Sensor and you should be able to see different values.

Difference between HC-SR04 and JSN -SR04:

The main difference besides it being waterproof is that this sensor uses only one ultrasonic transducer instead of two this transducer serves as both the transmitter and the receiver of the ultrasonic sound waves.

Ultrasonic sensor working:

Ultrasonic sensors work by emitting sound waves with a frequency that is too high for a human to hear. These sound waves travel through the air with a speed of sound roughly 343 meters per second. If there is an object in front of the sensor the sound waves get reflected back and the receiver of the ultrasonic sensor detects them by measuring how much time elapsed between sending and receiving the sound waves the distance between the sensor and object can be calculated. This is the basic concept of ultrasonic sensors bats, whales use them while measuring the distance during their traveling. At 20 degree centigrade the speed of sound is roughly 343 meters per second or 0.034 centimeters per micro second. If you multiply the speed of sound by the time the sound waves traveled you get the distance that the sound waves traveled.

Distance = speed × time

But that is not the result we are looking for the distance between the sensor and object is actually only half this distance because the sound waves traveled from the sensor to the object and back from the object to the sensor.

Waterproof Ultrasonic Sensor

You can see in the diagram the transmitter is emitting the sound wave which reaches the object and the reflected sound waves will come back to the receiver.

So this is the distance and the actual distance for measurement is half of this distance. So you need to divide the result by:

Distance= (speed (cm⁄μs)×time (μs))/2


  • Artificial intelligence and research
  • Horizontal distance
  • The object approaches there is a perceived
  • Traffic controls
  • Security, industrial control

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button