Introduction: Arduino LED Blink, Fade and Traffic Lights for Beginners

About: Hi, I'm an electronics and Arduino amateur, I try to share with you my experience and little projects, hope you like it. visit my youtube channel for more projects goo.gl/KSZVRG

Hi Everyone, Just started this, sorry for the low quality video, in this instructables I showed how to blink, fade a simple LED, then I did a traffic lights project.

Hope you enjoy it, any suggestions or advice is welcome, Thanks

Step 1: Prepare Your Equipement

You'll need:

1-Arduino Uno

2- 6xLEDs (2 reds, 2 oranges and 2 greens)

3-Jump wires

4-breadboard

6- 6x1kohm Resistors

Step 2: Simple Blink

The schematic is in the picture

Here's the code

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

//Simple LED blinking program
//SurtrTech Youtube Channel
const int L1 = 2; //Declaring LED pin
void setup()
{
pinMode(L1, OUTPUT); //Setting pin mode
}
void loop() 
{
digitalWrite(L1, HIGH); //Turn on led
delay(1000); // On time in miliseconds
digitalWrite(L1, LOW); //Turn off led
delay(1000); //Off time 
}

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

Step 3: LED Fading

In this part you can use the same components but you have to change the pin to an pwm pin.

I used the pin number 3 from the pwm output of the arduino

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

//Simple LED blinking program
//SurtrTech Youtube Channel
const int L1 = 3;  // Led pin (must use a pwm output)  
void setup() {
  
  pinMode(L1,OUTPUT);
}
void loop() {
   
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // A loop that goes from 0 to 255 which is 0V to 5V in an pwm output (3)
   
analogWrite(L1, fadeValue); // The led receive the value from 0 to 255
  
 delay(100); //Time in miliseconds
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // Same loop but from highest value to lowest value
  analogWrite(L1, fadeValue); // The led receive the value from 255 to 0
   
delay(100);
  }
}

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

Step 4: Traffic Lights

You'll need 6 LEDs (2 Reds,2 Oranges and 2 Greens)

You separate them in 2 groups (Red1, Orange1 and Green1) then (Red2, Orange2 and Green2)

You connect them like before using this setup:

Pin 2 Red1
Pin 3 Orange1
Pin 4 Green1
Pin 5 Red2
Pin 6 Orange2
Pin 7 Green2

This is the code

//Traffic lights using 6 LEDs
//SurtrTech Youtube Channel //Modified by LEBOUIHA const int L1 = 2; // Declaring 6 LEDs output 2,3 and for are for the light1 and
const int L2 = 3; // 5,6 and 7 are for the light 2
const int L3 = 4;
const int L4 = 5;
const int L5 = 6;
const int L6 = 7;
void setup()
{
pinMode(L1, OUTPUT);  //Red 1
pinMode(L2, OUTPUT);  //Orange 1
pinMode(L3, OUTPUT);  //Green 1
pinMode(L4, OUTPUT);  //Red 2
pinMode(L5, OUTPUT);  //Orange 2
pinMode(L6, OUTPUT);  //Green 2
}
void loop() 
{
digitalWrite(L1, HIGH); // You chose which two you want to turn on as you like, and you must turn off the others
digitalWrite(L6, HIGH); // And you repeat
digitalWrite(L2, LOW); 
digitalWrite(L5, LOW); 
digitalWrite(L3, LOW);  
digitalWrite(L4, LOW); 
delay(4000); // Time in miliseconds
digitalWrite(L1, HIGH); 
digitalWrite(L6, LOW);  
digitalWrite(L2, LOW); 
digitalWrite(L5, HIGH); 
digitalWrite(L3, LOW);  
digitalWrite(L4, LOW); 
delay(2000);
 digitalWrite(L1, HIGH); 
digitalWrite(L6, LOW);  
digitalWrite(L2, LOW); 
digitalWrite(L5, LOW); 
digitalWrite(L3, LOW);  
digitalWrite(L4, HIGH); 
delay(1000);
digitalWrite(L1, LOW); 
digitalWrite(L6, LOW);  
digitalWrite(L2, LOW); 
digitalWrite(L5, LOW); 
digitalWrite(L3, HIGH);  
digitalWrite(L4, HIGH); 
delay(4000);
digitalWrite(L1, LOW); 
digitalWrite(L6, LOW);  
digitalWrite(L2, HIGH); 
digitalWrite(L5, LOW); 
digitalWrite(L3, LOW);  
digitalWrite(L4, HIGH); 
delay(2000);
digitalWrite(L1, HIGH); 
digitalWrite(L6, LOW);  
digitalWrite(L2, LOW); 
digitalWrite(L5, LOW); 
digitalWrite(L3, LOW);  
digitalWrite(L4, HIGH); 
delay(1000);
}