Back to Tutorial

AJSR04M Waterproof Ultrasonic Sensor with ESP32 – Complete Guide for Water Level Monitoring

Ultrasonic sensors are widely used in IoT and automation projects for measuring distance and liquid levels. However, standard sensors like HC-SR04 are not suitable for humid or wet environments.

This is where the AJSR04M Waterproof Ultrasonic Sensor becomes extremely useful.

In this guide, we will learn how to connect the AJSR04M ultrasonic sensor with ESP32, understand how it works, and build a simple water level monitoring system using the NewPing library.

This tutorial is ideal for makers, engineers, IoT developers, and students.


What is the AJSR04M sensor Waterproof Ultrasonic Sensor?

The AJSR04M is a waterproof ultrasonic distance sensor designed for harsh and wet environments. Unlike normal ultrasonic sensors, it includes a sealed waterproof probe that can safely operate near water.

It works by sending ultrasonic sound waves and measuring the time it takes for the echo to return.

The sensor then calculates the distance between the sensor and the object.


Key Features of AJSR04M Sensor

✔ Waterproof ultrasonic probe
✔ Distance measurement up to 5 meters
✔ Suitable for water tanks and outdoor environments
✔ High measurement stability
✔ Compatible with ESP32, Arduino, and other microcontrollers


Why Use AJSR04M Instead of HC-SR04?

FeatureHC-SR04AJSR04M
WaterproofNoYes
Outdoor UseLimitedExcellent
ProbeBuilt-inSeparate Waterproof Probe
Maximum Distance~400 cm~500 cm

Because of its waterproof design, the AJSR04M is perfect for water tank monitoring systems.


Components Required

To build this project you will need:

  • ESP32 Development Board
  • AJSR04M Waterproof Ultrasonic Sensor
  • Jumper wires
  • Breadboard (optional)
  • USB cable for programming

ESP32 and AJSR04M Wiring Diagram

Connect the sensor with ESP32 as follows:

AJSR04M PinESP32 Pin
VCC5V
GNDGND
TRIGGPIO 25
ECHOGPIO 26

These pins can be changed depending on your project.


HOW TO CONNECT


Installing the NewPing Library

To use the ultrasonic sensor easily, install the NewPing Library in Arduino IDE.

Steps:

  1. Open Arduino IDE
  2. Go to Sketch → Include Library → Manage Libraries
  3. Search for NewPing
  4. Click Install

This library simplifies ultrasonic distance measurements.


ESP32 Code for AJSR04M Ultrasonic Sensor

Below is the working code to measure distance using ESP32 and AJSR04M sensor.

#include <NewPing.h>

#define TRIGGER_PIN  25
#define ECHO_PIN     26
#define MAX_DISTANCE 500

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  Serial.begin(115200);
}

void loop() {
  delay(50);
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm());
  Serial.println(" cm");
}

Upload the code to your ESP32 board and open the Serial Monitor to view the measured distance.


Understanding the Code

Let’s break down the important parts of the program.

Library Import

#include <NewPing.h>

This loads the NewPing library used for ultrasonic sensors.

Pin Definitions

#define TRIGGER_PIN  25
#define ECHO_PIN     26

These define the trigger and echo pins connected to ESP32.

Maximum Distance

#define MAX_DISTANCE 500

Sets the maximum sensing distance (500 cm).

Sensor Initialization

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

This creates the ultrasonic sensor object.

Reading Distance

sonar.ping_cm()

This function returns the distance in centimeters.


How the Ultrasonic Sensor Works

The working principle of ultrasonic sensors is simple:

  1. The sensor sends high frequency ultrasonic sound waves
  2. The waves hit an object and reflect back
  3. The sensor measures the echo return time
  4. The system calculates the distance

Formula used:

Distance = (Speed of Sound × Time) / 2


Water Tank Monitoring Using AJSR04M

One of the best applications of the AJSR04M sensor is smart water tank monitoring.

The sensor is installed at the top of the tank lid.

It measures the distance between:

Sensor → Water Surface

From this distance, the system calculates the water level percentage.

Example formula:

Water Level % = ((Tank Height − Distance) / Tank Height) × 100

You can then display this value on:

  • LCD Display
  • Mobile App
  • IoT Dashboard
  • Remote ESP32 Display using ESP-NOW

Advantages of Using ESP32 with AJSR04M

ESP32 makes the project more powerful.

Benefits include:

✔ Built-in WiFi
✔ Supports IoT applications
✔ Fast processing speed
✔ Multiple GPIO pins
✔ Compatible with many sensors

This allows you to build advanced smart monitoring systems.


Applications of AJSR04M Ultrasonic Sensor

The sensor can be used in many real-world projects:

Smart Water Tank Level Indicator

Monitor water levels automatically.

Industrial Liquid Monitoring

Used in storage tanks and factories.

Smart Irrigation Systems

Detect water levels in reservoirs.

Robotics

Obstacle detection.

Smart City Projects

Flood monitoring systems.


Conclusion

The AJSR04M waterproof ultrasonic sensor with ESP32 is a powerful solution for distance measurement and water level monitoring.

Because of its waterproof probe and long range, it works much better than standard ultrasonic sensors in outdoor or humid environments.

By combining it with ESP32 and the NewPing library, you can easily build smart systems like:

  • Water tank monitoring
  • IoT level indicators
  • Industrial automation devices

This simple project is perfect for beginners, students, and IoT developers.

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial