Description
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.
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.
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:
- Waterproof:Â The sensor is designed to operate effectively in wet or humid conditions.
- Industrial-grade Design:Â It has an industrial-grade integrated ultrasonic sensing probe design, enhancing durability and performance.
- Separate Probe and Module:Â The module consists of two parts, the control board, and the sensing probe, allowing for flexible installation.
- High Precision:Â The sensor is capable of highly precise distance measurements.
Specifications:
- Operating Voltage:Â It typically operates at a voltage of 5V DC.
- Operating Frequency:Â The ultrasonic sensor operates at a frequency of 40kHz.
- Range:Â It can measure distances from 25cm to 450cm.
- Ranging Accuracy:Â It can measure with an accuracy of up to 2mm.
- Interface:Â The sensor has a 4-pin interface (VCC, GND, Trig, Echo).
- Operating Temperature: The sensor can operate in a wide range of temperatures, typically from -20°C to +70°C.
- 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:
- VCC:Â Powers the sensor, typically with a 5V DC supply.
- Trig (Rx):Â Initiates the ultrasonic pulses when a high pulse is sent.
- Echo (Tx):Â Outputs a pulse proportional to the distance to the object.
- GND (Ground):Â Connects to the system ground to complete the circuit.
nterfacing 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.
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) |
 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:
#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.