5 LEDs Program in IoT: Complete Code and Circuit

Q. Write a program to blink 5 LEDs in serial mode with a delay of 2 seconds.

This is the important program in O Level Module 4 — IOT Practical — that blinks 5 LEDs in serial mode, meaning they will all turn on and off together in sequence with a 2-second delay.

Program for Blink 5 LEDs
Variable Declaration
  • These lines define 5 integer variables named⁣ led1 to⁣ led5.
  • Each variable holds the number of the Arduino pin to which a corresponding LED is connected.
  • led1 is connected to digital pin 12.
  • led2 to pin 11, and so on down to led5 on pin 8.
Setup Function
  • The setup()function runs once when the Arduino starts.
  • pinMode(pin, OUTPUT) tells the Arduino to treat the given pin as an output pin—meaning it will send voltage to control things like LEDs.
  • Each of your 5 LED pins is set as an output.
Loop Function
What It Does:

This function runs over and over in a loop forever.

Each LED’s sequence explained:
  • digitalWrite(ledX, HIGH); turns ON the LED connected to that pin.
  • delay(2000); keeps it ON for 2000 milliseconds (2 seconds).
  • digitalWrite(ledX, LOW); turns OFF that LED.
  • Then the next LED in line is turned on in the same way.
CODE
Share your love
Jaz Expert
Jaz Expert
Articles: 12

Leave a Reply

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