9008620582 info@probots.co.in

After ultrasonic sensors started being used in cars as reverse parking sensors, they started being manufactured in bulk and they are now easily available in a wide variety of models at nominal prices. We at Probots (www.probots.co.in), sell a wide range of ultrasonic sensors which are easy and simple to interface with microcontrollers.

Waterproof Ultrasonic Distance Sensor Module JSN-SR04T

The most versatile and accurate of them is the Waterproof Ultrasonic Sensor AJ-SR04M/JSN-SR04T V2.0. It can detect objects up to 4.5meters, has a very practically useful beam angle of 45 degrees, is accurate up to 0.5cm. Unlike other ultrasonic sensors HC-SR04, JSN-SR04T, and the JSN-SR04T V2, the AJ-SR04M offers a wide range of operating voltage 3-5V(which means it can work on both 5V and 3.3V microcontrollers), has a low power consumption of only 20uA during sleep(which means it can run on batteries for years!). The other sensors HCSR05 and JSN-SR04T have high operating voltage and current consumption( which makes the AJ-SR04M is the best choice for designing consumer products)It has multiple operating modes – traditional Trigger and Echoes through digital IO Pins, Serial UART, PWM(I have not tested PWM, so can’t confirm)There are many articles and youtube videos showing that JSN-SR04T V2 and AJ-SR04M are not working and hence recommend to use SN-SR04T. But they didn’t put in a good effort to get them working and concluded that an older sensor JSN-SR04T with fewer features is better.

We recently delivered a custom electronics product using the AJ-SR04M and were able to get it working with no issues. The product has already reached the market and has been received with high satisfaction from both our customers and their users. 

If you are trying to use this ultrasonic sensor in your product or project, then this article will help you get it working immediately. I used the sensor we have in stock with us. We sell the same sensor on our website, Buy it here – WWW.probots.co.in

Modes Format Description:

Modes Selection Resistor(R19)
ModesResistance ValueStandby CurrentLow Power CurrentBlind Area
Traditional Mode compatible with AJ-SR04MOpen circuit<2mA-------20cm
Low Power Mode300KΩ<2mA<40μA20cm
Automatic Serial Port Mode120KΩ<2mA---------20cm
Low Power Serial Mode47KΩ<2mA<20μA20cm
Computer Printing Mode0KΩ<2mA<20μA20cm

Specification:

The Module is capable of providing information of the objects between the distance range 20cm to 450cm.

  • Operating Voltage: DC 5V
  • Quiescent Current: 5mA
  • Total Current Draw:30mA
  • Frequency: 40KHZ
  • Range:20cm to 450cm
  • Resolution : about 0.5cm
  • Beam Angle: less than 50 degrees
  • Working Temperature:-10~70° C
  • Storage temperature:-20~80° C

Board Overview :

Sr.noModule PinsDescription
15VPower Input
2Trigger(RX)Trigger Signal
3Echo(TX)Echo Signal
4GndPower Ground
52 Pin ConnectorUltrasonic Probe Connector

The AJ-SR04M has 5 working modes:

  • Traditional Mode compatible with HCSR04:

This mode uses Trigger and Echo pins. You will have to allocate two digital pins on your microcontroller, and a software timer to calculate the distance.

Note that the communication sequence is the same as per HC SR04, but make sure your high signal on the Trigger pin is at least 10 ms wide. Some users have reported getting good reading only after increasing the trigger width to 20m.

This mode works with the popular Arduino Newping Library. to use this sensor with NewPing Library, (not necessary to use this library for this mode, it is a simple program )

#define echoPin 11 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 12 //attach pin D3 Arduino to pin Trig of HC-SR04

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(9600); // // Serial Communication is starting with 9600 of baud rate speed
  Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
  Serial.println("with Arduino UNO R3");
}
void loop() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);  //
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");// working  code for aj-sr04m
}
Measuring the obstacle distance using Waterproof Ultrasonic Senor module in Traditional mode, output distance obtained at serial monitor and distance of obstacle in mm
  • Low Power Mode

This Mode of working is similar to mode1 for this mode to working we need to do some hardware configuration, earlier we mentioned .the replacement of R19 by 300KΩ. In this mode, the module in sleep mode, when >1ms TTL trigger signal occurred, measure the distance and gives the output distance in mm. in this mode current consumption is better.

The working code for his mode is the same as mode1, the only changes are the resistance value used.

  • Automatic Serial port mode

Use Resistance value 120KΩ, to enter the Automatic Serial port mode. The trigger signal not used in this mode, Serial data output occurred at the echo line.   AJ-SR04m transmits bytes per measurement, which is shown below.

Byte1Byte2Byte3Byte4
Start ByteUpper ByteLower ByteChecksum

40KHZ pulse generated internally for every 120ms and gives the output distance in echo line. distance in (mm). The checksum is the output,  and it is the sum of the Upperbyte and LowerByte.checksum is used to verify the packet loss during transmission.

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
 
SoftwareSerial jsnSerial(rxPin, txPin);
 
void setup() {
  jsnSerial.begin(9600);
  Serial.begin(9600);
}
 
void loop() {
  /*jsnSerial.write(0x01);
   delay(10);*/
  if(jsnSerial.available()){
    getDistance();
   //
  
  }
  
}
void getDistance(){
  unsigned int distance;
  byte startByte, h_data, l_data, sum = 0;
  byte buf[3];
  
  startByte = (byte)jsnSerial.read();
  if(startByte ==255){
    jsnSerial.readBytes(buf, 3);
    h_data = buf[0];
    l_data = buf[1];
    sum = buf[2];
    distance = (h_data<<8) + l_data;
    if((( h_data + l_data)) != sum){
      Serial.println("Invalid result");
    }
    else{
      Serial.print("Distance [mm]: "); 
      Serial.println(distance);
      
    } 
  } 
  
  else return;
  delay(100);
}
  1. Low Power Serial Mode: 

Use 47KΩ at R19 to enter the Low power mode, this measurement performing on the request of the trigger input. The communication is serial, we need to trigger a signal to start the measurement, in this, we use trigger command  0x01 for starting the measurement. this mode has a low power consumption mode compares to mode 3.

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
 
SoftwareSerial jsnSerial(rxPin, txPin);
 
void setup() {
  jsnSerial.begin(9600);
  Serial.begin(9600);
}
 
void loop() {
    jsnSerial.write(0x01);
    delay(50);
  if(jsnSerial.available()){
    getDistance();
  }
}
void getDistance(){
  unsigned int distance;
  byte startByte, h_data, l_data, sum = 0;
  byte buf[3];
  
  startByte = (byte)jsnSerial.read();
  if(startByte == 255){
    jsnSerial.readBytes(buf, 3);
    h_data = buf[0];
    l_data = buf[1];
    sum = buf[2];
    distance = (h_data<<8) + l_data;
    if((( h_data + l_data)&0xFF) != sum){
      Serial.println("Invalid result");
    }
    else{
      Serial.print("Distance [mm]: "); 
      Serial.println(distance);
    } 
  } 
  else return;
}
Measuring the obstacle distance using Waterproof Ultrasonic Senor module in Lowe power serial mode, output distance obtained at serial monitor and distance of obstacle in mm
  • Computer Printing Mode:

Simply short the resistor R19 to enter to this mode, this Computer Printing Mode is the easiest mode compare to other modes, in previous modes the distance calculation we need to do it. But here the output distance occurred at the serial monitor. The output is readable on a serial monitor.

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
 
SoftwareSerial jsnSerial(rxPin, txPin);
 
void setup() {
  
  jsnSerial.begin(9600);
  Serial.begin(9600);
}
 
void loop() {
    jsnSerial.write(0x01);
    delay(10);
    if(jsnSerial.available()){
    Serial.println(jsnSerial.readString());
  }
}
Measuring the obstacle distance using Waterproof Ultrasonic Senor module in Computer printing mode, output distance obtained at serial monitor and distance of obstacle in mm

You can purchase all products that were used in this article – ultrasonic sensor, Arduino Uno, BreadBoard, Jumper wires, and many such modules are available for sale on our website – www.probots.co.in .You can order them online.