Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Lesson – 11: How to Use HC-SR04 Ultrasonic Sensor with Arduino | pulseIn() Explained

1.5K views on YouTube

Lesson – 11: Interfacing HCSRO4 Ultrasonic Sensor With An Arduino

Hello and welcome to Electro Nerds Academy. In this video we will learn how to interface the HC-SR04 Ultrasonic Sensor with an Arduino. The HC-SR04 ultrasonic sensor is perfect for projects like, Obstacle avoiding robots, Fluid level detection, Object counting and much more.

In this video, you’ll learn:

✅ How the HC-SR04 ultrasonic sensor works
✅ Pinout and connections with Arduino
✅ Using trigger & echo pins for distance measurement
✅ Writing Arduino code with pulseIn() function
✅ Testing and real-world limitations of the sensor

Code used in this video:

// Lesson 11: HC-SR04 Ultrasonic Sensor with Arduino
// Variables for duration and distance
long duration;
int distance;

void setup()
{
// Start the Serial Monitor
Serial.begin(9600);

// Set pin modes
pinMode(10, OUTPUT);
pinMode(9, INPUT);
}

void loop()
{
// Clear the trigger pin
digitalWrite(10, LOW);
delayMicroseconds(2);

// Send a 10µs pulse to trigger the ultrasonic burst
digitalWrite(10, HIGH);
delayMicroseconds(10);
digitalWrite(10, LOW);

// Measure the duration of the echo pulse
duration = pulseIn(9, HIGH);

// Calculate distance in cm
distance = (duration * 0.034) / 2;

// Print the result on Serial Monitor
Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” cm”);

// Small delay before next measurement
delay(250);
}

By the end of this tutorial, you’ll know exactly how to use the HC-SR04 sensor with Arduino in your own projects.

If you found this helpful, don’t forget to Like 👍, Share 🔁, and Subscribe 🔔 to Circuit Academy for more Arduino and electronics tutorials!

#HCSR04 #ArduinoProjects #ElectronicsDIY #arduino #serialcommunication #arduinotutorials #embeddedsystems #electronicsforbeginners #electronerdsacademy #arduinotutorials #ElectronicsForBeginners #arduinoprogramming #ultrasonicsensor #distancemeasurement #circuitbuilding