[ Fundamentals ] Arduino Practice - Distance Measurement Using Ultrasonic Sensor

주피터 · 2019-10-28 · 5
Distance Measurement Using Ultrasonic Sensor Module ⓞ Ultrasonic Sensor Module HC-SR04 1. Operating Voltage: DC 5V 2. Operating Current: 15mA 3. Detection Range: 2cm ~ 4m 4. Size: 45x20x15mm Operating Method (1) Output a trigger signal of approximately 10µs minimum and input it to the Trig pin of the ultrasonic sensor module. (2) The ultrasonic module detects the signal input through the Trig pin and automatically transmits sound waves with eight 40kHz pulses. (3) From this point, the echo pin becomes High state, and when the sound wave is reflected and received back, the echo pin becomes Low state. The period of the High signal from when the sound wave is transmitted until it returns becomes the round-trip time. * Sound speed travels at 340m per second or 1cm distance per 29 microseconds. * The sound wave is reflected and returns, and since it is the round-trip distance, divide by 2. * Distance (cm) = Round-trip time (µSec) / 29 / 2 ⓞ Diagram - Operating Pulse ⓞ Diagram - Pin Configuration ⓞ Physical Specifications Key Specifications 1. Operating Voltage: DC 5V 2. Standby Current: <2mA 3. Level Output: high: 5V, low: 0V 4. Detection Angle: not more than 15 degrees 5. Sensing Range: 2cm-400cm 6. Accuracy: Maximum 0.2cm ⓞ Hardware Configuration Sketch Writing < Initialization Section > < Loop Function Section > < Distance Calculation Function > Serial Monitor Results ⓞ Serial Monitor Distance Measurement Results ``` const int TriggerPin = 13; const int EchoPin = 12; long Duration = 0; void setup() { pinMode(TriggerPin, OUTPUT); pinMode(EchoPin, INPUT); Serial.begin(9600); } void loop() { digitalWrite(TriggerPin, LOW); delayMicroseconds(2); digitalWrite(TriggerPin, HIGH); delayMicroseconds(10); digitalWrite(TriggerPin, LOW); Duration = pulseIn(EchoPin, HIGH); long Distance_mm = Distance(Duration); Serial.print("Distance = "); Serial.print(Distance_mm); Serial.println(" mm"); delay(1000); } long Distance(long time) { long DistanceCalc; DistanceCalc = ((time/2.9)/2); return DistanceCalc; } ```
5
댓글 0
등록된 댓글이 없습니다.