Traffic Lights

Green, yellow and red, the colors used for traffic lights. These lights control traffic and are essential in our modern day lives. It would be a mess without these signals to guide us when and when not to go. They are important for both pedestrians and drivers as they prevent accidents (if followed correctly). The lights pattern should be timed differently depending on the traffic (will be explained in next paragraph).
Timing is key for traffic lights. It is crucial that one side will be going while the other is red, signaling to stop. The yellow light should come before the red light, giving drivers a warning a red light is incoming to prepare them to slow down, or to pass the light depending on their situation. It could be useful if the green lights did not turn on the exact same time the red lights turned on to let incoming drivers slow down, or barely pass the yellow light. This is not a major concern in all cases as cars take time to accelerate, but is still important when cars are already up to speed passing the new green light. Pedestrians should be warned in advance when the light is about to change to yellow. The timers count down to the traffic lights yellow signal. This allows the pedestrian know when it is a good or not a good time to cross. The button for pedestrians does not change the timing of the stop lights, but indicates when the pedestrian should walk when it is a green light. Roads that are less occupied with pedestrians and cars require you to press the button to cross as some stop lights only turn red when they detect a car waiting to go. The timing on the green lights of roads are different depending on how busy the road is. Evidently, the road with more cars will have a longer green light and a shorter red light. We can take Baseline as an example. The green lights on Baseline rd. are almost always longer than the other opposite roads. There are also situations where a left turning left is needed. The yellow light will always be 3 seconds before turning red. This means that only one direction will be green and the other 3 or 2 will be red. This causes that direction to turn green earlier. Different places will have different timing for their stop lights.

Function of my code:

The three light colors are set up on both sides. I call one of the north and the other west. I will specify which light is on, if the light is not mentioned, it is assumed it is turned off. The code starts off with the north green light on;therefore, the red light of west will be also on (for 12 seconds). After those 12 seconds, the north yellow will be on while the west red light is still on, this will happen for 3 seconds. After those 3 seconds, the west green will be on while the north red is on (this same steps as before, but for the opposite direction) for 12 seconds. Just like before, after these 12 seconds, the west yellow will turn on while the north red is still on. After this, all the steps will repeat.

 
int ledGN = 13;
int ledYN = 12;
int ledRN = 11;
int ledGW = 10;
int ledYW = 9;
int ledRW = 8;
void setup() {
  // put your setup code here, to run once:
  pinMode(ledGN, OUTPUT);
  pinMode(ledYN, OUTPUT);
  pinMode(ledRN, OUTPUT);
  pinMode(ledGW, OUTPUT);
  pinMode(ledYW, OUTPUT);
  pinMode(ledRW, OUTPUT);
}
 
 
void loop() {
  // put your main code here, to run repeatedly:
  //north running for 15 seconds total
  digitalWrite (ledYN, LOW); //north yellow off
  digitalWrite (ledRN, LOW); //north red off
  digitalWrite (ledGN, HIGH); //north green on
 
  digitalWrite (ledRW, HIGH); //west red on
  digitalWrite (ledYW, LOW); //west yellow off
  digitalWrite (ledGW, LOW); //west green off
  delay(12000); //north goes for 12 seconds
 
  digitalWrite (ledYN, HIGH); //north yellow on
  digitalWrite (ledRN, LOW); //north red off
  digitalWrite (ledGN, LOW); //north green off
 
  digitalWrite (ledRW, HIGH); //west red on
  digitalWrite (ledYW, LOW); //west yellow off
  digitalWrite (ledGW, LOW); //west green off
  delay(3000); //north yellow on for 3 seconds
 
  //west running for 15 seconds total
  digitalWrite (ledYN, LOW); //north yellow off
  digitalWrite (ledRN, HIGH); //north red on
  digitalWrite (ledGN, LOW); //north green off
   
  digitalWrite (ledRW, LOW); //west red off
  digitalWrite (ledYW, LOW); //west yellow off
  digitalWrite (ledGW, HIGH); //west green om
  delay(12000); //west goes for 12 seconds
 
  digitalWrite (ledYN, LOW); //north yellow off
  digitalWrite (ledRN, HIGH); //north red on
  digitalWrite (ledGN, LOW); //north green off
 
  digitalWrite (ledRW, LOW); //west red off
  digitalWrite (ledYW, HIGH); //west yellow off
  digitalWrite (ledGW, LOW); //west green on
  delay(3000); //west yellow on for 3 seconds
}