user25583: my project involves:
1 ultrasonic sensor. 
1 servo motor.
3 leds.
when a person comes in range of ultrasonic sensor (7 to 20),servo turns by 150 degree.
then ultrasonic sensor check again if the person is in range, if yes then led1 turns on for 10sec n turns off, still if the person in in range then led2 turns on for 10sec and turns off, still if the person is in range then led3 turns on for 10sec and this keep on repeating for the leds(led1, led2, led3 but servo is still in 150) 
once detected and the person is not detected the leds should not glow and servo should return to 0 
code:
if ((distance1>7)&&(distance1 <= 20))
 {
  myservo1.write(150);
  delay(1000);
 }
 {
  if ((distance2>7)&&(distance2 <= 20))
   {
   digitalWrite(led1,HIGH); 
   delay(1000); 
   digitalWrite(led1,LOW);
   }
  if ((distance1>7)&&(distance1 <= 20))
   {
   digitalWrite(led2,HIGH); 
   delay(1000); 
   digitalWrite(led2,LOW);
   }
   if ((distance1>7)&&(distance1 <= 20))
   {
   digitalWrite(led3,HIGH); 
   delay(1000); 
   digitalWrite(led3,LOW);
   }
else
{
 myservo1.write(0);
  }

but this code does not work the way i want.
it blink the leds even when there is no person in range.
need help in programing so that the leds blink only when ultrasonic detects the person in range and stops when person is not detected.
thank u in advance

user22924: Your indenting doesn't match your code.
Right after the very first if (without an else), you have a new open brace ({). This looks wrong:
if ((distance1>7)&&(distance1 <= 20))
 {
  myservo1.write(150);
  delay(1000);
 }
 { // <<<< What is this?

The very very final else matches the very very final if - certainly not the first if!
Also, what is the difference between distance1 and distance2? You only have one ultrasonic sensor - there is only one distance!
EDIT:
I think what you need to do is use loop() more effectively. At the moment, you're pausing in the middle of your code, rather than letting the rest of the code work and using millis(). That function returns the number of milliseconds since the program started - which you can use for your problem (with a little mathematics):
EDIT 2:
I've added a little extra code to play different tunes depending on the current state. It uses the library at http://www.rhydolabz.com/other-widgets-c-205_124/mini-mp3-player-module-p-2159.html
static unsigned lastMilli = 0;
static byte lastLED = 0;
static const byte LEDs[] = { led1, led2, led3 };

distance1 = // Whatever you call to get the distance...
if (distance1>7) && (distance1<=20)) { // Too close?
   if (lastMilli==0) {       // Is this new???
       lastMilli = millis(); // Yes! Record that...
       mysero.write(150);    // ...and set servo.
   } // if
   unsigned delay = millis() - lastMilli; // Get how long it's been
   byte which = delay / 10000 % 3;        // Which LED / tune?
   byte LED = LEDs[which];                // Which LED?
   if (LED != lastLED) {                  // Has LED changed?
       if (lastLED!=0) {
           digitalWrite(lastLED, LOW);    // Yes! Stop that one
       } // if
       mp3_single_loop(true);             // Play forever!
       mp3_single_play(which+1);          // Play "mp3/000#.mp3"
       lastLED = LED;
       digitalWrite(LED, HIGH);           // And start the new one
   } // if
} // if
else if (lastMillis!=0) { // They're gone!
    digitalWrite(lastLED, LOW); // No LED
    myservo.write(0);           // No servo
    lastMilli = 0;              // So start again
    lastLED = 0;
    mp3_stop();
} // else


25583: <p>my project involves:
1 ultrasonic sensor. 
1 servo motor.
3 leds.
when a person comes in range of ultrasonic sensor (7 to 20),servo turns by 150 degree.
then ultrasonic sensor check again if the person is in range, if yes then led1 turns on for 10sec n turns off, still if the person in in range then led2 turns on for 10sec and turns off, still if the person is in range then led3 turns on for 10sec and this keep on repeating for the leds(led1, led2, led3 but servo is still in 150) 
once detected and the person is not detected the leds should not glow and servo should return to 0 </p>

<p>code:</p>

<pre><code>if ((distance1&gt;7)&amp;&amp;(distance1 &lt;= 20))
 {
  myservo1.write(150);
  delay(1000);
 }
 {
  if ((distance2&gt;7)&amp;&amp;(distance2 &lt;= 20))
   {
   digitalWrite(led1,HIGH); 
   delay(1000); 
   digitalWrite(led1,LOW);
   }
  if ((distance1&gt;7)&amp;&amp;(distance1 &lt;= 20))
   {
   digitalWrite(led2,HIGH); 
   delay(1000); 
   digitalWrite(led2,LOW);
   }
   if ((distance1&gt;7)&amp;&amp;(distance1 &lt;= 20))
   {
   digitalWrite(led3,HIGH); 
   delay(1000); 
   digitalWrite(led3,LOW);
   }
else
{
 myservo1.write(0);
  }
</code></pre>

<p>but this code does not work the way i want.
it blink the leds even when there is no person in range.
need help in programing so that the leds blink only when ultrasonic detects the person in range and stops when person is not detected.
thank u in advance</p>
 22924: <p>Your indenting doesn't match your code.</p>

<p>Right after the very first <code>if</code> (without an <code>else</code>), you have a new open brace (<code>{</code>). This looks wrong:</p>

<pre><code>if ((distance1&gt;7)&amp;&amp;(distance1 &lt;= 20))
 {
  myservo1.write(150);
  delay(1000);
 }
 { // &lt;&lt;&lt;&lt; What is this?
</code></pre>

<p>The very very final <code>else</code> matches the very very final <code>if</code> - certainly not the first <code>if</code>!</p>

<p>Also, what is the difference between <code>distance1</code> and <code>distance2</code>? You only have one ultrasonic sensor - there is only one <code>distance</code>!</p>

<h3>EDIT:</h3>

<p>I think what you need to do is use <code>loop()</code> more effectively. At the moment, you're pausing in the middle of your code, rather than letting the rest of the code work and using <code>millis()</code>. That function returns the number of milliseconds since the program started - which you can use for your problem (with a little mathematics):</p>

<h3>EDIT 2:</h3>

<p>I've added a little extra code to play different tunes depending on the current state. It uses the library at <a href="http://www.rhydolabz.com/other-widgets-c-205_124/mini-mp3-player-module-p-2159.html" rel="nofollow">http://www.rhydolabz.com/other-widgets-c-205_124/mini-mp3-player-module-p-2159.html</a></p>

<pre><code>static unsigned lastMilli = 0;
static byte lastLED = 0;
static const byte LEDs[] = { led1, led2, led3 };

distance1 = // Whatever you call to get the distance...
if (distance1&gt;7) &amp;&amp; (distance1&lt;=20)) { // Too close?
   if (lastMilli==0) {       // Is this new???
       lastMilli = millis(); // Yes! Record that...
       mysero.write(150);    // ...and set servo.
   } // if
   unsigned delay = millis() - lastMilli; // Get how long it's been
   byte which = delay / 10000 % 3;        // Which LED / tune?
   byte LED = LEDs[which];                // Which LED?
   if (LED != lastLED) {                  // Has LED changed?
       if (lastLED!=0) {
           digitalWrite(lastLED, LOW);    // Yes! Stop that one
       } // if
       mp3_single_loop(true);             // Play forever!
       mp3_single_play(which+1);          // Play "mp3/000#.mp3"
       lastLED = LED;
       digitalWrite(LED, HIGH);           // And start the new one
   } // if
} // if
else if (lastMillis!=0) { // They're gone!
    digitalWrite(lastLED, LOW); // No LED
    myservo.write(0);           // No servo
    lastMilli = 0;              // So start again
    lastLED = 0;
    mp3_stop();
} // else
</code></pre>
