(HC-SR04) Ultrasonic Arduino? Easy!


Introduction: (HC-SR04) Ultrasonic Arduino? Easy!

Here is how you can get your Ultrasonic Sensor (HC-SR04) working in less than 5 minutes!

You will need:


  • Gnd -> pin 13
  • Echo -> pin 12
  • Trig -> pin 11
  • Vcc -> pin 10



The measured distance is sent to your computer through the serial port, in centimeters and inches!


  • Make sure you connected the module properly
  • Make sure that the Serial Monitor is set to 9600 Baud
  • You may need to install additional drivers if using a non-genuine Arduino


I am aware that it is not ideal to use digital pins for VCC and Ground, but works well for this example plus it eliminates the need for using a breadboard.Once you've got the code up and running, you can experiment with different ranges or connecting multiple modules. For more precision you can try disabling Interrupts and digging deeper into the lower-level functionality of the Atmega chip. You can check the sensor's datasheet for detailed specifications [HC-SR04].



    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest

    3 Discussions

    Thank you. You definitely helped me to easily get my HC-SR04 up and running quickly!

    Can you explain where you derived the following:


    and why you limited the readout to between 3 - 100cm?

    How do you view the data please?

    Cool! I've always liked to include ultrasonic sensors in my projects!