Arduino Projects

Interface HC-SR04 Ultrasonic Sensor With Arduino


In this project, we will use an Ultrasonic Sensor With Arduino to measure the distance to an object. the ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It is also known as a transducer or sonar. Ultrasonic sensors are used in a wide variety of applications, such as measuring the distance to a parking spot in a car or detecting objects in a factory.

In this project, we will use an ultrasonic sensor with Arduino to make an easy distance measurement device. This device will use the ultrasonic sensor to measure the distance to an object, and will then display the distance on the Serial monitor. Also, Check this  What is Sensor? Different Types of Sensor & Their Uses.

Thank You NextPCB:

This project is successfully finished because of the service and support from NextPCB. NextPCB is one of the most professional PCB manufacturers in Global and has specialized in the PCB and assembly industry for over 16 years. Not only could NextPCB deliver the most creative printed circuit boards and assembly technologies in the most elevated quality standards, but the fastest delivery turnaround was also as fast as 24 hours.

Required Components

To get started, you will need the following materials:

  • Arduino Uno
  • Ultrasonic sensor
  • Breadboard
  • Jumper wires
  • 9V power supply

What is an Ultrasonic Sensor?

HC_SR04 ultrasonic sensor working

An ultrasonic sensor is a device that uses sound waves to measure distance. It can be used to measure the distance between two objects or to measure the thickness of a material. Ultrasonic sensors are used in a variety of applications, including automotive collision avoidance systems, security systems, and industrial process control.

How does an Ultrasonic Sensor work?

ultrasonic sensor working

An ultrasonic sensor is a device that emits sound waves at a frequency too high. When these waves hit a thing, they bounce back and are detected by the sensor. The time it takes for the waves to bounce back is used to calculate the distance to the object.

used in devices such as parking sensors, level sensors, and flow sensors, including obstacle detection, They are also used in some medical applications, such as ultrasound imaging.

Learn more about Ultrasonic sensors:

HC-SR04 Ultrasonic Sensor

ultrasonic sensor

The HC-SR04 is an ultrasonic sensor that can be used to measure distance. It is often used in robotics and automation applications. The sensor works by emitting a sound wave and measuring the time it takes for the sound wave to bounce back. The distance to the object can then be calculated based on the time it took for the sound wave to return. The HC-SR04 sensor is fairly easy to use and is usually used in DIY projects. It is also relatively affordable, making it a popular choice for multiple applications. The sensor is rather accurate and can be used to calculate distances up to 400 cm.

Here are the complete HC-SR04 ultrasonic sensor specifications:

Operating Voltage DC 5V
Operating Current 15mA
Operating Frequency 40KHz
Max Range 4m
Min Range 2cm
Ranging Accuracy 3mm
Measuring Angle 15 degree
Trigger Input Signal 10µS TTL pulse
Dimension 45 x 20 x 15mm

HC-SR04 Ultrasonic Sensor Pinout

ultrasonic sensor with Arduino pinout

The ultrasonic sensor has four pins:

  1. VCC Pin – positive terminal of the source should be connected.
  2. GND Pin – negative or ground terminal of the source should be connected.
  3. TRIG Pin – Acts as an output that emits Ultrasonic Sound waves.
  4. ECHO Pin – Acts as an input that receives the reflected Ultrasonic Sound waves.

Ultrasonic sensor Arduino connection

Ultrasonic Sensor With Arduino circuit

This sensor is perfect for any project that requires accurate distance measurement. The sensor can be connected to an Arduino using only a few wires. First, let’s connect the ultrasonic sensor to the Arduino.

Ultrasonic sensor And Arduino Connections:

  1. Vcc Pin______5V
  2. Trig Pin_____D2
  3. Echo Pin____D3
  4. GND Pin_____GND

Connect the Vcc pin to the 5V power supply pin on the Arduino. Connect the Trig pin to digital pin 9 on the Arduino. Connect the Echo pin to digital pin 8 on the Arduino. Finally, connect the GND pin to GND

Source Code

Now that the sensor is connected, we can write code to measure the distance to an object. The code is very simple.

Here’s an example code:

  • Open Arduino IDE Software and write down your code, or Copy the Above code and paste it
  • Choose an Arduino board, by selecting Tools > Board > Arduino/Geniuno Uno
  • Choose your COM Port  Tools > Port > COM..
  • Upload your source code by pressing Ctrl + U or Sketch > Upload
  • To display the measurement data you can use Serial Monitor by pressing Ctrl + Shift + M

Ultrasonic Sensor With Arduino data

The values ​​of the distance that the HC-SR04 senses will appear on the serial monitor. Put an object in front of it and change its distance from the sensor and confirm that the distance shown on the serial monitor is correct.

Related Articles

Leave a Reply

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

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker