Home Top Ad

Responsive Ads Here

LEDS

⌁⌁⌁ ⌁⌁⌁ ⌁⌁⌁⌁⌁ Running LEDs with Arduino ⌁⌁⌁ ⌁⌁⌁ ⌁⌁⌁⌁⌁

ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Important :☝☝☝☝We will depend on our projects on several programs.

Control in one LED :

   For this project, we will need one LED with Jumper wiresResistor 220 ohm Resistor, in addition to the Arduino UNO and the Breadboard.



   


   We create the project as shown in the image:












   
   The negative pole of the LED, we connect it to pin 2 in order to control its operation, and the positive pole connect it to the resistor in order to protect it, then connect the resistance to pin 3.3 of the Arduino.


LED On / Off Code:

//  You can write messages after this tag. This will not constitute a programming error.

;  It is important not to forget this sign after each of the commands for programming the Arduino.

   When you launch a new page from the Arduino interface, this command will appear.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

   The previous code restarts the Arduino from the beginning, it can be used in the event that any problems arise with the Arduino.

1 - void setup :

   This code is the preparation loop and definition of the entrances and exits of the project.

The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup() function will only run once, after each powerup or reset of the Arduino board .

void setup() {
  // put your setup code here, to run once:

}

 2- void loop :

   This is where the bulk of your Arduino diagram comes in. The program starts right after the opening parenthesis (}), runs until it sees the closing parenthesis (}), jumps again to the first line in the loop () and starts over.

   The loop function () will work again and again until the Arduino is reset.

void loop() {
  // put your main code here, to run repeatedly:

}

   We come to our project:
    encode the PIN with the LED, and we give this command:
int led=2;
And after the end of the definition of the LED,We are writing the command :
pinMode(led,OUTPUT);
   write the output command for the LED.

   The command turns on the LED for a period of time:

digitalWrite(led, HIGH);

   The command turns off the LED within a period of time.

digitalWrite(led, LOW);

Duration in milliseconds .

delay(500);

Now we go to the full code for the first project☝☝☝

Full code:

 // 1 ONE led programing witch arduino
int led=2;        // Determine the pin number for the LED
 void setup()
 {
  pinMode(led,OUTPUT);        // Determine LED as output
  }
void loop()
{
digitalWrite(led, HIGH);         // turn the LED on (HIGH is the voltage level)
  delay(500);                            // wait for a secon
  digitalWrite(led, LOW);        // turn the LED off by making the voltage LOW
  delay(500);                            // wait for a secon 
 }   

Control in 5 LED :

   For this project, we will need 5 LED with Jumper wires,5Resistor 220 ohm , in addition to the Arduino UNO and the Breadboard.

Do the same previous installation with the addition of 4 additional LEDs.

After completing the installation, we come to programming again, to identify the LEDs with the existing inputs and output.

 // 2  PROGRAMMING 5leds with arduino

int led1=2;        // Determine the pin number for the LED
int led2=3;
int led3=4;
int led4=5;
int led5=6;
 void setup()
 {
  pinMode(led1,OUTPUT);        // Determine LED as output
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  pinMode(led5,OUTPUT);
   }

   Now the program is divided into 3 cases

Case 1:

Run the leds together in order:

digitalWrite(led1, HIGH);         // turn the LED on (HIGH is the voltage level)
  delay(500); // wait for a secon
  digitalWrite(led2, HIGH);
  delay(500);
    digitalWrite(led3, HIGH);
  delay(500);
  digitalWrite(led4, HIGH);
  delay(500);
  digitalWrite(led5, HIGH);
  delay(500);

Case 2:

Turn off the leds together in order:

  digitalWrite(led1, LOW);        // turn the LED off by making the voltage LOW
  delay(500);                            // wait for a secon
  digitalWrite(led2, LOW);       
  delay(500);
    digitalWrite(led3, LOW);       
  delay(500);
    digitalWrite(led4, LOW);       
  delay(500);
    digitalWrite(led5, LOW);       
  delay(500);

Case 3:

On and off for each led in order:

 digitalWrite(led1, HIGH);         // turn the LED on (HIGH is the voltage level)
  delay(500);
 digitalWrite(led1, LOW);        // turn the LED off by making the voltage LOW
  delay(500);
digitalWrite(led2, HIGH);         
  delay(500);
 digitalWrite(led2, LOW);        
  delay(500);
  digitalWrite(led3, HIGH);         
  delay(500);
 digitalWrite(led3, LOW);        
  delay(500);
digitalWrite(led4, HIGH);         
  delay(500);
 digitalWrite(led4, LOW);        
  delay(500);
digitalWrite(led5, HIGH);         
  delay(500);
 digitalWrite(led5, LOW);        
  delay(500); 


   Now we have finished the explanation about this project and this is the complete code:

Full code:

// 2 PROGRAMMING 5leds with arduino :

int led1=2;        // Determine the pin number for the LED
int led2=3;
int led3=4;
int led4=5;
int led5=6;
 void setup()
 {
  pinMode(led1,OUTPUT);        // Determine LED as output
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  pinMode(led5,OUTPUT);
   }
void loop()
{
//case1
digitalWrite(led1, HIGH);         // turn the LED on (HIGH is the voltage level)
  delay(500); // wait for a secon
  digitalWrite(led2, HIGH);
  delay(500);
    digitalWrite(led3, HIGH);
  delay(500);
  digitalWrite(led4, HIGH);
  delay(500);
  digitalWrite(led5, HIGH);
  delay(500);
//case2
  digitalWrite(led1, LOW);        // turn the LED off by making the voltage LOW
  delay(500);                            // wait for a secon
  digitalWrite(led2, LOW);       
  delay(500);
    digitalWrite(led3, LOW);       
  delay(500);
    digitalWrite(led4, LOW);       
  delay(500);
    digitalWrite(led5, LOW);       
  delay(500);
//case3
digitalWrite(led1, HIGH);         // turn the LED on (HIGH is the voltage level)
  delay(500);
 digitalWrite(led1, LOW);        // turn the LED off by making the voltage LOW
  delay(500);
digitalWrite(led2, HIGH);         
  delay(500);
 digitalWrite(led2, LOW);        
  delay(500);
  digitalWrite(led3, HIGH);         
  delay(500);
 digitalWrite(led3, LOW);        
  delay(500);
digitalWrite(led4, HIGH);         
  delay(500);
 digitalWrite(led4, LOW);        
  delay(500);
digitalWrite(led5, HIGH);         
  delay(500);
 digitalWrite(led5, LOW);        
  delay(500);  
   }

Important :☝☝☝☝We can change the pins and change the times it takes to turn on and off.

   This is the test video :


ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

No comments