Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » JSN-SR04T Waterproof Ultrasonic Sensor with Arduino Guide
Arduino Projects

JSN-SR04T Waterproof Ultrasonic Sensor with Arduino Guide

Mamtaz AlamBy Mamtaz AlamUpdated:December 14, 20239 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Interfacing Waterproof Ultrasonic Sensor JSN-SR04T AJ-SR04M with Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

This tutorial is about Interfacing of Waterproof Ultrasonic Sensor JSN-SR04T/AJ-SR04M with Arduino & SSD1306 OLED Display to display ultrasonic distance. Earlier we build IoT Water Level Indicator using this sensor.

When working on projects that involve distance measurement or object detection in outdoor environments, the traditional HC-SR04 ultrasonic sensor might not be the best choice due to its fragility and lack of waterproofing. Fortunately, there are alternatives such as the JSN-SR04T and AJ-SR04M waterproof ultrasonic sensors that can withstand harsh conditions, making them ideal for outdoor applications. These sensors, compatible with various Arduino boards, are capable of measuring distances ranging from 25 to 450 cm.

In this article, we will explore the differences between the HC-SR04 and JSN-SR04T/AJ-SR04M sensors. The we will take a look at the Waterproof Ultrasonic Sensor JSN-SR04T/AJ-SR04M pinouts, interfacing with Arduino, programming, and practical testing. We’ll also discuss how to connect and use these sensors with I2C-supported displays like the SSD1306 OLED display module. By the end of this tutorial, you’ll be equipped with the knowledge to integrate the JSN-SR04T/AJ-SR04M waterproof ultrasonic sensor into your projects for versatile distance measurement and object detection capabilities.


Bill of Materials

We need following components for this tutorial. You can purchase all these items from given links.

S.N.ComponentsQuantityPurchase Link
1Arduino Nano1Amazon | AliExpress
2JSN-SR04T Ultrasonic Sensor1Amazon | AliExpress
30.96" I2C OLED Display1Amazon | AliExpress
4Jumper Wires10Amazon | AliExpress
5Breadboard1Amazon | AliExpress




How does the Ultrasonic Distance Sensor Works?

Ultrasonic sensors emit sound waves at a frequency higher than humans can hear – typically in the ultrasonic range, hence the name. These waves travel through the air until they encounter an obstacle and are reflected back to the sensor. This principle of operation is similar to how radar and sonar work, and it’s sometimes referred to as “echolocation” because it’s also how bats navigate.

Ultrasonic Distance Sensor Working

Here’s a basic step-by-step breakdown of how ultrasonic sensors work:

  1. Emission of Ultrasonic Waves: The sensor triggers the ultrasonic transmitter, which emits a burst of ultrasonic sound waves.
  2. Travel and Reflection of Waves: These sound waves travel through the air until they hit an object. When they encounter an object, they bounce back toward the sensor.
  3. Reception of Echo: The reflected sound waves, or “echoes,” are then detected by the ultrasonic receiver.
  4. Time Calculation: The sensor measures the time it took for the sound waves to travel to the object and back. This is often called “Time of Flight.”
  5. Distance Calculation: Using the speed of sound through air, which is approximately 343 meters per second at sea level under normal conditions, the sensor calculates the distance to the object. This is done using the formula: Distance = (Time of Flight x Speed of Sound) / 2. The division by 2 is necessary because the sound wave had to travel to the object and then back again, so the total distance is twice the distance to the object.

Ultrasonic sensors are used in a wide variety of applications, including robotics (for obstacle detection and avoidance), level sensing (for detecting the level of liquids in a tank), and even in some parking assist technologies in cars, among others.




JSN-SR04T/AJ-SR04M Waterproof Ultrasonic Sensor

The JSN-SR04T/AJ-SR04M is a versatile and robust waterproof ultrasonic sensor module that excels in non-contact distance measurement. With a remarkable ranging capacity between 25cm to 450cm and an accuracy of up to 2mm, this sensor proves to be highly precise and reliable for a multitude of applications.

JSN-SR04T AJ-SR04M Waterproof Ultrasonic Sensor

Distinctively, the JSN-SR04T/AJ-SR04M sensor module consists of two separate components: the transducer, which acts as the sensing element, and the control board, which processes the signals received. This dual-component design is reminiscent of the ultrasonic sensors found in car bumpers, hinting at the sensor’s robustness and reliability in real-world applications.

Boasting an industrial-grade integrated ultrasonic sensing probe, the sensor is designed to withstand harsh conditions while delivering stable performance and high precision. Its waterproof feature adds another layer of durability, making it suitable for outdoor applications or scenarios involving water.

Beyond just distance measurement, the JSN-SR04T/AJ-SR04M sensor can be leveraged for a broad spectrum of applications. This includes horizontal ranging, obstacle avoidance, automated control, and object monitoring.


JSN-SR04T/AJ-SR04M Features & Specifications

The JSN-SR04T/AJ-SR04M is a robust waterproof ultrasonic sensor module with numerous features and specifications that make it suitable for a wide range of applications. Here are the key features and specifications:

Features:

  1. Waterproof: The sensor is designed to operate effectively in wet or humid conditions.
  2. Industrial-grade Design: It has an industrial-grade integrated ultrasonic sensing probe design, enhancing durability and performance.
  3. Separate Probe and Module: The module consists of two parts, the control board, and the sensing probe, allowing for flexible installation.
  4. High Precision: The sensor is capable of highly precise distance measurements.

Specifications:

  1. Operating Voltage: It typically operates at a voltage of 5V DC.
  2. Operating Frequency: The ultrasonic sensor operates at a frequency of 40kHz.
  3. Range: It can measure distances from 25cm to 450cm.
  4. Ranging Accuracy: It can measure with an accuracy of up to 2mm.
  5. Interface: The sensor has a 4-pin interface (VCC, GND, Trig, Echo).
  6. Operating Temperature: The sensor can operate in a wide range of temperatures, typically from -20°C to +70°C.
  7. Detection Angle: The sensor typically has a detection angle of up to 70 degrees.



JSN-SR04T/AJ-SR04M Pinout

The JSN-SR04T ultrasonic sensor module features four pins:

JSN-SR04T/AJ-SR04M Pinout

  1. VCC: Powers the sensor, typically with a 5V DC supply.
  2. Trig (Rx): Initiates the ultrasonic pulses when a high pulse is sent.
  3. Echo (Tx): Outputs a pulse proportional to the distance to the object.
  4. GND (Ground): Connects to the system ground to complete the circuit.

JSN-SR04T/AJ-SR04M VS HC-SR04

The JSN-SR04T/AJ-SR04M and HC-SR04 are both ultrasonic distance sensors used widely in robotics and other distance sensing applications. They share similar operating principles but have different features that make them suitable for different scenarios. Here is a comparison of the two:

JSN-SR04T/AJ-SR04M VS HC-SR04

Feature/Specification JSN-SR04T/AJ-SR04M HC-SR04
Waterproof Yes No
Range 25cm – 450cm 2cm – 400cm
Operating Voltage 5V DC 5V DC
Operating Temperature -20°C to +70°C 0°C to +70°C
Sensing Elements Separate from the module Integrated on the board
Durability Higher (Industrial-grade) Lower
Suitable Environment Outdoor/Wet environments Indoor/Dry environments
Detection Angle Up to 70 degrees About 15 degrees
Accuracy Up to 2mm Varies (slightly less)
Flexibility More (due to separate probe and module) Less (due to integrated design)

While both sensors operate on similar principles and have comparable ranges and operating voltages, they differ significantly in terms of waterproofing, durability, flexibility, and suitable environments. The JSN-SR04T/AJ-SR04M, with its waterproof feature and separate sensing elements, offers more flexibility in installation and is suitable for outdoor or wet environments. The HC-SR04, however, is more suitable for indoor or dry environments due to its lack of waterproofing.


Interfacing JSN-SR04T Ultrasonic Sensor with Arduino

Here’s a simple guide for interfacing the waterproof ultrasonic sensor JSN-SR04T or AJ-SR04M with an Arduino and displaying the output on an OLED display. For this example, we will use an Arduino Nano Board and a 0.96″ I2C OLED Display.

Interfacing Waterproof Ultrasonic Sensor JSN-SR04T AJ-SR04M with Arduino

The connection is very simple as shown in this table below.

Component Pin Name Arduino NANO Pin
Ultrasonic Sensor VCC 5V
Ultrasonic Sensor GND GND
Ultrasonic Sensor Trig Digital 12
Ultrasonic Sensor Echo Digital 11
OLED Display VCC 3.3V
OLED Display GND GND
OLED Display SDA Analog 4 (A4)
OLED Display SCL Analog 5 (A5)

Ultrasonic Waterproof Sensor Arduino

You may use a breadboard for connection or for portable application solder all the components on a zero PCB.




Source Code/Program

In the programming part, we will interface the Waterproof Ultrasonic Sensor JSN-SR04T/AJ-SR04M with Arduino & OLED Display in the same way as we interface the HC-SR04 Sensor.

First, make sure you have the necessary libraries installed. You can download the Adafruit_SSD1306 library (for OLED) and Adafruit_GFX library (for graphics functions) from the Arduino Library Manager.

Here is a simple example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define trigPin 12
#define echoPin 11
 
long duration;
int distance;
 
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
  Serial.begin(9600);
}
 
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  duration = pulseIn(echoPin, HIGH);
 
  distance = duration*0.034/2;
 
  Serial.print("Distance = ");
  Serial.print(distance);
  Serial.println(" cm");
  display.clearDisplay();
 
  display.setTextSize(3);
  display.setCursor(10, 20);
  display.print(distance);
 
  display.setTextSize(3);
  display.setCursor(70, 20);
  display.print("CM");
 
  display.display();
}

This code is designed to interface an Arduino with an ultrasonic sensor (like the JSN-SR04T or AJ-SR04M) and an OLED display.

The ultrasonic sensor measures distance by sending out a sound wave at a specific frequency and then measuring how long it takes for the echo of the sound wave to return. The speed of sound is approximately 0.034 cm/µs, and we divide by 2 because the sound wave has to travel to the object and back. The OLED display then shows the measured distance.



Testing & Demonstrations

After completing the wiring and uploading the code to the Arduino, you should now be ready to test the functionality of the waterproof ultrasonic sensor (JSN-SR04T or AJ-SR04M) with the OLED display.

Connect the Arduino to your computer using a USB cable. The Arduino should power up, and if correctly wired, the OLED display should also power up.

The minimum distance the sensor can detect is 25cm. Hence if an obstacle is found at a distance lessor than 25cm, it will display 0 cm. When a distance is slightly increased, it starts showing the minimum distance.

The OLED display should also show the distance in centimeters. The display should refresh every second (or as defined in your code), and the distance should change as you move objects.

The sensor can show shows the distance upto 450cm which is the maximum distance. We tested and measured the accuracy at 193cm, the exact distance was shown in the OLED.

We measured the distance upto 250cm as this was the wall distance in our testing room.

For a more comprehensive demonstration, you can create a real-world application, such as measuring water levels, detecting object presence or distance, or even building a simple parking sensor.

To test the waterproof capability of the JSN-SR04T/AJ-SR04M, immerse the sensor (not the entire module) in water. Make sure only the waterproof part of the sensor is submerged, and the electronics remain dry.

Once you have successfully tested and demonstrated the setup, you can implement the ultrasonic sensor and OLED display in various projects, such as robotics, object detection, distance measurement, or obstacle avoidance systems.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleControl Stepper Motor with A4988 Driver & Raspberry Pi Pico
Next Article 10 Essential IoT Starter Kits to Kickstart Your Journey

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
Add A Comment

CommentsCancel reply

Latest Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 14, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • How to use LDR Sensor Module with Arduino
    How to use LDR Sensor Module with Arduino
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • Silicon Controlled Rectifier (SCR): Construction, Working & Applications
    Silicon Controlled Rectifier (SCR): Construction, Working & Applications
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.