Parking sensor not working!

Hello everybody! Im really new to this kind of stuff and I followed an online tutorial for a parking sensor that uses the Arduino Uno, HC-SR04, Active Buzzer and a breadboard for connections. The sensor/program is supposed to beep at a louder, more consistent frequency as you get closer to the sensor. However, the buzzer only goes off when I take the sensor out. Once the sensor is out the buzzer doesn't stop.

The tutorial I followed: https://www.instructables.com/id/Arduino-Parking-Sensor/#discuss
Here is the code:
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(4, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop() {
if ((distance <50)&&(distance > 0))
{
digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level)
}
else if ((distance > 51)&&(distance < 150))
{
digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10*(distance-50));
digitalWrite(IN4, LOW); // turn the LED on (HIGH is the voltage level)
delay(10*(distance-50));// wait for a set time
}
else if ((distance > 151)&&(distance < 200)) {
digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
digitalWrite(IN4, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000);
}
else if (distance > 200){
digitalWrite(IN4, LOW);
}
delayMicroseconds(10);
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance); //distance is the returned integer, it is the distance in cm
}

Your code is incomplete.
Please post all the code in code tags.

The tutorial I followed: https://www.instructables.com

These things should come with a Surgeon-General's warning.

It might help more if you posted your complete program using code tags when you do.

See read this before posting a programming question

What do you mean by "Active Buzzer" ?

When you run Serial Monitor and set the baud rate to 9600, does it display the expected distances?!?

Hi,
Your code is missing a major and significant set of lines at its beginning.

Tom..... :slight_smile: