Tutorial #3: More LEDs

More LEDs

LEDs can draw a lot of power, so to add more to your circuit, they will be strongest if they each are attached to their own Arduino pin (with a resistor in-between). Doing so will also allow you to control when they are on or off individually.

Multiple LEDs

Circuit

Here is a basic circuit:

Multiple LED Circuit

Code


//Flowing LED Lights
/* Eight LEDs will light up one by one from left to right, and then go out one by one from right to left.
After that, the LEDs will light up one by one from right to left, and then go out one by one from left to right.
This process will repeat indefinitely.*/
//Email:support@sunfounder.com
//Website:www.sunfounder.com
//2015.5.7
/**************************************/
const int lowestPin = 2;//the lowest one attach to pin 2
const int highestPin = 9;//the highest one attach to pin 9
/**************************************/
void setup()
{
//set pins 2 through 9 as output 
for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++)
{
pinMode(thisPin,OUTPUT); //initialize thisPin as an output
}
} 
/****************************************/
void loop()
{
//iterate over the pins
//turn the led on from lowest to the highest
for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++)
{
digitalWrite(thisPin,HIGH);//turn this led on
delay(100);//wait for 100 ms
}
//fade from the highest to the lowest
for(int thisPin = highestPin;thisPin>=lowestPin;thisPin--)
{
digitalWrite(thisPin,LOW);//turn this led off
delay(100);//wait for 100 ms
}
for(int thisPin = highestPin;thisPin>=lowestPin;thisPin--)
{
digitalWrite(thisPin,HIGH);//turn this led on
delay(100);//wait for 100 ms
}
for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++)
{
digitalWrite(thisPin,LOW);//turn this led off
delay(100);//wait for 100 ms
}
} )
          

Try

Try adjusting the code to make your own pattern or swap out different colors of LED’s. You can also use male-to-male jumper wires or soldered wire to make your LED’s legs longer and extend them into glass or sculptural forms.