Troubles with my parking alarm

Hello everyone!!So I was trying to make a parking alarm just to figure it out how my HC-SR04 distance sensor works, and I had faced some troubles with my code.
CODE:

/*The following program checks with a HC-SR04 distance sensor if there is 
 an object between 2m and 25cm. If there is an object between 2m and 1and a half
 meters the two green leds are changing from LOW to HIGH.If there is an object
 between 1,50m and 50cm the green and the yellow LDS are going HIGH.If there is 
 an object between 50cm and 25cm all the leds are going HIGH.And finally if 
 there is an object closer to 25cm all the leds are flashing.
 Circuit:ONE HC-SR04 Sensor
 two green leds,two yellow leds,two red leds with a 220? resistor attached to 
 each one of them
 wires!!!!*/



int gren=10;
int green=9;
int yellow=6;
int yellow1=5;
int red=4;
int red1=2;
int trig=8;//triger pin of the sensor
int echo=7;//echo pin of the sensor
int maximumrange=200;//the maximum range that we want the sensor to measure
int minimumrange=25;//minimum range that we want the sensor to measure
int redRange=50;
int yellowRange=150;


long duration,distance;

void setup(){
  Serial.begin(9600);
  pinMode(echo,INPUT);
  pinMode(trig,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(gren,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(yellow1,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(red1,OUTPUT);
 }


void loop(){
  //We send signal from the triger pin and taking the signal with the 
  //echo pin
  digitalWrite(trig,LOW);
  delayMicroseconds(2);

  digitalWrite(trig,HIGH);
  delayMicroseconds(10);

  digitalWrite(trig,LOW);
  duration=pulseIn(echo,HIGH);
  //we calculate the distance
  distance=duration/58.2;
  if(distance <=minimumrange){//minimum=25cm
    limit();
  }
 else if(distance <=redRange && distance >= minimumrange){
    redLimit();//red=50 minimum=25
  }
  /*if the distance is smaller or equal to 1,50 m and greater or equal to 25cm
   do the fowlloings*/
 else if(distance <= yellowRange && distance >=redRange){
    yellowLimit();//yellow=150cm red=50cm
  }
  else if(distance <= maximumrange && distance >= yellowRange){
    greenLimit();
  }

}
void redLimit(){
  Serial.println();
  Serial.print("  RED ATTENTION!!! You are: ");
  Serial.print(distance);
  Serial.print(" cm close to an object");

  digitalWrite(green,HIGH);
  digitalWrite(gren,HIGH);
  digitalWrite(yellow,HIGH);
  digitalWrite(yellow1,HIGH);
  digitalWrite(red,HIGH);
  digitalWrite(red1,HIGH);
}
void limit(){   //limit= 25cm from an object
  Serial.println();
  Serial.print(" ATTENTION!!! You are: ");
  Serial.print(distance);
  Serial.print(" cm close to an object");

  digitalWrite(green,HIGH);
  digitalWrite(gren,HIGH);
  digitalWrite(yellow,HIGH);
  digitalWrite(yellow1,HIGH);
  digitalWrite(red,HIGH);
  digitalWrite(red1,HIGH);
  delay(500);
  digitalWrite(green,LOW);
  digitalWrite(gren,LOW);
  digitalWrite(yellow,LOW);
  digitalWrite(yellow1,LOW);
  digitalWrite(red,LOW);
  digitalWrite(red1,LOW);
  delay(500);
}

void yellowLimit(){ 
  Serial.println();
  Serial.print(" YELLOW You are: ");
  Serial.print(distance);
  Serial.print(" cm close to an object");


  digitalWrite(red,LOW);
  digitalWrite(red1,LOW);
  digitalWrite(green,HIGH);
  digitalWrite(gren,HIGH);
  digitalWrite(yellow,HIGH);
  digitalWrite(yellow1,HIGH);
  delay(500);
}

void greenLimit(){
  Serial.println();
  Serial.print("green limit You are: ");
  Serial.print(distance);
  Serial.print(" cm close to an object");

  digitalWrite(yellow,LOW);
  digitalWrite(yellow1,LOW);
  digitalWrite(red,LOW);
  digitalWrite(red1,LOW);
  digitalWrite(green,HIGH);
  digitalWrite(gren,HIGH);

  delay(500);

}

(PLEASE ignore the comments and the spelling mistakes :P)
So When I upload the code to my Arduino Uno if there is an object between the limit(25cm or less) all the leds are flashing and in the serial port writes ATTENTION…(So far so good).
And here are the problems:
If there is an object between the red limit(25cm to 50cm), non of the leds are ON :~
If there is an object between the yellow limit(50cm to 150cm) only the red leds are ON :drooling_face:
And finally if there is an object between the green limit(150cm to 200cm) only the yellow and the red leds are ON(AND NOT the green ones)!!!
Any help will be appreciated! Thank you…

Does the serial output correctly print the distance?

Yes and that is what confuses me morea!!!!!!!Any idea of what is wrong? Thanks

It's a wiring/understanding issue: the way you have it wired, digitalWrite(Pin,LOW); turns the led in question on. You just need to swap HIGH for LOW and vice versa to get the behaviour you're looking for.

Good call wildbill.

orestman, apparently you are using current sinking (+5VDC -> LED -> Arduino) rather than current sourcing (Ardiono -> LED -> Ground). You can rewire or just change the logic in software.

If you want to do it in software, at the top of your program do

#define ON LOW
#define OFF HIGH

and then just digitalWrite(ledpin, ON) or digitalwrite(ledpin, OFF) to makes things easy to read.

Thank you very much both of you!!!!The problem after all was at the software.I ad connected the leds not to ground but to 5volts from the arduino(with a wire to the breadboard), so you where right!!! Anyway thanks a lot again XD