Today I am presenting the complete project solution on blinking multiple LEDs in almost all possible ways with number of different decorative effects. In my view, this code will give give you the ease of selecting any particular decorative effect or ranodom effects as per your own choice. So let us start with the project, first by listing the required parts.
Table of Contents
Required Material
- Red LEDs (or any mixed color LEDs) – 8 nos.
- Breadboard – 1 no.
- Arduino Uno or Arduino Nano – 1 no. (the code given is same for both, don’t worrry about it).
- 1k resistors – 8 nos.
- Connecting wires, etc.
Connection Details
I am connecting the 8 LEDs to 8 pins of Arduino Uno or Arduino Nano as follows:
- LED-1 to pin-2
- LED-2 to pin-3
- …
- LED-8 to pin-9
The connections of all these LEDs are as such that their cathodes are returned to ground. The anode of each LED is connected in series with 1k resistor each and then connected to above pins in sequence.
Note: Since I started the LED connections with pin-2, you can either use Arduino Uno or Nano, without any conflicts of pin connections.
Section of Code with Explanation
First I am using an array for 8 LEDs, as follows:
int i; // a variable which will be used to assign the 8 LEDs in sequence inside the array in void setup() function, below.
int LEDPins[]={2,3,4,5,6,7,8,9};
This part of the code assigns all the 8 LEDs to respective pins as explained above.
Now using void setup() we are initialising the respective sequence of these LEDs into Arduino, as follows:
void setup()
{
for(i=0;i<8;i++)
{
pinMode(LEDPins[i],OUTPUT);
}
}The above code will actually assign all the 8 LEDs into the array as the “for” loop progresses from 0 to 7 for the variable “i”.