Hello!

Welcome to our first tutorial on Arduino board.

In this tutorial we are going to code (sketch) and build a 4 way traffic light circuit using an Arduino microcontroller board.

This will be the result:

For this tutorial we will use the components below:

  • An Arduino board: that will help us decode and execute the sketch (code)
  • A laptop: with what will write our sketch
  • A USB cable: for the uploading the sketch to the Arduino board
  • Wires or jumper wires
  • Soldering iron
  • A project board
  • 12 LEDs where we have 4 Red, 4 Green and 4 Yellow
  • 4 226Ω Resistors

Step 1

First of all we will start by mounting our LEDs and Resistors on the project board.

Step 2

We connect our various LEDs neutral to the resistors and from the resistors to our Arduino board ground.

Step 3

We do our soldering.

Step 4

We are going to write our sketch using our Arduino IDE; if you don’t have an Arduino IDE on your laptop you easily download it on the website arduino.org, after downloading the software you can now install it and start writing sketches.

Here is our traffic light sketch looks like:

//variable declaration
int r1=1;
int y1=2;
int g1=3;
int r2=4;
int y2=5;
int g2=6;
int r3=7;
int y3=8;
int g3=9;
int r4=10;
int y4=11;
int g4=12;

void setup() {
pinMode(r1, OUTPUT);
pinMode(y1, OUTPUT);
pinMode(g1, OUTPUT);

pinMode(r2, OUTPUT);
pinMode(y2, OUTPUT);
pinMode(g2, OUTPUT);

pinMode(r3, OUTPUT);
pinMode(y3, OUTPUT);
pinMode(g3, OUTPUT);

pinMode(r4, OUTPUT);
pinMode(y4, OUTPUT);
pinMode(g4, OUTPUT);

// put your setup code here, to run once:

}

void loop() {
digitalWrite(g1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
delay(9000);
digitalWrite(g1,LOW);
digitalWrite(r2,LOW);

digitalWrite(r2,HIGH);
delay(3000);
digitalWrite(y1,LOW);
digitalWrite(r2,LOW);

digitalWrite(r1,HIGH);
digitalWrite(g2,HIGH);
delay(9000);

digitalWrite(g2,LOW);
digitalWrite(r3,LOW);

digitalWrite(y2,HIGH);
digitalWrite(y3,HIGH);
delay(3000);

digitalWrite(y2,LOW);
digitalWrite(y3,LOW);

digitalWrite(r2,HIGH);
digitalWrite(g3,HIGH);
digitalWrite(r4,HIGH);
delay(9000);

digitalWrite(g3,LOW);
digitalWrite(r4,LOW);
// What will you add here?

digitalWrite(y3,HIGH);
digitalWrite(y4,HIGH);
delay(3000);

digitalWrite(y3,LOW);
digitalWrite(y4,LOW);

digitalWrite(r3,HIGH);
digitalWrite(g4,HIGH);
delay(9000);

digitalWrite(r3,LOW);
digitalWrite(g4,LOW);
digitalWrite(r1,LOW);
digitalWrite(y1,HIGH);
digitalWrite(y4,HIGH);
delay(3000);

digitalWrite(y1,LOW);
digitalWrite(y4,LOW);

// put your main code here, to run repeatedly:
}
Advertisements