Ultrasonic Sensor | Arduino Tutorial
Maybe your like
About Ultrasonic Sensor
Ultrasonic sensor HC-SR04 is used to measure the distance to an object by using ultrasonic waves.
Pinout
The ultrasonic sensor HC-SR04 includes four pins:
- VCC pin: needs to be connected to VCC (5V)
- GND pin: needs to be connected to GND (0V)
- TRIG pin: this pin receives the control signal (pulse) from Arduino.
- ECHO pin: this pin sends a signal (pulse) to Arduino. Arduino measures the duration of pulse to calculate distance.
image source: diyables.io How It Works
This section is the in-depth knowledge. DON'T worry if you don't understand. Ignore this section if it overloads you, and come back in another day. Keep reading the next sections.- Micro-controller: generates a 10-microsecond pulse on the TRIG pin.
- The ultrasonic sensor automatically emits the ultrasonic waves.
- The ultrasonic wave is reflected after hitting an obstacle.
- The ultrasonic sensor:
- Detects the reflected ultrasonic wave.
- Measures the travel time of the ultrasonic wave.
How to Get Distance From Ultrasonic Sensor
To get distance from the ultrasonic sensor, we only need to do two steps (1 and 6 on How It Works part)
- Generates a 10-microsecond pulse on TRIG pin
- Measures the pulse duration in ECHO pin, and then calculate the distance between sensor and obstacle
Distance Calculation
We have:
- The travel time of the ultrasonic wave (µs): travel_time = pulse_duration
- The speed of the ultrasonic wave: speed = SPEED_OF_SOUND = 340 m/s = 0.034 cm/µs
So:
- The travel distance of the ultrasonic wave (cm): travel_distance = speed × travel_time = 0.034 × pulse_duration
- The distance between sensor and obstacle (cm): distance = travel_distance / 2 = 0.034 × pulse_duration / 2 = 0.017 × pulse_duration
Arduino - Ultrasonic Sensor
Arduino's pins can generate a 10-microsecond pulse and measure the pulse duration. Therefore, we can get the distance from the ultrasonic sensor by using two Arduino's pins:
- One pin is connected to TRIG PIN to generate 10µs pulse to TRIG pin of the sensor
- Another pin is connected to ECHO PIN measure pulse from the sensor
Tag » Arduino Hc-sr04 Code
-
Ultrasonic Sensor HC-SR04 With Arduino Tutorial
-
Getting Started With The HC-SR04 Ultrasonic Sensor - Arduino Cloud
-
Ultrasonic Sensor HC-SR04 And Arduino - Complete Guide
-
Complete Guide For Ultrasonic Sensor HC-SR04 With Arduino
-
Sử Dụng Cảm Biến Khoảng Cách HC-SR04
-
Arduino - Ultrasonic Sensor - Tutorialspoint
-
HC-SR04 Ultrasonic Sensor With Arduino Tutorial (5 Examples)
-
How HC-SR04 Ultrasonic Sensor Works & How To Interface It With ...
-
Ultrasonic Sensor HC-SR04 And Arduino Tutorial - YouTube
-
Ultrasonic Sensor HC-SR04 With Arduino Tutorial
-
Ultrasonic Sensor HC-SR04 And Arduino Tutorial
-
Arduino Lib For HCSR04 Ultrasonic Sensor - GitHub
-
Using The HC-SR04 Ultrasonic Distance Sensor With Arduino