Sunday, October 9, 2011

Circuit-02 - Multiple LED's

Purpose: To make 8 LED's blink

Equipment:
  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC-02 Breadboard Sheet x 1
  • Yellow LED x 8
  • Wire x 10
  • 330 Ohm Resistor x 8

References: 


Program Details:
In this circuit, the methods used from the previous circuit (CIRC-01) are used again, except on a much bigger scale. This time, instead of making only 1 LED blink, we will make multiple LED's blink. However, one new hardware concept is learned through this experiment. A wire connected from ground(-) or power(+) will allow the whole column to flow with the same type of electricity (either + or -). This will allow multiple wires to be connected from a positive or negative column into the horizontal rows which in turn will allow multiple rows to have the same flow of electricity. This is more efficient than connecting every single row with a power  or ground source.

In terms of programming, we learn a few more things about arduino. In the previous exercise we learned how to use a void loop and three basic methods, pinMode, Digital Write, and delay. In this exercise, we learn how to use a for loop and an array. An array is used to manage variables. Instead of creating a bunch of variables to hold certain values, we can use an array to do it. A for loop is used to run a piece of code several times. In this exercise, we learn how to use a for loop to assign values to variables in an array.

To create circuit-01, we followed the breadboard sheet almost exactly. One difference was the PIN numbers because it was hard to place the wires as they were all getting crowded. The other difference was the colour in LED's, we had 4 red LEDs and 4 yellow LED's. Aside from that, everything else was the same.

Time to Complete: 15 mins to set up arduino board
                                20 mins to write program

Results: When we first tried it, only 4 of the lights lit up. We found out that this was because we didn't place the other 4 LED leads on the correct rows. After we fixed it, all of them worked. 

Photo: 


Tips:
  • Try to be neat with wiring and resistors
  • Remember that arrays are a group of variables of the same type (in this case Integers)
  • Change the code to make cool LED patterns

Further Work: I will change the code to be more efficient (use more loops) and make different intervals between the LED's to make different lighting patterns.

Program Modifications:
The code is the exact same as the one from the link below. 



Program: 
//LED Pin Variables
int ledPins[] = {2,3,4,5,6,7,8,9};  //An array to hold the pin each LED is connected to (ledPins[0] is   
                                                    //connected to pin 2)                                  

void setup()                            //Runs once to intialize the program
{
  for(int i = 0; i < 8; i++)        //Sets i to 0, loops as long as i is less than 8,
                                            //everytime a loop is completed i = i+1
 {              
      pinMode(ledPins[i],OUTPUT);   //Assigns all 8 ledPins with an OUTPUT Signal
  }                                  
}// ends setup method

void loop()                         // everthing inside the loop is repeated as long as there is power
{
  oneAfterAnotherLoop();            //calls the oneAfterAnotherLoop Method
}// ends the loop

void oneAfterAnotherLoop()
{
  int delayTime = 100;               //time in milliseconds   
  //Turn Each LED on with a delay
  for(int i = 0; i <= 7; i++)         //integer i is a counter, i is added once everytime a loop is run up to 8 times
  {
    digitalWrite(ledPins[i], HIGH);   //Turns on LED #i everytime this runs 
    delay(delayTime);                 
   }                                          // ends the for loop                                                                        
  //Turn Each LED off with a delay
  for(int i = 7; i >= 0; i--)        //integer i is a counter, i is subtracted once everytime a loop is run up to 8 times
  {  
    digitalWrite(ledPins[i], LOW);   //Turns off LED #i each time this runs
    delay(delayTime);                
  }                                                                                                                                                 
}// ends oneAfterAnotherLoop method

No comments:

Post a Comment