Introduction - Working - Interfacing Ultra Sonic HC-SR04 Sensor
In this post we will see, basic features of ultrasonic sensor, and how to interface it with a microcontroller.
- Principle of Operation:-
*Consists of a tramistter part and a receiver part.
*Transmitter sends US waves, After detecting any obstacle, waves travel back.
*Receiver captures returning waves.
*Time taken for the travel is obtained and distance towards object
is calculated by,
D=(t*340)/2
D=Distance
t=Total time
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPCSEh993X06WlKoRVYwgKsLP1hPYqI6HirjpoGaqDmST3o0bhI3F4Ii5kYgoBvHvg-eHr3qY39yBEgIQdPaNWUw6U7v-I3Add0PjQihI5ghE5-kFtb9aUszGBz_dGE5irXQOgAvnoRGE/s400/Introduction+-+Working+-+Interfacing+Ultra+Sonic+HC-SR04+Sensor1.png)
- Pin Description:-
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOz9R4LfYK5JY7wmRD3vYQSEM3ezKuheV-af4sE6DsDyHCV_NUNaX5a-VwD_o7SMDgbyMgLirS5SzMcADePY5NIKI7XCAmSDM6s_zvJXE9B04F7suTpte-MLwlSUfxpmMGp2oT1bcGgfY/s400/Introduction+-+Working+-+Interfacing+Ultra+Sonic+HC-SR04+Sensor2.jpg)
PIN 1 - VCC - 5v Supply
PIN 2 - Trigger pin - To activate sensor.
PIN 3 - Echo pin - High value for whole wave transmission.
PIN 4 - GND - Ground pin.
- Working:-
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb2awhl4i075cIs59yT7qhNXR3Z0evzejzSABlKd8bvRzeKq8DKBiDtfvKmbiqyH7016oX8s1_drSovnBnQSBqy8BtX3BbzwadhJEOBqTlNOkYnMxRoCZbHVxZ5Zz20Ns4vsE1Vyc61gM/s400/Introduction+-+Working+-+Interfacing+Ultra+Sonic+HC-SR04+Sensor3.png)
* A pulse of time period greater than 10us is applied to trigger pin.
* Transmitter will transmit US waves and echo pin will go high.
* Run a timer during high pulse of echo pin.
* When the receiver receives US waves echo pin goes low,timer is stopped.
* Distance is calculated from timer value.
- Interfacing with Micro-controller:-
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNOk8alGhzctIO0Mvq45ol9dHxnZqkA6Jpb-yMjZZ6Ee2X86qOvMgssdfYPQnQS7ffAMMP2Nobc_PJQNlr3PovF2j4CnPr0u6NpU-kxFF_XnqoJiXjjz3WFpT4_xUn3goWJ__UlWMmlZY/s400/Introduction+-+Working+-+Interfacing+Ultra+Sonic+HC-SR04+Sensor4.bmp)
* Connect echo pin to an interrupt pin in micro-controller.
* Connect trigger pin to any of output pin.
* Generate a pulse of time period greater than 10us and apply to trigger.
* Start a timer with echo pin as its control.
* Calculations based on timer value.
- View as Slideshow :-