What is Ultrasonic Sensor with Arduino Leave a comment

An ultrasonic sensor, also known as an ultrasonic transducer or distance sensor, is a device that uses ultrasonic waves to measure distances or detect objects. Ultrasonic sensors are commonly use in various applications, including robotics, industrial automation, automotive systems, and even consumer electronics.

How does a Sensor work?

Here’s how an ultrasonic sensor typically works:

Transmitter: The sensor consists of a transmitter and a receiver. The transmitter emits a high-frequency sound wave (ultrasonic wave), usually beyond the range of human hearing.

Reflection: The emitted sound wave travels through the air until it encounters an object in its path. When the sound wave hits the object, it reflects back toward the sensor.

Receiver: The sensor’s receiver detects the reflected sound wave.

Time Measurement: The sensor measures the time it takes for the sound wave to travel to the object and back. It calculates the distance based on the speed of sound in the air and the time it takes for the echo to return.

Distance Calculation: Using the formula Distance = (Speed of Sound × Time) / 2, the sensor calculates the distance to the object. Dividing by 2 is necessary because the sound wave travels to the object and then back to the sensor.

Application Use

Ultrasonic sensors are versatile and offer advantages such as non-contact distance measurement, high accuracy, and the ability to work in various environmental conditions. They are often use in applications like:

Obstacle Detection: In robotics and autonomous vehicles, ultrasonic sensors can detect obstacles and help navigate around them.

Distance Measurement: Ultrasonic sensors can measure distances to objects, such as monitoring liquid levels in tanks or measuring the height of objects on a conveyor belt.

Parking Assistance: In automotive systems, ultrasonic sensors are commonly use in parking assistance systems to alert drivers about nearby obstacles when parking.

Object Counting: They can also use to count objects passing by a specific point on a conveyor or assembly line.

Proximity Sensing: Ultrasonic sensors can detect the presence or absence of objects, making them useful in proximity sensing applications.

It’s worth noting that while ultrasonic sensors are effective in many scenarios, their performance can affect by factors like temperature, humidity, and the material properties of objects. Additionally, their accuracy and range can vary depending on the specific sensor model and design.

Arduino Code

Ultrasonic Sensor


* Company Name:LK Tronics
* Author: Research & Development Department
* Date: 2020/ 03/ 12
* https://lk-tronics.com/
* All rights reserved. No part of this code may be reproduced, distributed,
* or transmitted in any form or by any means, including photocopying, recording,
* or other electronic or mechanical methods, without the prior written permission
* of LK Tronics, except in the case of brief quotations embodied in
* critical reviews and certain other noncommercial uses permitted by copyright law.

const int trigPin = 3;
const int echoPin = 2;

long duration; // defines variables
int distance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600);// defines variables

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

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);// Reads the echoPin from Recevire Side

  distance = duration * 0.034 / 2; // Distance calculating

  Serial.print("Distance: ");



Leave a Reply