Pengukuran Jarak Menggunakan Sensor Ultrasonik HC-SR04 dengan Arduino Uno dan OLED Display

Overview

HR-SR-04 sensor ultrasonik mengunakan sonar untuk menentukan jarak benda, hampir mirip dengan kelelawar, Modul ini sudah termasuk transmitter, receiver dan control.

HR-SR-04 mampu mengukur jarak mulai dari 2 cm-400 cm tanpa bersentuhan dengan benda yang diukur dengan akurasi sekitar 3mm.

Specifications

Power Supply :+5V DC
Quiescent Current : <2mA
Working Current: 15mA
Effectual Angle: <15°
Ranging Distance : 2cm – 400 cm/1″ – 13ft
Resolution : 0.3 cm
Measuring Angle: 30 degree
Trigger Input Pulse width: 10uS
Dimension: 45mm x 20mm x 15mm

Cara Kerja

1. Transmitter (Trig Pin) mengirim sinyal frekuensi tinggi

2. Jika sinyal mengenai benda, sinyal akan dipantukan

3. Transmitter (echo pin) menerimanya.

Pins:

VCC: +5VDC
Trig : Trigger (INPUT)
Echo: Echo (OUTPUT)
GND: GND

Schematic

Program/source code

 
int trigPin = 11;    // Trigger
int echoPin = 12;    // Echo
long duration, cm, inches;
 
void setup() {
  //Serial Port begin
  Serial.begin (9600);
  //Define inputs and outputs
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
 
void loop() {
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  // Convert the time into a distance
  cm = (duration/2) / 29.1;     // Divide by 29.1 or multiply by 0.0343
  inches = (duration/2) / 74;   // Divide by 74 or multiply by 0.0135
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(250);
}

Demonstration

Jika kita bandingkan data pengukuran dengan penggaris sekitar 5 cm, dan dengan sensor HC-SR04 , tampak pada serial monitor menunjukkan nilai yang sama, 5cm. Jadi akurasinya lumayan bagus.

Next Project

Leave a Reply

Your email address will not be published. Required fields are marked *