Interface Ultrasonic Sensor With 8051

Ultrasonic sensor act like a bats.

  • The HC-SR04 ultrasonic sensor uses sonar to determine distance.
  • It offers excellent range detection with high accuracy and stable reading.
  • It offers range detection from 2cm to 400 cm or 1 to 13 feet.
  • Ultrasonic sensor consist of Transmitter and Receiver module.


  • Sensor trigger pin must receive a pulse of high (5V) for 10us.
  • Then sensor will transmit out 8 cycle of 40kHz ultrasonic burst.
  • Sensor wait for the reflected ultrasonic burst.
  • When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay.
  • Delay period is a width which proportion to distance.
  • To obtain the distance, measure the width (Ton) of Echo pin.

Timing Diagram

Distance Calculation

  • Time = Width of Echo pulse, in uS (micro second).
  • Distance in centimeters = Time / 58.
  • Distance in inches = Time / 148.


  • Power Supply :+5V DC.
  • Quiescent Current : <2mA.
  • Working Current: 15mA.
  • Effectual Angle: Less than 15 Degree.
  • Ranging Distance : 2cm to 400 cm/1 to 13ft.
  • Resolution : 0.3 cm.
  • Measuring Angle: 30 degree.
  • Trigger Input Ppse width: 10uS.
  • Dimension: 45mm x 20mm x 15mm.

Hardware Required

  • Ultrasonic HC-SR04.
  • 8051 MicroController.

Pin Diagram

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


Leave a Reply

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