how to get signal to led to stay on

hello i have modified a ping sketch i have found on the internet to turn an led on and off when one of 3 ping sensors returns a value <= 5 inches the problem i am having is i would like the led to stay on until the ping sensor that is sending the target value is back above 5 inches as written the led flashes off and on even though the sensor that is returning the <= 5 inch value is maintained at less than 5 inches i know it has to be some thing i have not included in the code but i am a noob at arduino programming and need a little guidance
Thanks for any and all help James

    /*
    Treehouse Projects - www.treehouseprojects.ca
    Ping HC-SR04 Tutorial
    This program is adapted from the example Ping code from Arduino.
    It is extended to light a red LED when an object is a certain distance
    from the sensor, and green otherwise.
    Jun. 2012
    */
     
    //pin which triggers ultrasonic sound
    const int trigPin0 = 22;
    const int trigPin1 = 24;
    const int trigPin2 = 26; 
    const int ledPin =28;
    //pin which delivers time to receive echo using pulseIn()
    int echoPin0 = 23;
    int echoPin1 = 25;
    int echoPin2 = 27;  
     
    void setup() {
      // initialize serial communication
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);
    }
     
    void loop()
    {
      //raw duration in milliseconds, cm is the
      //converted amount into a distance
      long duration, inches, cm;
     
      //initializing the pin states
      pinMode(trigPin0, OUTPUT);
      pinMode(trigPin1, OUTPUT);
      pinMode(trigPin2, OUTPUT);
     
      //sending the signal, starting with LOW for a clean signal
      digitalWrite(trigPin0, LOW);
      delayMicroseconds(1000);
      digitalWrite(trigPin0, HIGH);
      delayMicroseconds(5000);
      digitalWrite(trigPin0, LOW);
     
      //setting up the input pin, and receiving the duration in
      //microseconds for the sound to bounce off the object infront
      pinMode(echoPin0, INPUT);
      duration = pulseIn(echoPin0, HIGH);
      {
      if (inches <= 5) {
        digitalWrite(ledPin,HIGH);
      }
      else{
        digitalWrite(ledPin,LOW);
      }
    }
      // convert the time into a distance
       inches = microsecondsToInches(duration);
   

      
      //printing the current readings to ther serial display
      Serial.print(inches);
      Serial.print("in");
      Serial.println();
     delay(1000);
     
     
      //run 2
     
      //sending the signal, starting with LOW for a clean signal
      digitalWrite(trigPin1, LOW);
      delayMicroseconds(1000);
      digitalWrite(trigPin1, HIGH);
      delayMicroseconds(5000);
      digitalWrite(trigPin1, LOW);
     
      //setting up the input pin, and receiving the duration in
      //microseconds for the sound to bounce off the object infront
      pinMode(echoPin1, INPUT);
      duration = pulseIn(echoPin1, HIGH);
       {
      if (inches <= 5) {
        digitalWrite(ledPin,HIGH);
      }
      else{
        digitalWrite(ledPin,LOW);
      }
    }
    
      // convert the time into a distance
      inches = microsecondsToInches(duration);
     
      //printing the current readings to ther serial display
      Serial.print(inches);
      Serial.print("in");
      Serial.println();
      delay(1000);
      
        //run 3
     
      //sending the signal, starting with LOW for a clean signal
      digitalWrite(trigPin2, LOW);
      delayMicroseconds(1000);
      digitalWrite(trigPin2, HIGH);
      delayMicroseconds(5000);
      digitalWrite(trigPin2, LOW);
     
      //setting up the input pin, and receiving the duration in
      //microseconds for the sound to bounce off the object infront
      pinMode(echoPin2, INPUT);
      duration = pulseIn(echoPin2, HIGH);
      {
      if (inches <= 5) {
        digitalWrite(ledPin,HIGH);
      }
      else{
        digitalWrite(ledPin,LOW);
      }
    }
      // convert the time into a distance
      inches = microsecondsToInches(duration);
     
      //printing the current readings to ther serial display
      Serial.print(inches);
      Serial.print("in");
      Serial.println();
     
      delay(1000);
   
    }
     
    long microsecondsToInches(long microseconds)
    {
      // The speed of sound is 340 m/s or 29 microseconds per centimeter.
      // The ping travels out and back, so to find the distance of the
      // object we take half of the distance travelled.
      return microseconds / 74 / 2;
    }
  1. the sensor will exhibit noise - the signal will vary up and down so it’ll be returning
    < 5" and >= 5" in rapid succession when near the 5" range.

  2. You nearly always need hysteresis when switching on an analog sensor output.

Hysteresis means you have two thresholds, one for switching on, one for switching
off, and the difference in thresholds should be greater than the peak-to-peak amplitude
of the noise.

Try something like:

  if (range < 4.0)
    digitalWrite (ledpin, HIGH) ;
  if (range > 6.0)
    digitalWrite (ledpin, LOW) ;
[/quote]

i made these changes in the code but am still getting the led flashing on and off no matter if the sensors is reading <5 inches or a reading of 41 inches there must be something missing elsewhere that i need to include to get the led to only come on when any of the 3 sensors get a reading of less than 5 inches

  if (range < 5.0)
    digitalWrite (ledpin, HIGH) ;
  if (range > 20.0)
    digitalWrite (ledpin, LOW) ;

problem solved with help from multiple people