Skip to content

Manual and Automatic Traffic Lights

Automatic-Traffic-Lights-configurationFinally, the automation!
After programmed Arduino, your only job is to give power supply to it.
Just last change to wires; configure as in picture.
As you can see we have no power from Arduino neither the analog input; we don't need them anymore.
Ground instead is necessary - always - but we use the one on digital pins; don't worry, there's no difference; ground is same everywhere (here the yellow wire).
Only code misses, and it' very simple (remember to unwire arduino before connect it to pc).

const int OutPin8 = 8; // Red
const int OutPin12 = 12; // Yellow
const int OutPin13 = 13; // Green

void setup() {
  pinMode(OutPin8, OUTPUT);
  pinMode(OutPin12, OUTPUT);
  pinMode(OutPin13, OUTPUT);
}

void loop() {
  digitalWrite(OutPin8, HIGH);
  digitalWrite(OutPin12, LOW);
  digitalWrite(OutPin13, LOW);
  delay(4500);

  digitalWrite(OutPin8, LOW);
  digitalWrite(OutPin12, LOW);
  digitalWrite(OutPin13, HIGH);
  delay(6000);

  digitalWrite(OutPin8, LOW);
  digitalWrite(OutPin12, HIGH);
  digitalWrite(OutPin13, LOW);
  delay(1500);
}

 

By code, sequence giver Red, Green, Yellow, Red, ... Watch below.

Finished! Well done!