Measuring Distance Using the HCSR04 Ultrasonic Sensor and Arduino

7,545

61

10

Introduction: Measuring Distance Using the HCSR04 Ultrasonic Sensor and Arduino

About: I'm an electronic engineer and i love to learn new stuff and also share my knowledges with everybody and make tutorials to teach about the things that i make.

Hello, in this instructable i will show you how to use an ultrasonic sensor with Arduino. In this case i use the HCSR04 sensor, which can measure in a range from 2 cm to 5 mts.When it detects anything within the range of 15 cm, it will light up a LED, also you can see the measurement readings on the Serial Monitor of the Arduino IDE.

Step 1: What Do You Need?

So for completing this project you will need the following items:

  1. Arduino UNO board.
  2. HCSR04 Sensor x 1.
  3. LED x 1.
  4. Few wires.
  5. PC.

So when you have all of this you can go on the next step

Step 2: Diagram Connections

Just follow the diagram that i show you above and you will be ready to upload the program to your Arduino UNO board. Also check the video on the following step to see how everything is set.

Step 3: And Download the Arduino Program Code!

Now you are here just click on the link below to download the program code for Arduino.

http://www.mediafire.com/file/nggoo5bm3652ok4/Sens...

When you have it, unrar it, then open your Arduino program and upload the code to your Arduino board. If everything went ok until this point you can open the serial monitor on the Arduino IDE and you should see the distance measures that you sensor is taking.

Don't forget to watch the video and turn on the english subtitles to see how the sensor is set with the Arduino and how it works!

That's all folks, thanks for reading and remember, if you have any doubt you can let me know on the comments, i will be happy to help you. Happy coding.

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Be the First to Share

    Recommendations

    • Build a Tool Contest

      Build a Tool Contest
    • Backyard Contest

      Backyard Contest
    • First Time Author Contest

      First Time Author Contest

    10 Comments

    0
    ubalaas
    ubalaas

    1 year ago

    Is there possible with display?

    0
    fdr1929
    fdr1929

    Reply 1 year ago

    Of course!, maybe you can use a 2x16 I2C display, and then make the distance measurements print not to the arduino serial monitor but to the 2x16 display or any other display you want to use, hope this can help you, thanks for reading my stuff, cheers!

    0
    ubalaas
    ubalaas

    Reply 1 year ago

    thanks for the reply.
    can you pls modify with 2X16 I2C also share the code

    I am not a electronic guy.. I am hobbyist. Hence it will be very much better kind frm you

    Also can you pls clarify, whether its shows the decimal point to i.e 14.5cm, 7.3Inch

    0
    RobertRoberts1000
    RobertRoberts1000

    Question 4 years ago on Introduction

    Hey, is there any possibility to regulate the measuring distance with maybe a dimmer?

    0
    FedericoP30
    FedericoP30

    Answer 4 years ago

    Hi, well maybe you can do that by adding the dimmer and measuring its resistance value with the arduino adc, then before measuring the distance with the ultrasonic sensor first check for the dimmer resistance value, by this resistance value you will Change the distance range in the code for the ultrasonic sensor, hope i made myself clear with the explanation and thanks for reading, cheers!

    0
    bhagathkumarborra3
    bhagathkumarborra3

    Question 4 years ago on Step 3

    is there any possibility to get the distance on 16 bit dispaly

    0
    RevanthK7
    RevanthK7

    5 years ago

    i did it! thanks...

    0
    fdr1929
    fdr1929

    Reply 5 years ago

    Yeah, that's awesome!!, thanks for letting me know Revanth, have a nice day!

    0
    ChetanS43
    ChetanS43

    5 years ago

    it's was usefull...

    0
    fdr1929
    fdr1929

    Reply 5 years ago

    Glad to hear that Chetan, thanks for reading, have a nice day!