Skip to content

Latest commit

Β 

History

History

README.md

πŸ“˜ Day 04: Ultrasonic Sensor (HC-SR04) - Distance Measuring

Welcome to Day 04 of the Arduino Explorer: 30 Days, 30 Sensors journey! Today, we will be exploring the Ultrasonic Sensor (HC-SR04). This sensor is widely used in robotics, obstacle detection, and range finding. It allows us to measure the distance to an object using ultrasonic sound waves.


πŸ“Œ Project Overview

  • Sensor: Ultrasonic HC-SR04

  • Purpose: To measure the distance to objects

  • Difficulty: Beginner Friendly

  • Topics Covered:

    • Working principle of ultrasonic sensors
    • Accurate distance measurement in centimeters
    • Displaying sensor output via Serial Monitor

πŸ“‚ Project Structure

Day04_Ultrasonic_Sensor/
β”œβ”€β”€ ultrasonic_sensor.ino
β”œβ”€β”€ Code_Explanation.md
β”œβ”€β”€ requirements.md
β”œβ”€β”€ README.md
β”œβ”€β”€ Schematic View.pdf
β”œβ”€β”€ wiring_diagram.png
β”œβ”€β”€ Screeshot 1.png
└── Tinkercad_Simulation_Guide.md

πŸ”§ Components Required

Component Quantity
Arduino Uno/Nano 1
Ultrasonic Sensor HC-SR04 1
Jumper Wires 4
Breadboard 1
USB Cable 1

πŸ”Œ Connections

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

⚠️ Make sure to connect the Echo pin to a digital pin that supports pulseIn().


πŸ” Working Principle

The sensor sends out an ultrasonic pulse and waits for it to bounce back from an object. The time taken for the echo to return is used to calculate the distance.

Formula:

Distance (cm) = Duration Γ— 0.0343 / 2

🧠 What You’ll Learn

  • Fundamentals of ultrasonic wave-based distance measurement
  • Interfacing HC-SR04 with Arduino
  • Using digitalWrite(), pulseIn(), and Serial Monitor
  • How to avoid common pitfalls like noise and misreads

πŸš€ Getting Started

1. Upload the Code

  • Open the ultrasonic_sensor.ino file in the Arduino IDE.
  • Connect your Arduino board.
  • Upload the sketch.

2. Open Serial Monitor

  • Set baud rate to 9600
  • Observe real-time distance measurements in cm

πŸ› οΈ Troubleshooting

  • No Output: Check VCC and GND wiring
  • Always 0 cm: Reverse ECHO/TRIG pins
  • Fluctuating Readings: Add a delay and avoid noisy environments

πŸ§ͺ Simulate Online (Tinkercad)

Use this project even if you don't have physical components!

  1. Visit Tinkercad Circuits

  2. Create new circuit

  3. Add:

    • Arduino Uno
    • HC-SR04 sensor
    • Connect as per the above table
  4. Copy-paste the ultrasonic_sensor.ino code

  5. Start Simulation & open Serial Monitor

More help: See Tinkercad_Simulation_Guide.md


πŸ“₯ Requirements

  • Arduino IDE
  • Libraries: None (built-in functions only)

Check requirements.md for details.


βœ… Output

  • Real-time distance readings on Serial Monitor (in cm)
  • Accuracy: Β±3 mm typically

πŸ’¬ Feedback & Contribution

We welcome suggestions and improvements! If you find a bug or have a feature request, feel free to open an issue or PR.

Happy Building! πŸš€

β€” Arduino Explorer Team