need help with project

#define trigPin 9
#define echoPin 10
long duration;
int distance;
long firstoff;
int distancefirst;
int activated = 0;

void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
delay(1000);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
firstoff = pulseIn(echoPin, HIGH);
distancefirst = firstoff*0.034/2; // cm
}

void loop()
{

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2; // cm
Serial.println(distance);
delay(1000);
Serial.println(distancefirst);

if (distance <= distancefirst - 5);
{
tone(3, 500, 500);
delay(500);
tone(3, 800, 500);
delay(500);
delay(50);
Serial.println(activated);
Serial.println(distance);
}

}
how do you use a potentiometer to change the distance of the ultrasonic sensor so it goes of at a different length

4356THG:
how do you use a potentiometer to change the distance of the ultrasonic sensor so it goes of at a different length

What are you trying to do, really?
Is this the HC-SR04 or another ultrasound sensor?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

4356THG:

how do you use a potentiometer to change the distance of the ultrasonic sensor so it goes of at a different length

If I am understanding your problem;

First see how to use a potentiometer

Then instead of using analogWrite to control an LED using PWM (as in the example) in your code you should use the value from potentiometer in the ‘if’ statement at the end of your code which controls whether or not the tone is sounded.