See more at:
Facebook link: https://www.facebook.com/pages/Theorycircuit/82511...
The HC-SR 04 is famous ultrasonic range sensor, and its very easy to use with many microcontrollers. This article will give you idea about to interface ultrasonic sensor with arduino board.
Step 1: Make Connections
Here the circuit constructed for to identify the range limit with warning beep sound. This circuit have minimum components such as arduino development board, ultrasonic sensor HC-SR 04 and a buzzer.
Step 2: Arduino Code
/*HC-SR04 Ping distance sensor
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 9
Trig to Arduino pin 8
Buzzer +ve to Arduino pin 13 and GND to GND
Original code sourced from theorycircuit.com
Some code and wiring inspired by arduino.cc
#define trigPin 8
#define echoPin 9
#define Buzzer 13
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 30)
digitalWrite(Buzzer,HIGH); //less than 30cm then buzzer will produce beep sound
if (distance >= 200 || distance <= 0)
Serial.println("Out of range");
/* See more at: http://www.theorycircuit.com/DoItYourself/Electro...