Introduction: How to Make a Traffic Light Blink With Arduino

first get familiar with your parts.

led

breadboard

Arduino

male wires

resistors( if u get the wrong one the lights won't work)

Step 1: Setup

Step 2: Making a Variable


int redled= 13; // declares that the name redled is the same as 13

int yellowled= 12; // declares that the name yellowled is the same as 12

int greenled= 11; // declares that the name greenled is the same as 11

Step 3: Setup

void setup(){

pinMode(greenled,OUTPUT); // declares the green led as an output

pinMode(yellowled, OUTPUT); // declares the yellow led as an output

pinMode(redled, OUTPUT);// declares the red led as an output

}

Step 4: The Loop

void loop(){ // keeps the code on until it is stopped by a person

digitalWrite(greenled, HIGH); // turns on the green light

delay(3000);// sets how long the green light would stay

digitalWrite(greenled, LOW); // turns the green light off

digitalWrite(yellowled,HIGH);// turns yellow light on

delay(3000); // sets how long the yellow light will stay on

digitalWrite(yellowled,LOW);// turns yellow light off

digitalWrite(redled,HIGH);// turns red light on

delay(3000);// sets how long the red light will stay on

digitalWrite(redled,LOW);// shuts off the red light

} // the end of the code

Step 5: What Should Happen