Uploaded November 2016 | Updated September 2026, 2 weeks ago
In this Arduino Tutorial we will learn how the HC-SR04 Ultrasonic Sensor works and how to use it with the Arduino Board.
Required Hardware:
Arduino Board: amzn.to/2LZr6t4
Ultrasonic Sensor HC-SR04: amzn.to/3s4SbdT
Breadboard: amzn.to/3qxLxwm
Jumper Wires: amzn.to/3doetmT
Recommended Items:
Use Your Muscles in Project - amzn.to/3wdL45C
37 Sensor & Module Packages - amzn.to/3m66WeQ
Try this Robot Arm - amzn.to/3fq8DCl
Best Resin 3D Printer - amzn.to/39tY8KB
Arduino Compatible Kits - bit.ly/2J2AFF7
Banggood Spring Sale - bit.ly/3slMbOn
Connections:
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.
The HC-SR04 sensor attach to the Breadboard
The Sensor VCC connect to the Arduino Board +5V
The Sensor GND connect to the Arduino Board GND
The Sensor Trig connect to the Arduino Board Digital I/O 9
The Sensor Echo connect to the Arduino Board Digital I/O 10
Code:
First you have to define the Trig and Echo pins. In this case they are the pins number 9 and 10 on the Arduino Board and they are named trigPin and echoPin. Then you need a Long variable, named “duration” for the travel time that you will get from the sensor and an integer variable for the distance.
In the setup you have to define the trigPin as an output and the echoPin as an Input and also start the serial communication for showing the results on the serial monitor.
If the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.
Source Code: create.arduino.cc/editor/mertarduinotech/d3fdbc15-a615-440e-bad1-62718a77d55b/preview
Social Media:
instagram.com/mertarduino
facebook.com/mertarduino
In this Arduino Tutorial we will learn how the HC-SR04 Ultrasonic Sensor works and how to use it with the Arduino Board.
Required Hardware:
Arduino Board: amzn.to/2LZr6t4
Ultrasonic Sensor HC-SR04: amzn.to/3s4SbdT
Breadboard: amzn.to/3qxLxwm
Jumper Wires: amzn.to/3doetmT
Recommended Items:
Use Your Muscles in Project - amzn.to/3wdL45C
37 Sensor & Module Packages - amzn.to/3m66WeQ
Try this Robot Arm - amzn.to/3fq8DCl
Best Resin 3D Printer - amzn.to/39tY8KB
Arduino Compatible Kits - bit.ly/2J2AFF7
Banggood Spring Sale - bit.ly/3slMbOn
Connections:
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.
The HC-SR04 sensor attach to the Breadboard
The Sensor VCC connect to the Arduino Board +5V
The Sensor GND connect to the Arduino Board GND
The Sensor Trig connect to the Arduino Board Digital I/O 9
The Sensor Echo connect to the Arduino Board Digital I/O 10
Code:
First you have to define the Trig and Echo pins. In this case they are the pins number 9 and 10 on the Arduino Board and they are named trigPin and echoPin. Then you need a Long variable, named “duration” for the travel time that you will get from the sensor and an integer variable for the distance.
In the setup you have to define the trigPin as an output and the echoPin as an Input and also start the serial communication for showing the results on the serial monitor.
If the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.
Source Code: create.arduino.cc/editor/mertarduinotech/d3fdbc15-a615-440e-bad1-62718a77d55b/preview
Social Media:
instagram.com/mertarduino
facebook.com/mertarduino








![08# Arduino Visual Programming | Robot Arm Control with Potentiometers | XOD
New Video November 8, 2018: https://youtu.be/tl6A7EKicjo
The Last Few Days Save 40% More for Electronics: https://goo.gl/covX9J
Robot Arm Control with Potentiometers:
In this tutorial we will learn how to control Robot Arm with Potentiometers. We will use XOD visual programming for this. Its very simple and great for beginners.
Required Hardware:
4DOF Robot Arm + SG90:
https://amzn.to/39udgY9
https://goo.gl/LLzd76
Arduino Nano :
https://goo.gl/QbEmNL
https://amzn.to/3w9D45T
Potentiometers:
https://goo.gl/E3MSuS
https://amzn.to/3dlgYq1
Breadboard:
https://goo.gl/vWrJAA
https://amzn.to/3qxLxwm
Jumper Wires :
https://goo.gl/EGTafY
https://amzn.to/3doetmT
4DOF Robot Arm Kit with Uno + Pot + MG90S Servo
https://goo.gl/SjS5E8
Recommended Items:
Use Your Muscles in Project - https://amzn.to/3wdL45C
37 Sensor & Module Packages - https://amzn.to/3m66WeQ
Try this Robot Arm - https://amzn.to/3fq8DCl
Best Resin 3D Printer - https://amzn.to/39tY8KB
Arduino Compatible Kits - http://bit.ly/2J2AFF7
Banggood Spring Sale - https://bit.ly/3slMbOn
Other XOD tutorials :
01# Activate an LED - https://youtu.be/zgu2ID9fzp8
02# LED Brightness with Pot - https://youtu.be/rn_pFUvAjPU
03# Control Servo with Pot - https://youtu.be/R1ErboSVk9w
04# Control LED with Button - https://youtu.be/CtH8Fau8IDk
05# LDR (photoresistor) - https://youtu.be/FMQGCHU75OM
06# DC Motors with L293D - https://youtu.be/_PoCf-mh0aI
07# Obstacle Avoiding Robot - https://youtu.be/07jbVvx3BL4
You can share any technical problem at https://forum.xod.io/
The team of XOD developers will respond to you very quickly and more accurately.
XOD Official https://xod.io/
XOD Community https://forum.xod.io/
Background Music
Syn Cole - Feel Good [NCS Release]
https://youtu.be/q1ULJ92aldE
NoCopyrightSounds - https://goo.gl/Veefkc
Syn Cole - https://soundcloud.com/syncole 08# Arduino Visual Programming | Robot Arm Control with Potentiometers | XOD](https://i.ytimg.com/vi/zO6IACwkHfA/mqdefault.jpg)

