Tuesday, October 20, 2020
Home Arduino Strarter Kit HC-SR05 | ULTRASONIC SENSOR

HC-SR05 | ULTRASONIC SENSOR

The HC-SR05 is an upgrade from the lower precision HC-SR04. This has 5 pins and can be used in 1-pin trigger/echo or 2-pin.

USA purchase link
UK purchase link
Germany purchase link

hc-sr05
HC-SR05 Module

Specification

  • Trigger Pin Format: 10 uS digital pulse
  • Sound Frequency: 40 kHz
  • Echo Pin Output: 0-Vcc
  • Echo Pin Format: output is DIGITAL and directly proportional to range. See our conversion formula above.
  • Range: 2cm to ~4.5m
  • Resolution: 0.3cm
  • Angle: up to 15 deg
  • Measurement Rate: 40 Hz
  • Supply Voltage: 4.5V to 5.5V
  • Supply Current: 10 to 40mA
  • Connector: standard 5-pin male connector which can plug directly into breadboards.

How does the HC-SR05 work :

The sensor contains emitter and transmitter which uses a frequency in the range of ultrasound, for example, the range is around 40 kHz. The emitter produces the sound and the transmitter catches the reflected echo. From the timer’s time, it is easier to calculate the total distance, in conclusion, half of the distance is the actual distance between the two objects.

HC-SR05 Pin Configuration :

HC-SR05 Pinout

This module has four pins:

  • Vcc+
  • Trigger
  • Echo
  • Output
  • Ground

Arduino Wiring :

First, GND to Arduino GND

Second, Sensor Vcc+ to Arduino +5V

Third, Echo to Arduino PIN 9

Output is left floating

Lastly, Trigger to Arduino PIN 10

Arduino Code:

 int TRIG_PIN=13;
 int ECHO_PIN=12;
 int BAUD_RATE=9600;

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  Serial.begin(BAUD_RATE);
}

void loop() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  

 long duration= pulseIn(ECHO_PIN, HIGH);
 int distance= duration/29/2;
 if(duration==0){
   Serial.println("Warning: no pulse from sensor");
   } 
  else{
      Serial.print("distance to nearest object:");
      Serial.println(distance);
      Serial.println(" cm");
  }
 delay(100);
 }

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

KY-032 | OBSTACLE AVOIDANCE SENSOR

The KY-032 obstacle avoidance sensor is an infrared obstacle avoidance sensor. It comes with the 37 in 1 starter kit for Arduino. It helps...

HIH-4000 | Humidity Sensors

The HIH-4000  sensors are one of the highly efficient humidity sensors you can buy. The HIH-4000 is an analog humidity sensor. It is useful...

KY-026 | ARDUINO FLAME IR SENSOR

The KY-026 Arduino Flame Sensor is a low-cost starter sensor. It normally comes in the starter kit of Arduino like the ky-039. It can...

KY-039 | ARDUINO HEARTBEAT SENSOR

The KY-039 Heartbeat sensor is one of the cheapest sensors to get a start on Arduino like the Sound sensor. It cost less than...

Recent Comments