Traffic Lights questions

Okay, so, I have done some research, and I just want to be sure this will work.
I want to make a program that will simulate traffic lights, using LED's and Arduino ofc. (It's all connected to a breadboard)
I ordered Arduinio Mega 2560. (Don't ask me why so big)
So, I have a couple of questions.
Number one, will the program that i wrote work?
The program:

int RED = 13;
int YELLOW = 12;
int GREEN = 11;
int DELAY_RED = 5000;
int DELAY_YELLOW = 2000;
int DELAY_GREEN = 5000;

void setup(){
  pinMode(RED,OUTPUT);
  pinMode(YELLOW,OUTPUT);
  pinMode(GREEN,OUTPUT);
}

void loop()
{
  digitalWrite(RED, HIGH);
  digitalWrite(YELLOW, LOW);
  digitalWrite(GREEN, LOW);

  delay(DELAY_RED);

  digitalWrite(RED, HIGH);
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);

  delay(DELAY_YELLOW);

  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  digitalWrite(GREEN, HIGH);

  delay(DELAY_GREEN);

  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);

  delay(DELAY_YELLOW);
}

The red and green lights are supposed to light 5 seconds, and the yellow 2 seconds.

Question 2- Resistors?
So, after some researching, I figured out I needed 330 Ohm resistors (330 Ohm > 5V / 0,02 A, correct me if I'm wrong), but where do I put them? Do I put them in between the Digital Pins on the Arduino and the LED's, or in between the constant power supply and the LED's? Or it's the same outcome?
I'm more into Informatics than this...
This is of great importance to me, and I really need the help.

Homework time is it? I must admit you seem to have done more research than the usual.

Try the search box in the top right hand corner - this question comes up quite frequently.

after some researching, I figured out I needed 330 Ohm resistors (330 Ohm > 5V / 0,02 A, correct me if I’m wrong), but where do I put them? Do I put them in between the Digital Pins on the Arduino and the LED’s, or in between the constant power supply and the LED’s? Or it’s the same outcome?

Need a schematic and LED specification.
This is of great importance.

AWOL:

after some researching, I figured out I needed 330 Ohm resistors (330 Ohm > 5V / 0,02 A, correct me if I’m wrong), but where do I put them? Do I put them in between the Digital Pins on the Arduino and the LED’s, or in between the constant power supply and the LED’s? Or it’s the same outcome?

Need a schematic and LED specification.
This is of great importance.

LED size - 5 mm
I have the resistor stated here (in the pic) , but I still wanna be sure.
In another traffic light build I saw some resistors placed between the power supply… Not as stated here.
Idk does it really matter where they are.

dannable:
Homework time is it? I must admit you seem to have done more research than the usual.

Try the search box in the top right hand corner - this question comes up quite frequently.

I’ve got an informatics competition in a few weeks, so, yeah, I guess homework :smiley:
I’ve searched, but I found nothing alike my problem.

nakica:

AWOL:

after some researching, I figured out I needed 330 Ohm resistors (330 Ohm > 5V / 0,02 A, correct me if I'm wrong), but where do I put them? Do I put them in between the Digital Pins on the Arduino and the LED's, or in between the constant power supply and the LED's? Or it's the same outcome?

Need a schematic and LED specification.
This is of great importance.

LED size - 5 mm
I have the resistor stated here (in the pic) , but I still wanna be sure.
In another traffic light build I saw some resistors placed between the power supply... Not as stated here.
Idk does it really matter where they are.

Depends on how your creating your circuit, but in a case like this its just a resistor and LED in series so it doesn't really matter either way. If you had some other details of the LED like voltage, or current you could probably specify the resistor a lot better. Or else if you're lazy you could always use something like this http://led.linear1.org/1led.wiz most likely case is its probably going to be just like in your picture though, in fact I used the exact same resistor yesterday for an LED :).

Also I think your code is fine? I'm not too sure what you're doing though since you seem to have two LEDs on? This is what I understand, although truth be told I haven't slept in 48 hours so I'm a lil out of it.
Basically your pseudo like code does

  1. Red on for 5 seconds
  2. Red on AND Yellow on for 2 seconds
  3. Red and Yellow now off and Green on for 5 seconds
  4. Green off and only Yellow on for 2 seconds
  5. goto 1

trustnoone:
Also I think your code is fine? I'm not too sure what you're doing though since you seem to have two LEDs on? This is what I understand, although truth be told I haven't slept in 48 hours so I'm a lil out of it.
Basically your pseudo like code does

  1. Red on for 5 seconds
  2. Red on AND Yellow on for 2 seconds
  3. Red and Yellow now off and Green on for 5 seconds
  4. Green off and only Yellow on for 2 seconds
  5. goto 1

That is the correct sequence for UK traffic lights, although the timings are usually longer. 5 seconds on green will only let two cars through, at most! :roll_eyes:

Henry_Best:

trustnoone:
Also I think your code is fine? I'm not too sure what you're doing though since you seem to have two LEDs on? This is what I understand, although truth be told I haven't slept in 48 hours so I'm a lil out of it.
Basically your pseudo like code does

  1. Red on for 5 seconds
  2. Red on AND Yellow on for 2 seconds
  3. Red and Yellow now off and Green on for 5 seconds
  4. Green off and only Yellow on for 2 seconds
  5. goto 1

That is the correct sequence for UK traffic lights, although the timings are usually longer. 5 seconds on green will only let two cars through, at most! :roll_eyes:

It's just an example. I'll change the timing :smiley:

When I wrote "specification", I was thinking more electrical, rather than mechanical.

Henry_Best:

trustnoone:
Also I think your code is fine? I'm not too sure what you're doing though since you seem to have two LEDs on? This is what I understand, although truth be told I haven't slept in 48 hours so I'm a lil out of it.
Basically your pseudo like code does

  1. Red on for 5 seconds
  2. Red on AND Yellow on for 2 seconds
  3. Red and Yellow now off and Green on for 5 seconds
  4. Green off and only Yellow on for 2 seconds
  5. goto 1

That is the correct sequence for UK traffic lights, although the timings are usually longer. 5 seconds on green will only let two cars through, at most! :roll_eyes:

Oh serious? I never knew that, I'm actually quite surprised it differs so much to Aus and I'm also guessing the US. I guess it lets people know its about to turn green though, lucky I've never drove in the UK lol.