Ultrasonic Proximity Sensor Arduino

So, here is another easy-to-build ultrasonic proximity sensor based on Arduino to detect objects made from various materials regardless of their shape, colour, or surface contour. Thanks, it operates using high-frequency sound waves that are inaudible to the human ear!

US Proximity Switch Uno

In this Arduino ultrasonic proximity detection system, an alarm indicator lights up if a body approaches the ultrasonic sensor probe at a predefined distance. The basic circuitry may be extended to relay operation with a suitable relay module. The recommended operating voltage range of the system is 9-12VDC. It works according to the same principle as the ultrasonic echo range of bats.

This is the Arduino Uno/Nano Sketch:

const int trigPin = 9; //US Sensor TRIG
const int echoPin = 10; //US Sensor ECHO
const int driveSignal = 12; //Alert OUT

long duration;
int distance;
int senseDistance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(driveSignal, OUTPUT);

void loop() {
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration * 0.034 / 2;

senseDistance = distance;
if (senseDistance <= 50) { //Sense Distance
digitalWrite(driveSignal, HIGH);
delay(5000); //Alert Duration
digitalWrite(driveSignal, LOW);
else {
digitalWrite(driveSignal, LOW);

This project is centered around the JSN-SR04T waterproof ultrasonic sensor. The JSN-SR04T is an ultrasonic sensor consisting of a waterproof ultrasonic sensor probe and a control circuit. The sensor comes with a 2.5-meter-long cable that connects to the control circuit module which handles the sensor and does all the processing of the signal. Note that only the sensor probe and the cable itself are waterproof.

In principle, the ultrasonic proximity sensor system works by sending out ultrasound waves. When the ultrasound waves get reflected back by a nearby object, the ultrasonic sensor probe detects it. And by timing how much time passed between sending and receiving the ultrasound waves, the distance between the sensor probe and the object is estimated for further processing.

The JSN-SR04T module provides measurements within a range of circa 20cm to 600cm. It can be powered from the Arduino’s 5V and GND pins.

From JSN-SR04T datasheets, the input pin on the control circuit module is called the Trigger as it is used to trigger the sending of the ultrasonic pulse, and its output is called the Echo. The Echo pin is low (L) until the module has taken its distance measurement. It then sets the pin high (H) for the same amount of time that it took the pulse to return.

As a sidenote, when searching for the JSN-SR04T sensor, you might come across its updated version, the JSN-SR04T-2.0 which works exactly the same but is rated for 3-5V instead of 5V.

Below is a diagram of my Arduino hardware setup. I chose 50cm as the sensing distance but you can alter it just by updating the Arduino Sketch accordingly. Note at this point that the minimum distance that can be measured with JSN-SR04T-2.0 is 20cm.

Likewise, the setup shown here employs digital pins 9-10-12 of the Arduino, but of course, you can change it to almost any digital pin you want.

US Uno Circuit

There are many proven ways to detect close proximity with analog and digital electronics. In this experiment, the quick pick is an easily available waterproof ultrasonic distance sensor to detect the proximity of a nearby object through an Arduino microcontroller.

This Arduino ultrasonic proximity sensor features a switch output with an adjustable sustain time. The sensing distance (proximity detection distance) can also be finetuned according to individual requirements.

US Proximity Switch Uno

All that said, I sincerely hope someone finds my rantings useful. If not useful, then perhaps entertaining. Well, keep on doing projects and learning the electronics you love to do!

Leave a Reply

Your email address will not be published. Required fields are marked *