Course Content
📘 MODULE 11 – Edge Avoiding Robot
📦 MODULE 12 – Smart Multi-Function Robot (Mega Project)
Arduino Hands-On Programming and Robotics Course

📘 Lesson 5.2 – HC-SR04 Circuit & Arduino Connections

🎯 Learning Objectives

After completing this lesson, students will be able to:

✅ Understand the circuit of an Ultrasonic Distance Meter

✅ Connect HC-SR04 with Arduino Uno

✅ Identify the purpose of each connection

✅ Understand Trigger and Echo communication

✅ Test hardware connections safely

✅ Troubleshoot common wiring mistakes


1. Introduction

In the previous lesson, we learned:

  • What an Ultrasonic Sensor is
  • How HC-SR04 works
  • Trigger and Echo pins
  • Distance measurement concept

Now it is time to connect the sensor with Arduino and build the hardware circuit.

This is the first practical step toward creating an Ultrasonic Distance Meter.


2. Components Required

For this project we need:

Component Quantity
Arduino Uno 1
HC-SR04 Ultrasonic Sensor 1
Breadboard 1
Jumper Wires Few
USB Cable 1
Computer/Laptop 1

3. Understanding the HC-SR04 Pins

Before wiring, let’s review the sensor pins.

Pin Function
VCC Power Supply
TRIG Trigger Input
ECHO Echo Output
GND Ground

4. Arduino Connections

Connect the sensor as follows:

HC-SR04 Pin Arduino Uno Pin
VCC 5V
GND GND
TRIG Digital Pin 9
ECHO Digital Pin 10

5. Circuit Diagram (Text Representation)

 
HC-SR04             Arduino UNO

VCC --------> 5V

GND --------> GND

TRIG --------> D9

ECHO --------> D10
 

6. Why Each Connection is Needed

VCC → 5V

The HC-SR04 requires power to operate.

Arduino provides:

 
5 Volts
 

through its 5V pin.

Without power, the sensor cannot generate ultrasonic waves.


GND → GND

Ground completes the electrical circuit.

Every electronic device connected to Arduino must share a common ground.

Without GND:

  • Sensor may not work
  • Readings become unstable

TRIG → D9

The Trigger pin receives commands from Arduino.

Arduino sends a very short pulse to:

 
TRIG
 

which tells the sensor:

 
Start Measuring Distance
 

ECHO → D10

The Echo pin sends information back to Arduino.

This pin tells Arduino:

 
How long the sound wave took to return
 

Arduino then calculates distance.


7. Data Flow in the Circuit

The communication process is:

Arduino

TRIG Pulse

HC-SR04 Emits Sound

Sound Hits Object

Sound Reflects Back

ECHO Signal Generated

Arduino Calculates Distance

Distance Displayed


8. Breadboard Wiring Method

Place HC-SR04 on the breadboard.

Connect:

Power Rail

Arduino 5V → Breadboard +

Arduino GND → Breadboard –

Then connect:

HC-SR04 VCC → +

HC-SR04 GND → –

This keeps wiring organized.


9. Understanding Trigger Pulse

The Trigger pin requires a pulse of:

 
10 Microseconds
 

Arduino sends this pulse to begin measurement.

Think of it as:

 
"Take a measurement now."
 

10. Understanding Echo Signal

After sending ultrasonic waves:

The sensor waits for reflection.

When sound returns:

The Echo pin becomes HIGH.

The duration of this HIGH signal is measured by Arduino.

Longer duration:

Object is farther away

Shorter duration:

Object is closer


11. Example Distance Measurement Process

Suppose an object is:

 
20 cm
 

away.

Sensor sends ultrasonic wave.

Wave travels to object.

Wave reflects back.

Echo duration measured.

Arduino calculates:

 
20 cm
 

12. Power Requirements

HC-SR04 typically consumes:

 
15mA
 

which is very low.

Arduino can easily power the sensor through its 5V pin.

No external power supply is required.


13. Why We Use Digital Pins?

The HC-SR04 communicates using digital pulses.

Therefore:

 
TRIG → Digital Pin

ECHO → Digital Pin
 

Analog pins are not required.


14. Hardware Testing Before Coding

Before uploading code:

Check:

✅ VCC connected to 5V

✅ GND connected to GND

✅ TRIG connected to D9

✅ ECHO connected to D10

✅ USB cable connected properly

✅ No loose wires

This prevents troubleshooting later.


15. Common Wiring Mistakes

Mistake 1

VCC and GND Reversed

Result:

Sensor does not work.


Mistake 2

TRIG and ECHO Swapped

Result:

No distance readings.


Mistake 3

Loose Jumper Wires

Result:

Random readings.


Mistake 4

Wrong Arduino Pin Numbers

Result:

Program cannot communicate with sensor.


16. Troubleshooting Tips

If the sensor is not working:

Check Power LED

Arduino should be powered.


Check Wiring

Compare with connection table.


Reinsert Jumper Wires

Loose wires are common.


Test Sensor Again

Upload code after verifying hardware.


17. Real-World Example

In an obstacle-avoiding robot:

HC-SR04 constantly measures distance.

If distance becomes:

 
< 10 cm
 

Arduino stops the robot.

Without correct wiring, obstacle detection becomes impossible.


18. Best Practices

✅ Use short jumper wires

✅ Keep wiring neat

✅ Verify connections before power ON

✅ Use color coding

Red = Power

Black = Ground

Yellow = Signal

✅ Label sensor pins while learning


📊 Summary

In this lesson, we learned:

✅ HC-SR04 wiring

✅ Arduino connections

✅ Trigger and Echo communication

✅ Power requirements

✅ Data flow

✅ Troubleshooting techniques

The HC-SR04 circuit is very simple, requiring only four connections, making it one of the easiest sensors to interface with Arduino.


📖 Key Terms

Trigger Pin

Starts ultrasonic measurement.

Echo Pin

Returns timing information.

VCC

Power supply pin.

GND

Ground connection.

Ultrasonic Wave

High-frequency sound wave used for distance measurement.

Pulse

A short digital signal.


🎯 Quiz

1. Which Arduino pin is connected to TRIG in this project?

A. D5

B. D8

C. D9 ✅

D. D13


2. Which Arduino pin is connected to ECHO?

A. D10 ✅

B. D11

C. A0

D. D2


3. What voltage powers HC-SR04?

A. 3.3V

B. 5V ✅

C. 9V

D. 12V


4. Which pin sends measurement results back?

A. VCC

B. GND

C. TRIG

D. ECHO ✅


5. Why is GND important?

A. Programming

B. Distance Calculation

C. Completing the Circuit ✅

D. Data Storage


🏠 Assignment

Task 1

Build the HC-SR04 circuit on a breadboard.

Task 2

Create a wiring table showing all connections.

Task 3

Draw the complete circuit diagram in your notebook.

Task 4

Explain the role of Trigger and Echo pins.

Task 5

List five possible wiring mistakes and their solutions.

Scroll to Top