Challenge

Project 2 - Measuring distance of an object using ultrasonic sensor (HC-SR04)

AIM :

In this project we have to write a Code in Microchipp studio to implement it for measuring the distance of an object using ultra sonic distance sensor HC-SR04.

To measure distance of an object using an HC-SR04 ultrasonic sensor, we need to use the following steps:

  1. Connect the trigger of the pin of the sensor to a digital output pin on our microcontroller .
  2. Connect the echo Pin of the sensor to the digital input pin of the microcontroller.
  3. send the short pulse to the trigger pin of the sensor.
  4. measure the duration of the pulse on the echo pin.
  5. use the speed of sound to calculate the distance of the object. The distance formula is:
    Distance = (duration of pulse) x (speed of sound)/ 2
  6. Display the distance on a display or store it in variable for further use.
  7. use speed of sound in the air around 343 m/s.

Goals:

  • Measuring the distance of an object using Ultrasonic Distance Sensor (HC-SR04)
  • Usage of Input Capture Mode

Key Highlights of the Project:

  • Measuring the distance travelled by the wave to the object and gets bounced back from the object to sensor.
  • Measuring Pulse width using Input Capture Mode

I have attached below all the files of the project.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.