Connection, Interfacing & Programming of Ultrasonic Sensor HC-SR04

Today I will give you a tutorial on the Ultrasonic sensor HC-SR04 ! Also called as PING sensor or RANGE sensor; it is one of the most basic & easiest sensors of the beginners kit !

About Ultrasonic sensor HC-SR04 :-

The transmitter transmits ultrasonic pulses & they are reflected back & gets sensed by the receiver if any obstacle lies between the path.
The range of this ultrasonic is about 4 metres. There is a chance of error of +-3cm in measuring the distance.
It measures the time interval between sending & receiving the pulse & then by a formula – gives us the distance.

It has got 4 pins :-
VCC –                             connect it to 5V supply.
GND –                            connect it to ground.
echopin, trigpin –  connect it to any digital pin (as of here, we’ve connected them to 9, 10).

& the positive terminal of the LED is connected to pin number 7 on Arduino !

Code for the Ultrasonic sensor :-

You might like –

Make an Obstacle avoiding robot with this Ultrasonic sensor in 10 mins

Here is a video tutorial on the ultrasonic sensor….. 😉

You can buy it from Amazon… here it is

Please do not hesitate to ask questions. Please comment your problems(any kind of) faced by you in the comment section below so that I could answer them as early as possible 🙂 !

You might also like –

Tutorial on Infrared sensor TSOP 17xx | How to control LED with help of TV remote ?



  2. exit status 1
    ‘trigPin’ was not declared in this scope

Leave a Reply

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