How do I start?
The first thing to do is to take a look at our photos above to see how the circuit is constructed, and then have a go building it yourself! Hint: Use the circuit diagram when building it, it’s there for a reason.
The positive led of the Green LED is connected to Pin 13 via a current limiting resistor and the negative led of the Green LED is connected to the Ground Pin via a jumper wire.
This is the same for the Amber and Red LEDs. You can see how they share the same ground connection, this is perfectly fine to do and is encouraged to reduce wiring.
A quick summary of the circuit can be seen below:
Pin 11 > Resistor > Red LED > Ground Rail
Pin 11 > Resistor > Amber LED > Ground Rail
Pin 11 > Resistor > Green LED > Ground Rail
Ground Rail on Breadboard > Jumper Wire > Ground Pin
Let’s run through what the code is doing
We initialise the Pins that the LEDs are connected to. Eg. ‘int led1 = 13;’
Inside the Setup function we use the pinMode function to set our Pins to which the LEDs are connected to be Outputs. Then inside the main loop function we are using the digitalWrite function to write each LED either HIGH or LOW. Essentially turning them ON or OFF.
Also utilising the delay function to pause the program and keep the current state of the program/circuit static for a specific amount of time.
Check out the information given on Arduino documentation to learn more.
Now open the Arduino IDE and copy the code below
If you don’t know how to do this, check out our Arduino Sketch set up tutorials and youtube videos.
// This simple program uses the void loop() to run a sequence of LEDs using delays and the HIGH/LOW variables
int led1 = 13; // Red
int led2 = 12; // Yellow
int led3 = 11; // Green
void setup() {
// Setting all LEDs as OUTPUTs
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
}
void loop() {
// Turning pins HIGH for a specified time and then LOW until the loop restarts
digitalWrite(led1,HIGH);
delay(3000);
digitalWrite(led1,LOW);
delay(1000);
digitalWrite(led2,HIGH);
delay(3000);
digitalWrite(led2,LOW);
delay(1000);
digitalWrite(led3,HIGH);
delay(3000);
digitalWrite(led3,LOW);
delay(1000);
}
/*
This code can be edited to include more LEDs running in different sequences.
This is a simple 'traffic light' sequence.
*/
/*
created 02/2020
by Jamie Buick
graycode.ie
*/