Coding question for setup of Ultrasonic sensor (HC-SR04) and

I am relatively new to Arduino so I know the basics however I am not the best at coding. My problem is that I am not sure about the coding for the following setup: I am using a Ultrasonic Sensor (HC-SR04) and a piezo buzzer. I want to be able to move my hand towards the sensor and away from the sensor and in doing this the buzzer will produce notes which will increase and decrease in pitch relative to my hand movement. (e.g. when my hand moves closer to the sensor the notes rise in pitch and when my hand moves away the notes decrease in pitch) I would greatly appreciate any feedback or help as I am quite stuck and it is for a college project!

Take one of the standard examples for the HC-SR04. They usually measure the distance and switch a LED on or off depending on distance.

Next have a look at the tone() function; I’ve never used it but it might do what you want. Else you can switch the buzzer on and off at a given rate (e.g. 1ms on, 1ms off will give you a 500Hz tone).