Arduino Nano Ultrsonic Sensor HC-SR04

This article is included in the ISTEM 2023 Series

  • In the Arduino IDE Library Manager, enter HC-SR04 into the search box.
  • Find and Install the HC-SR04 library by Dirk Sarodnick.
  • Open the HC-SR04 Simple example code.
  • Modify the code so the triggerPin is set to 11.
  • Check and Upload the code to the Arduino Nano.
Ultrasonic Sensor Unabstructed
Ultrasonic Sensor with my hand covering it
  • Open the Serial Monitor.
  • Notice that the distance varies as you move your hand closer and away from the sensor. 

Code Challenge!: My ruler is in inches, modify the code to display inches instead of centimeters.

  • Verify operation using the Serial Monitor.

Leave a Comment

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