Led blink without delay please help

led dont blink respectively , somewhere is the wrong please help me

unsigned long t0 = 0;
unsigned long t = 0;

unsigned long t1 = 1000;
unsigned long tt = 1000;

unsigned long t2 = 2000;
unsigned long ttt = 2000;

unsigned long t3 = 3000;
unsigned long tttt =3000;

unsigned long t4 = 4000;
unsigned long ttttt = 4000;

const long dt = 1000;
const long dtt = 2000;
const long dttt = 3000;
const long dtttt = 4000;
const long dttttt = 5000;

void setup() {

Serial.begin(9600);
pinMode(2, OUTPUT);//
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A0, OUTPUT);
}

void loop(){

t = millis();
if(t - t0 >= dt) {
t0 = t;
digitalWrite(8, LOW);//1.Green Led
digitalWrite(A0, HIGH);//1.Red Led
digitalWrite(2, HIGH);//2.Green Led
digitalWrite(3,LOW);//2.Red Led
digitalWrite(4, LOW);//3.Green Led
digitalWrite(5, HIGH);//3.Red Led
digitalWrite(6, LOW);//4.Green Led
digitalWrite(7, HIGH);//4.Red Led

}
tt=millis();
if(tt - t1>= dtt){
t1 = tt;

digitalWrite(A0, HIGH);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);

}
ttt=millis();
if(ttt - t2>=dttt){
t2=ttt;

digitalWrite(A0, HIGH);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
tttt=millis();
if(tttt - t3>=dtttt){
t3=tttt;

digitalWrite(A0, LOW);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}

}

When every ambulance passes, I want the lights to turn red and only one direction turns green.

but somewhere is wrong

So what does happen ?

UKHeliBob:
So what does happen ?

When Rfid is read, it is not smooth, I want to suddenly turn green ambulance while there is green light in another direction(turn the red another direction) in emergency transitions and then traffic lights goes are normally with in the codes

If you want the code to be respond quickly to any kind of input you need to get rid of the delay()s and use millis() for timing instead.

Read Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

UKHeliBob:
If you want the code to be respond quickly to any kind of input you need to get rid of the delay()s and use millis() for timing instead.

Read Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

i dont get it , i tried but i cannot write code with millis function can u help me

i tried but i cannot write code with millis function

What did you try ?

It is likely that you will need to restructure your program in order to do what you want. This program controls traffic lights which will be in one of a number of states where different combinations of LEDs are on or off.

Start by writing down which LEDs are on during each state and for how long. To help understanding I suggest that you give the LEDs names such as North red, North amber, North green etc. With that information we can move forward to using millis() for the timing. Don't worry about the RFID stuff until you have got the traffic lights working using millis()

editing

I see that you decided not to write down the LED states as I suggested, nor to give the LED pins names to help understanding the program. You seem to have tried

#define LED_PIN 2
#define LED_PIN 3
#define LED_PIN 4
#define LED_PIN 5
#define LED_PIN 6
#define LED_PIN 7
#define LED_PIN 8
#define LED_PIN A0

but how many pins do you want to give the same name to ?

Then you don't even attempt to use the pin names

    digitalWrite(A0, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
etc

Please give all your variables sensible names rather than ls0, ls1, ls2 etc. It is probable that your program will use arrays given the numeric suffixes but I have no idea what those variables are supposed to do. If you give them sensible names then the logic of the program will be easier to understand. For instance, see how easy

if (currentTime - startTime >= period)

is to read and understand ?

You really are going to have to restructure your program in order to use millis() for timing.

Please do us and yourself a favour and Auto Format your code in the IDE before posting it and use code tags when you do to make it easier to copy to an editor. See read this before posting a programming question

Hi i want to using millis function but led not working with properly led blinking randomly i dont get it why

if u have any suggestions please write me i dont get it why

unsigned long t0 = 0;
unsigned long t = 0;

unsigned long t1 = 1000;
unsigned long tt = 1000;

unsigned long t2 = 2000;
unsigned long ttt = 2000;

unsigned long t3 = 3000;
unsigned long tttt =3000;

unsigned long t4 = 4000;
unsigned long ttttt = 4000;

const long dt = 1000;
const long dtt = 2000;
const long dttt = 3000;
const long dtttt = 4000;
const long dttttt = 5000;

void setup() {

Serial.begin(9600);
pinMode(2, OUTPUT);//
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A0, OUTPUT);
}

void loop(){

t = millis();
if(t - t0 >= dt) {
t0 = t;
digitalWrite(8, LOW);//1.Green Led
digitalWrite(A0, HIGH);//1.Red Led
digitalWrite(2, HIGH);//2.Green Led
digitalWrite(3,LOW);//2.Red Led
digitalWrite(4, LOW);//3.Green Led
digitalWrite(5, HIGH);//3.Red Led
digitalWrite(6, LOW);//4.Green Led
digitalWrite(7, HIGH);//4.Red Led

}
tt=millis();
if(tt - t1>= dtt){
t1 = tt;

digitalWrite(A0, HIGH);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);

}
ttt=millis();
if(ttt - t2>=dttt){
t2=ttt;

digitalWrite(A0, HIGH);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
tttt=millis();
if(tttt - t3>=dtttt){
t3=tttt;

digitalWrite(A0, LOW);
digitalWrite(2, LOW);
digitalWrite(3,HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}

}

Where is rfid1() definded.

Use CTRL T to format your code.

Use code tags when showing your code.

larryd:
Where is rfid1() definded.

Use CTRL T to format your code.

Use code tags when showing your code.

rfid1 not important thing i deleted and i tried ctrl t but chrome not useful for this combination

so do u have any idea for this code

I uploaded this to an UNO, LEDs flash randomly i.e. as per code, what's not working for you?

CTRL T is done in the IDE.

larryd:
I uploaded this to an UNO, LEDs flash randomly, what's not working for you?

CTRL T is done in the IDE.

i'll send a video that's traffic light as u can see for decleration with leds , not flashing respectively

You need to tell us what this is supposed to do.

Commenting your lines of code lets us see what is supposed to happen.

Use variables that give a clue as what they are for, single letter variables are just crap.

My guess is a 'State Machine' is what is needed here.

larryd:
You need to tell us what this is supposed to do.

Commenting your lines of code lets us see what is supposed to happen.

Use variables that give a clue as what they are for, single letter variables are just crap.

My guess is a 'State Machine' is what is needed here.

here is the video link

You need to tell us what this is supposed to do.

Commenting your lines of code lets us see what is supposed to happen.

Use variables that give a clue as what they are for, single letter variables are just crap.

My guess is a 'State Machine' is what is needed here.

We do not see any series dropping resistors for your LEDs.

If you don't use them, you will damage your UNO!

How are you keeping track of ‘t’s?

HolaMusty:
editing with

HolaMusty:
editing

Stop vandalizing the forum. This is your only warning.

Maybe this will help:

unsigned long lastTime;
const long    wait = 1000;

byte LEDstate = 1;

void setup()
{
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(A0, OUTPUT);

  lastTime = millis();
}

void loop()
{
  switch (LEDstate)
  {
    case 1:
      if (millis() - lastTime >= wait)
      {
        lastTime = millis();
        digitalWrite(A0, HIGH);
        digitalWrite(2, HIGH);
        digitalWrite(3, LOW);
        digitalWrite(4, LOW);
        digitalWrite(5, HIGH);
        digitalWrite(6, LOW);
        digitalWrite(7, HIGH);
        digitalWrite(8, LOW);

        LEDstate = 2;
      }
      break;

    case 2:
      if (millis() - lastTime >= wait)
      {
        lastTime = millis();
        digitalWrite(A0, HIGH);
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
        digitalWrite(7, HIGH);
        digitalWrite(8, LOW);

        LEDstate = 3;
      }
      break;

    case 3:
      if (millis() - lastTime >= wait)
      {
        lastTime = millis();
        digitalWrite(A0, HIGH);
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
        digitalWrite(7, HIGH);
        digitalWrite(8, LOW);

        LEDstate = 4;
      }
      break;

    case 4:
      if (millis() - lastTime >= wait)
      {
        lastTime = millis();
        digitalWrite(A0, HIGH);
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
        digitalWrite(7, HIGH);
        digitalWrite(8, LOW);

        LEDstate = 1;
        break;
      }
  }// END of switch

}