why is my ultrasonic ranger code not working?

Hi all, I am an Arduino novice & have slight problem with some arduino syntax. I am trying to use a unltrasonic range finder SRF05 to vary the pitch of a sound produced by a piezo I have connected to PWM pin number 10. I have uploaded the code but there is no sound and I can't figure out why any suggestions? here is my code.

int echoPin=2; //SRF05 echo pin (digital 2) int initPin=3; //SRF05 trigger pin (digital 3) unsigned long pulseTime=0;

void setup() { pinMode(initPin,OUTPUT); pinMode(echoPin,INPUT); pinMode(10,OUTPUT); } void loop(){ digitalWrite(initPin,HIGH); delayMicroseconds(10); digitalWrite(initPin,LOW); pulseTime=pulseIn(echoPin,HIGH); }

but there is no sound and I can’t figure out why

Where do you ever tell it to make any noise?

In the code pasted I guess I don't write HIGH to pin 10, but I did try that too and still nothing, I don't fully understand what I am doing wrong.

Writing HIGH to a pin with a piezo attached should make some noise, assuming that the piezo works and is connected correctly, but it will be the same noise regardless of the sensor output.

It seems like what you want to do, though, is use the tone() function to print different tones based on the value read from the sensor.

Of course, you need to use Serial.print, and verify that you are getting reasonable data from the sensor, first.

Thank you, I will try this!

Piezos don't normally sound just by driving them high - you need to pulse them.