HC-SR04 Ultrasonic Range Finder and Mounting Bracket

£ 3.99


Here we have a precision ultrasonic range finder that accurately measures distance, also included is the mounting bracket.

This particular module is very popular with hobbyists and robotic enthusiasts and there are many online tutorials and projects that attest to this.

  • Voltage: DC5V
  • Static current: less than 2mA
  • level output: high-5V
  • level output: the end of 0V
  • Sensor angle: not more than 15 degrees
  • Detection distance: 2cm-450cm
  • High precision: up to 0.3cm
  • Input trigger signal: 10us TTL impulse
  • Echo signal : output TTL PWL signal
  • Thickness :2.8-3.1mm
  • Fixing Hole Diameter: 3.8MM
  • Material: Acrylic
  • 1 x HC-SR04 Ultrasonic range finder
  • 1 x Acrylic Mounting Bracket

HC-SR04 Ultrasonic Range Finder and Mounting Bracket

Getting started using your sensor simply requires direct connection to your Arduino or you could follow the hook-up diagram further down the page to build a slightly more complex circuit.

Simple Distance Measurement

Connect directly to your microcontroller and start reading distance right away

  • Ultrasonic range finder
  • Arduino
  • Jumper Wire

This code returns the distance in Inches. Remove the *.39 to return cm instead of inches. You could make float ultrasoundValue = 0; but then you can't print it unless you transfer it into another type, but it could be used for further calculations.

unsigned long echo = 0;
 int ultraSoundSignal = 9; // Ultrasound signal pin
 unsigned long ultrasoundValue = 0;
 void setup()
 unsigned long ping(){
 pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
 digitalWrite(ultraSoundSignal, LOW); // Send low pulse
 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
 delayMicroseconds(5); // Wait for 5 microseconds
 digitalWrite(ultraSoundSignal, LOW); // Holdoff
 pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
 digitalWrite(ultraSoundSignal, HIGH); // Turn on pullup resistor
  // please note that pulseIn has a 1sec timeout, which may
  // not be desirable. Depending on your sensor specs, you
  // can likely bound the time like this -- marcmerlin
  // echo = pulseIn(ultraSoundSignal, HIGH, 38000)
  echo = pulseIn(ultraSoundSignal, HIGH); //Listen for echo
  ultrasoundValue = (echo / 58.138) * .39; //convert to CM then to inches
 return ultrasoundValue;
 void loop()
 int x = 0;
 x = ping();
  delay(250); //delay 1/4 seconds.

Distance based piezo tone

The following circuit sounds a piezo buzzer when an object is detected. The tone will get progressively louder as the object draws closer to the sensor.

  • Ultrasonic range finder
  • Piezo speaker
  • 10 kohm resistor
  • Arduino
  • Jumper Wire

const int TRIG = 8;
const int ECHO = 7;
const int BUZZ = 5;
void setup(){
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(BUZZ, OUTPUT);
void loop(){
  long duration, inches, cm;
  digitalWrite(TRIG, LOW);
  digitalWrite(TRIG, HIGH);
  digitalWrite(TRIG, LOW);
  duration = pulseIn(ECHO, HIGH);
  inches = duration / 74 / 2 ;
  cm = duration / 29 / 2 ;
  Serial.print("in, ");
  if(cm < 20){
    analogWrite(BUZZ, (20 - cm) * 10);
    digitalWrite(BUZZ, LOW);