This tutorial will suggest steps to take if you want to use the HC-SR04 sensor module in a project. The methods used could also be applied to most projects that use a time based sensor.
The target for this tutorial will be the ATmega4808/4809 Curiosity development board. Atmel Studio 7 will be the development environment. The code is written in 'C' and should easily port to other processors.
The tutorial assumes that the reader can create a project in Atmel Studio 7 and configure it to interface to the Curiosity board or whatever target hardware they are using.
main.c is the initial starting code. HC-SR04_1.zip has the Atmel Studio 7 initial project. HC-SR04_2.zip has the reorganized project.