กลับไปหน้ารวมไฟล์
distance-measurement-with-an-ultrasonic-sensor-hy-srf05-bf2923-en.md

The ultrasonic sensor measures the distance of the nearest object, sending the result to the serial port. It can work from 2 cm to 3 m. It measures the time spent by the signal to reach the object and return to the sensor.

Connections:

  • Vcc -> 5 V
  • Trig -> pin 13 (digital pin)
  • Echo -> pin 12 (digital pin)
  • Out ->
  • GND -> GND

Sonar Technology Overview

The HY-SRF05 Ultrasonic Ranging Project is a fundamental lesson in "Non-Contact Measurement." While simple to wire, it introduces builders to the physics of acoustics and the mathematics of speed, time, and distance. The HY-SRF05 is an evolved version of the classic HC-SR04, offering higher precision and the ability to operate in many different wiring modes. This project is the first step toward building autonomous robots that can "see" obstacles.

Hardware Core & Detection Tier

  • Arduino UNO: Functions as the master timekeeper. It generates the precise 10-microsecond trigger pulse and measures the return echo with microsecond granularity.
  • HY-SRF04/05 Ultrasonic Sensor: The system's "Acoustic Transceiver."
    • Transmitter (T): Emits a 40kHz ultrasonic burst (invisible and inaudible).
    • Receiver (R): Listens for the "echo" bouncing back from a solid surface.
  • Pins and Mode:
    • Trig (Pin 13): Input pin used to start the measurement.
    • Echo (Pin 12): Output pin that goes HIGH for a duration equal to the flight time of the sound.
    • Out (MODE Pin): On the SRF05, this pin can be used to set 1-pin or 2-pin operation.

Dimensional Logic and Math

The distance calculation is based on the universal Speed of Sound (approx. 343 m/s at room temperature):

  1. The Pulse Cycle: The Arduino sends a 10us HIGH pulse to the Trig pin. The sensor responds by shooting out 8 cycles of ultrasonic sound.
  2. Timing the Flight: The Echo pin turns HIGH. The Arduino uses the pulseIn() function to wait until the pin turns LOW, giving the total "Time of Flight" in microseconds.
  3. Calculating Centimeters:
    • Since the sound traveled to the object and back, we divide the time by 2.
    • Using the constant 0.0343 (cm per microsecond), the distance is: Distance = (Time / 2) * 0.0343.
  4. Data Reporting: The final value is printed to the Serial Monitor in a human-readable format (e.g., "15.4 cm").

Why This Project is Important

This build teaches the fundamentals of Pulse-Width Timing and Acoustic Physics. It demonstrates how to translate an invisible environmental phenomenon into a tangible digital variable. Once mastered, you can use this distance data to trigger alarms (Parking Sensors), drive motors (Obstacle Avoiding Robots), or even measure liquid levels in a water tank (IoT Tank Monitor).

ข้อมูล Frontmatter ดั้งเดิม

title: "Distance Measurement with an Ultrasonic Sensor HY-SRF05"
description: "Measure the world around you."
author: "Nicholas_N"
category: "Sensors & Environment"
tags:
  - "sensor"
views: 105199
likes: 10
price: 435
difficulty: "Easy"
components:
  - "1x Arduino UNO"
  - "1x HY-SRF05 Ultrasonic Sensor"
tools: []
apps: []
downloadableFiles: []
documentationLinks: []
passwordHash: "a61e7a6c7b6620308844e79cc15021d3f59ed45cff5c6ff966ea3aff84db03a6"
encryptedPayload: "U2FsdGVkX18LM5AxmfILt/DP4N3Kq1n6Qj76s52lTq6LVW7BJV/zFIEijx+wmZ9kKqc9/C4oIhvJCDxpkE0btGDcizKWdfqaYH8bveXZuqM="
seoDescription: "Learn how to measure distance using Arduino and Ultrasonic Sensor HY-SRF05. Simple and accurate for object detection projects."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/distance-measurement-with-an-ultrasonic-sensor-hy-srf05-bf2923_cover.jpg"
lang: "en"