arduino

Glow LED using Arduino

Arduino microcontroller is a very popular open source project which can be used to make prototype for electronics, robotics and IoT projects.

In this post, I will explain how to on and off LEDs, when varying LEDs and time.

See the program and circuit

arduino


void setup()
{
pinMode(13,OUTPUT);

}
void loop()
{
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13,LOW);
delay(5000);
}


Here setup() function of Arduino runs only once, and used for pin configuration and setting data, and signal rate of serial communication between computer and  Arduino. .

loop() function runs forever until you stop, you will put the main task inside loop function.



First  prototype

In setup() function,  pinMode(13, OUTPUT) sets the pin no. 13 for OUTPUT.

In loop() function, main instructions are written in which

digitalWrite(13, HIGH); statement causes to glow LED at pin 13.

delay(5000); statement used after digitalWrite(13, HIGH);  to glow LED for 5 seconds.

digitalWrite(13, LOW); statement causes to not glow LED at pin 13.

delay(5000); statement used after digitalWrite(13, LOW);  to not glow LED for 5 seconds.

See the video for whole explanation


Second Prototype

Now see another prototype in which in which red  LED will be on for 5 seconds and that time green LED is off.

Arduino


void setup()

{

pinMode(13,OUTPUT);

pinMode(5, OUTPUT);

}

void loop() {

digitalWrite(13, HIGH);

digitalWrite(5, LOW);

delay(5000);

digitalWrite(13,LOW);

digitalWrite(5, LOW);

delay(5000);

}

 

See the code explanation

In setup() function,  pinMode(13, OUTPUT) and pinMode(5, OUTPUT)  sets the pin no. 13 and 5 for OUTPUT.

In loop() function, main instructions are written in which

digitalWrite(13, HIGH); statement causes to glow LED at pin 13

and

digitalWrite(5, LOW); statement causes to not glow LED at pin 5.

delay(5000); statements used after digitalWrite(13, HIGH); and digitalWrite(5, LOW);  to glow  red LED for 5 seconds and to not glow LED at pin no. 5 for 5 seconds.

digitalWrite(13, LOW); and digitalWrite(5, HIGH); statements causes to not glow LED at pin 13 and glow green LED at pin no. 5 .

delay(5000); statement used after digitalWrite(13, LOW); digitalWrite(5, HIGH);  to not glow  red LED   for 5 seconds and to glow green LED for 5 seconds.

See the video for detailed explaination.


See also

  1. Servo Motor with Arduino (20.8)
  2. Display Three Names at Delay of 10 Seconds using Arduino and LCD (29.8)
  3. Calculate Distance using Ultrasonic Sensor and Arduino Uno Microcontroller (36.6)
  4. Glowing an LED using Arduino Microcontroller (55)
  5. Glow Two-LED Alternatively Using Arduino (56.3)
  6. Glow an LED using Arduino Code Explanation Line by Line (57.8)

Leave a Comment

Your email address will not be published. Required fields are marked *

©Postnetwork-All rights reserved.