Tuesday, June 9, 2015

Arduino Traffic Lights

Hi guys!Today what we are going to do is traffic lights!I thinks its a good example to understant delay command.Of course we will use an arduino board and here is a video of mine.



Here is the parts we need
-Arduino Board
-Breadboard
-3xLed(red/yellow/green)
-3x220 ohm Resistor
-Jumper Wires

Schematic of our circuit(really simple)


And the arduino code
-------------------

const int ledPins[] = {2, 3 ,4};

void setup() {
  pinMode(ledPins[0],OUTPUT);
  pinMode(ledPins[1],OUTPUT);
  pinMode(ledPins[2],OUTPUT);
}

void loop() {
  digitalWrite(ledPins[0],HIGH);
  delay(7000);
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],HIGH);
  delay(2000);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],HIGH);
  delay(5000);
  digitalWrite(ledPins[2],LOW); 
}

-------------------------------------------------------------


If you came here you did well ^-^. Ask me anything in the comment section. See you later in another tutorial. ^-^






No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...