Waterproof Ultrasonic Sensor Module (JSN SR04T - 2.0) || Arduino

Introduction: Waterproof Ultrasonic Sensor Module (JSN SR04T - 2.0) || Arduino

About: I'm electronics enthusiast. I like to design and develop new things.

In this instructable, I will show you how to interface a Waterproof Ultrasonic Sensor Module (JSN SR04T - 2.0) with the Arduino board.

JSN-SR0T4-2.0 ultrasonic distance measurement module can provide 20cm-600cm non-contact distance sensing function, ranging accuracy up to 2mm; module includes the transceiver of an integrated ultrasonic sensor and control circuit.

Features:

  • Small size, easy to use.
  • Low voltage, low power consumption.
  • High precision measurement.
  • Strong anti-interference.
  • Integrated closed waterproof cable probe, suitable for wet, bad measurement occasions.

Step 1: Ultrasonic Sensor (JSN SR04T-2.0) Specifications

Step 2: Operating Mode 1:

The basic working principle:

  • Using IO port TRIG trigger range, to a minimum of the 10us high letter.
  • The module automatically send 8 40khz square waves, automatically detect whether there is a signal to return;
  • 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 (340 m/s)) / 2.
  • The 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 60 ms, marking the end of the measurement, whether successful or not.
  • LED indicator, LED non-power indicator, it will receive the signal after the module will be lit, then the module is working.

Note:

R27 = open that is not solder.

Step 3: Operating Mode 2 (Serial Data, R27 = 47K Resistor.​):

Serial output format for the TTL level, that: 100 ms module for the cycle of automatic transmission The value of the distance, in mm.

Serial baud rate: 9600, n, 8,1. Module power recognition, directly into the work mode, the module to conduct a distance every 100ms range and outputs one frame from the pin TX with four 8-bit data.

The frame format is: 0XFF + HIGH DATA + LOW DATA + SUM 1.

  • 0XFF: for a frame to start the data
  • HIGH DATA: the upper 8 bits of the distance data
  • LOW DATA: the lower 8 bits of the distance data
  • SUM 1: data and, for the effect of its 0XFF + HIGH DATA + LOW DATA = SUM (only low 8)
  • HIGH DATA and LOW DATA synthesize 16-bit data, that is, the distance in millimeters.

Note: Mode 2: R27 = 47K resistor.

Step 4: Operating Mode 3 (Serial Data, R27 = 120K Resistor):

When the module power recognizes, the module into the standby state, the serial output format for the TTL level, the serial port baud rate: 9600, n, 8, 1.

When the RX port receives the 0X55 instruction, the module starts a ranging and outputs from the pin TX out of a frame with four 8-bit data.

The frame format is: 0XFF + HIGH DATA + LOW DATA + SUM 1.

  • 0XFF: for a frame to start the data
  • HIGH DATA: the upper 8 bits of the distance data
  • LOW DATA: the lower 8 bits of the distance data
  • SUM 1: data and, for the effect of its 0XFF + HIGH DATA + LOW DATA = SUM (only low 8)
  • HIGH DATA and LOW DATA synthesize 16-bit data, that is, the distance in millimeters

Note: Mode 3: R27 = 120K resistor.

Step 5: Arduino Coding for Waterproof Ultrasonic Sensor (JSN SR04T - 2.0)

#define TRIGGER_PIN 13

#define ECHO_PIN 12

#define USONIC_DIV 58.0

#define MEASURE_SAMPLE_DELAY 5

#define MEASURE_SAMPLES 20

#define MEASURE_DELAY 25

void setup()
{

Serial.begin(9600); // Serial monitoring

pinMode(TRIGGER_PIN, OUTPUT); // Initializing Trigger Output and Echo Input

pinMode(ECHO_PIN, INPUT);

digitalWrite(TRIGGER_PIN, LOW); // Reset the trigger pin and wait a half a second

delayMicroseconds(500);

}

void loop()
{

delay(MEASURE_DELAY);

long distance = measure();

Serial.print("Distance: ");

Serial.print(distance + 22);

Serial.println(" mm");

}

long measure()
{

long measureSum = 0;

for (int i = 0; i < MEASURE_SAMPLES; i++)

{

delay(MEASURE_SAMPLE_DELAY);

measureSum += singleMeasurement();

}

return measureSum / MEASURE_SAMPLES;

}

long singleMeasurement()
{

long duration = 0; // Measure: Put up Trigger...

digitalWrite(TRIGGER_PIN, HIGH); // Wait for 11 µs ...

delayMicroseconds(11); // Put the trigger down ...

digitalWrite(TRIGGER_PIN, LOW); // Wait for the echo ...

duration = pulseIn(ECHO_PIN, HIGH);

return (long) (((float) duration / USONIC_DIV) * 10.0);

}

Be the First to Share

    Recommendations

    • Fabric Challenge

      Fabric Challenge
    • Meatless Challenge

      Meatless Challenge
    • Backyard Contest

      Backyard Contest

    4 Comments

    0
    scaseley
    scaseley

    4 months ago

    Hi, thanks for the great details. I have been able to configure this to measure snowfall. I am getting accurate readings when there is no snow and I am able to get an accurate reading after the snow is done, and therefore can easily determine how much snow has fallen by subtracting the 2. What I am struggling with now, is when the snow is falling - my readings are "WILD AND CRAZY". I am guessing the cause is the sensor is reflecting whatever snow flakes are under the sensor based on each reading. I am guessing there is not way to resolve this, but wanted to see if anyone had any thoughts for dealing with this? Appreciate any and all suggestions.

    0
    gpnandhakumar777
    gpnandhakumar777

    Question 1 year ago on Step 5

    hey is there any way to get th eraw echo data just like we take it from hc sor sensor for nultiple object detection

    0
    AbhijitA11
    AbhijitA11

    Question 1 year ago on Step 5

    Hello
    Very useful
    Why you added +22 in distance. Any specific reason?
    Regards
    Abhijit

    0
    DIY Hacks and How Tos

    Hello there!

    We're glad you want to share something with the Instructables community!

    And we’re here to help you out.

    Due to some recent changes on the site, we are no longer able to publish stand-alone videos and other forms of incomplete posts. In order to be published live on the site, Instructables must consist of the following things:

    - Multiple steps showing how you made your project

    - Written instructions in each step

    - Your own original images

    Beyond making your Instructable simply publishable, this guide (https://www.instructables.com/id/How-to-Create-a-Feature-Worthy-Instructable/) explains what is required to have your Instructables featured by our site editors. It’s very helpful, and definitely worth checking out.

    We would love to review your project again after you have made the necessary edits, and we will publish your project if it is eligible.

    If you have any questions, please feel free to ask right here or send us an email at service@instructables.com.

    Best,

    Instructables Community Manager