Street Lighting System

I have implemented a model for smart street lighting. All things are working fine. Just a small issue i found in my model. I have set a delay of 3 secs for LED's. So what happen is If a vehicle passes through first IR sensor and it glow 2 or 3 lights. When vehicle goes through the next IR sensor, It first waits for 3 seconds to over for IR1 and then glow the lights. Hope you have understood what i want to say? So my question is how i can avoid this issue?

I'm sure you can fix this by making changes to your (unspecified) IR sensors or in your (unposted) code.

Don't use delay(). Use the blink without delay method for timing. Then your code won't block and will be responsive.

See also:
http://forum.arduino.cc/index.php?topic=223286.0
http://forum.arduino.cc/index.php?topic=503368.0

int LED1=13;
int LED2=12;
int LED3=11;
int LED4=10;
int LED5=9;
int LED6=8;
int LED7=7;
int isObstacle1Pin=22;
int isObstacle2Pin=24;
int isObstacle3Pin=26;
int isObstacle4Pin=28;
int isObstacle1=0;
int isObstacle2=0;
int isObstacle3=0;
int isObstacle4=0;
void setup()
{
pinMode(isObstacle1Pin,INPUT_PULLUP);
Serial.begin(9600);
pinMode(isObstacle2Pin,INPUT_PULLUP);
Serial.begin(9600);
pinMode(isObstacle3Pin,INPUT_PULLUP);
Serial.begin(9600);
pinMode(isObstacle4Pin,INPUT_PULLUP);
Serial.begin(9600);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);
pinMode(LED7,OUTPUT);
}

void loop()
{
isObstacle1 = digitalRead(isObstacle1Pin);
isObstacle2 = digitalRead(isObstacle2Pin);
isObstacle3 = digitalRead(isObstacle3Pin);
isObstacle4 = digitalRead(isObstacle4Pin);
unsigned int AnalogValue;
AnalogValue = analogRead(A0);
Serial.print(AnalogValue);
Serial.print('\n');

if(AnalogValue >= 400)
{
digitalWrite(LED1, HIGH);
digitalWrite(LED7, HIGH);
if(isObstacle1 == HIGH)
{
Serial.println("OBASTCLE !! at sensor 1");
digitalWrite(LED2, HIGH);
delay(2000);
}
else
{
Serial.println("sensor 1 clear");
analogWrite(LED2, 10);
}

if(isObstacle2 == HIGH)
{
Serial.println("OBASTCLE !! at sensor 2");
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
delay(2000);
}
else
{
Serial.println("sensor 2 clear");
analogWrite(LED2, 10);
analogWrite(LED3, 10);
}

if(isObstacle3 == HIGH)
{
Serial.println("OBASTCLE !! at sensor 3");
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
delay(2000);
}
else
{
Serial.println("sensor 3 clear");
analogWrite(LED3, 10);
analogWrite(LED4, 10);
}

if(isObstacle4 == HIGH)
{
Serial.println("OBASTCLE !! at sensor 4");
digitalWrite(LED6, HIGH);
delay(2000);
}
else
{
Serial.println("sensor 3 clear");
analogWrite(LED6, 10);
}
}
else
{
Serial.println(" Light in room ");
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
}

}

Why no code tags?

What code tags? Can you explain as i am new here.

http://forum.arduino.cc/index.php/topic,148850.0.html

See #7.

CODE:

int LED1=13;
int LED2=12;
int LED3=11;
int LED4=10;
int LED5=9;
int LED6=8;
int LED7=7;
int isObstacle1Pin=22;
int isObstacle2Pin=24;
int isObstacle3Pin=26;
int isObstacle4Pin=28;
int isObstacle1=0;
int isObstacle2=0;
int isObstacle3=0;
int isObstacle4=0;
void setup()
{
  pinMode(isObstacle1Pin,INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(isObstacle2Pin,INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(isObstacle3Pin,INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(isObstacle4Pin,INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(LED4,OUTPUT);
  pinMode(LED5,OUTPUT);
  pinMode(LED6,OUTPUT);
  pinMode(LED7,OUTPUT);
}

void loop()
{
  isObstacle1 = digitalRead(isObstacle1Pin);
  isObstacle2 = digitalRead(isObstacle2Pin);
  isObstacle3 = digitalRead(isObstacle3Pin);
  isObstacle4 = digitalRead(isObstacle4Pin);
  unsigned int AnalogValue;
  AnalogValue = analogRead(A0);
  Serial.print(AnalogValue);
  Serial.print('\n');

if(AnalogValue >= 400)
{
  digitalWrite(LED1, HIGH);
  digitalWrite(LED7, HIGH);
  if(isObstacle1 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 1");
    digitalWrite(LED2, HIGH);
    delay(2000);
  }
  else
  {
    Serial.println("sensor 1 clear");
    analogWrite(LED2, 10);
  }

  if(isObstacle2 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 2");
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
    delay(2000);
  }
  else
  {
    Serial.println("sensor 2 clear");
    analogWrite(LED2, 10);
    analogWrite(LED3, 10);
  }

    if(isObstacle3 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 3");
    digitalWrite(LED3, HIGH);
    digitalWrite(LED4, HIGH);
    delay(2000);
  }
  else
  {
    Serial.println("sensor 3 clear");
    analogWrite(LED3, 10);
    analogWrite(LED4, 10);
  }

      if(isObstacle4 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 4");
    digitalWrite(LED6, HIGH);
    delay(2000);
  }
  else
  {
    Serial.println("sensor 3 clear");
    analogWrite(LED6, 10);
  }
}
 else
{
    Serial.println(" Light in room ");
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,LOW);
}
 
}

You you can lookup the code. Any modifications on that?

Several delay(2000) calls there. That is a prime candidate for the problems you described. Get rid of those, use millis() based timing instead (see the Blink Without Delay example).

Can you explain me where to use the conditions for mills as i am not getting where to use it

Still i am not getting the correct coding for this. Any more Help ?

I am using 5 IR sensors. When first IR sensor detects the vehicles 2 LED's should be on. When second IR sensor detects the vehicle 2 respective LED's should be on and so on. But i have set a delay for 3 seconds and because of that LED's takes time to glow because of the previous LED's.. I know this is happening because of the delay. As you guys have suggested to use millis(), I tried to do it but was unable to do. Can anyone suggest me where to use milli() and how can i avoid the delay problem. My sketch is given below:

Sketch:

int LED1=13;
int LED2=12;
int LED3=11;
int LED4=10;
int LED5=9;
int LED6=8;
int LED7=7;
int isObstacle1Pin=22;
int isObstacle2Pin=24;
int isObstacle3Pin=26;
int isObstacle4Pin=28;
int isObstacle5Pin=30;
int isObstacle1=0;
int isObstacle2=0;
int isObstacle3=0;
int isObstacle4=0;
int isObstacle5=0;

void setup()
{
  pinMode(isObstacle1Pin,INPUT_PULLUP);
  pinMode(isObstacle2Pin,INPUT_PULLUP);
  pinMode(isObstacle3Pin,INPUT_PULLUP);
  pinMode(isObstacle4Pin,INPUT_PULLUP);
  pinMode(isObstacle5Pin,INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(LED4,OUTPUT);
  pinMode(LED5,OUTPUT);
  pinMode(LED6,OUTPUT);
  pinMode(LED7,OUTPUT);
}

void loop()
{
  isObstacle1 = digitalRead(isObstacle1Pin);
  isObstacle2 = digitalRead(isObstacle2Pin);
  isObstacle3 = digitalRead(isObstacle3Pin);
  isObstacle4 = digitalRead(isObstacle4Pin);
  isObstacle5 = digitalRead(isObstacle5Pin);

  
  Serial.print("Program ON Time: ");
  time = millis();
  Serial.println(time);    //prints time since program started
  delay(1000);            //Correction to be done after delay solving

  Serial.print("Light Intensity: ");
  unsigned int AnalogValue;
  AnalogValue = analogRead(A0);
  Serial.print(AnalogValue);
  Serial.print('\n');

if(AnalogValue >= 400)
{
  digitalWrite(LED1, HIGH);
  digitalWrite(LED7, HIGH);

  if(isObstacle1 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 1");
    digitalWrite(LED2, HIGH);
    delay(3000);
  }
  else
  {
    Serial.println("sensor 1 clear");
    analogWrite(LED2, 10);
  }
}

  if(isObstacle2 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 2");
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
    delay(3000);
  }
  else
  {
    Serial.println("sensor 2 clear");
    analogWrite(LED2, 10);
    analogWrite(LED3, 10);
  }

  if(isObstacle3 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 3");
    digitalWrite(LED3, HIGH);
    digitalWrite(LED4, HIGH);
    delay(3000);
  }
  else
  {
    Serial.println("sensor 3 clear");
    analogWrite(LED3, 10);
    analogWrite(LED4, 10);
  }

   if(isObstacle4 == HIGH)
   {
    Serial.println("OBASTCLE !! at sensor 4");
    digitalWrite(LED6, HIGH);
    delay(3000);
   }
  else
  {
    Serial.println("sensor 4 clear");
    analogWrite(LED6, 10);
  }

   if(isObstacle5 == HIGH)
   {
    Serial.println("OBASTCLE !! at sensor 5");
    digitalWrite(LED5, HIGH);
    digitalWrite(LED6, HIGH);
    delay(3000);
   }
  else
   {
    Serial.println("sensor 5 clear");
    analogWrite(LED5, 10);
    analogWrite(LED6, 10);
   }
}
 else
{
    Serial.println(" Light in room ");
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,LOW);
}
Serial.println("");
}

Study these:

https://forum.arduino.cc/index.php?topic=503368.0

http://forum.arduino.cc/index.php?topic=223286.0

https://forum.arduino.cc/index.php?topic=526696.0

https://forum.arduino.cc/index.php?topic=525240.0

I had a look on all these posts but believe me for a beginner it is very confusing. I am totally confused where should i use what. Can any one have a look on my sketch and correct it for me

  if(isObstacle1 == HIGH)
  {
    Serial.println("OBASTCLE !! at sensor 1");
    digitalWrite(LED2, HIGH);
    delay(3000);
  }

Why do you want to delay for 3 seconds here?

When first IR sensor detects . . ..

Detects what, when, how?

OP started the same project here:

https://forum.arduino.cc/index.php?topic=529182.0

Moderator: merged topics. Please do not crosspost - that is wasting everybodies time including yours.

ashishpandey:
Still i am not getting the correct coding for this. Any more Help ?

Why are you asking for help in another thread?
This not only wastes our time but is very rude!

What is the purpose of each delay() in your sketch?