Putting Arduino on stand by “Need Help Please”

I’m trying to turn off my LED lights and buzzer once my ultrasonic sensor stops detecting moving or a new distance. I’m using this project to assist my wife with parking in the garage. So what I’m looking for is for a way to stop measuring once the car reaches and stays at 25 inches. The code I’m currently using is below. Thanks for your help.

Parking assistance for garage

const int pingPin = 12; //setup pingpin as 12
int Buzzer = 8; // Connect buzzer pin to 8
void setup() {
Serial.begin(9600); //this is not necessary
pinMode(2, OUTPUT); // set up these pins as outputs
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);

digitalWrite(2, HIGH); // this is not necessary, this is just a startup
digitalWrite(3, HIGH); // function to let you know it is ready
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
delay (500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
void loop()
{

long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);

if (inches < 50) {
digitalWrite(2, HIGH); } //these numbers give the distances needed to turn lights on or off
if (inches > 50) { //change these to chang thedistances
digitalWrite(2, LOW); }

if (inches < 45) {
digitalWrite(3, HIGH);}
if (inches > 45) {
digitalWrite(3, LOW);}

if (inches < 40) {
digitalWrite(4, HIGH);}
if (inches > 40) {
digitalWrite(4, LOW);}

if (inches < 35) {
digitalWrite(5, HIGH);}
if (inches >35) {
digitalWrite(5, LOW);}

if (inches < 30) {
digitalWrite(6, HIGH);}
if (inches > 30) {
digitalWrite(6, LOW);}

if (inches < 25) {
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);}
if (inches > 25) {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}

delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

So what I'm looking for is for a way to stop measuring once the car reaches and stays at 25 inches

Why not leave it run all the time?

What starts it measuring again?

Why not use a tennis ball?

In the future:
Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Show us a good schematic of your circuit.
Show us a good image of your wiring.

Low power sleep may be useful if this battery powered, it if it’s on a plugpack, the losses in the adapter will draw more than the Arduino!

How would I put it on low power sleep? Sorry for the dumb questions, I’m very very new to this.

All you need is here:

When sleeping the Arduino, you have the problem of waking it up.

It seems to me that OP only wants to stop the lights and buzzer after a while when the car is < 25" from the sensor.
This (untested) sketch might give some ideas.
Leo..

const byte pingPin = 12;
const byte buzzerPin = 8;
long duration, inches;
unsigned long previousMillis, alarmDuration = 10000; // 10 seconds

void setup() {
  for (byte i = 2; i <= 8; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
  delay(500);
  for (byte i = 2; i <= 8; i++) {
    digitalWrite(i, LOW);
  }
}

void loop() {
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  inches = microsecondsToInches(duration);
  if (inches < 25 && millis() - previousMillis >= alarmDuration) {
    for (byte i = 2; i <= 8; i++) {
      digitalWrite(i, LOW);
      delay(1000);
    }
  } else {
    if (inches < 50) digitalWrite(2, HIGH);
    if (inches > 50) digitalWrite(2, LOW);
    if (inches < 45) digitalWrite(3, HIGH);
    if (inches > 45) digitalWrite(3, LOW);
    if (inches < 40) digitalWrite(4, HIGH);
    if (inches > 40) digitalWrite(4, LOW);
    if (inches < 35) digitalWrite(5, HIGH);
    if (inches > 35) digitalWrite(5, LOW);
    if (inches < 30) digitalWrite(6, HIGH);
    if (inches > 30) digitalWrite(6, LOW);
    if (inches < 25) {
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
    } else {
      digitalWrite(7, LOW);
      digitalWrite(8, LOW);
    }
    previousMillis = millis();
  }
  delay(100);
}

long microsecondsToInches(long microseconds) {
  return microseconds / 74 / 2;
}