Tuesday, October 4, 2011

8 Blinking LEDs (CIRC-02)

Purpose:
The purpose of this experiment is to turn multiple LEDs on and off in a sequence.


Equipment:

  • 8 x 330 Ohm Resistor
  • 8 x Yellow LED
  • 10 x Wire
  • 1 x Breadboard
  • 1 x Arduino Uno
  • 1 x Breadboard reference sheet
Program Details:

      This circuit uses techniques similar to the first circuit, but with added LEDS (8 in total). Again, assembly is straightforward, but not easy. As the amount of LEDs increases, so does the resistors, and again, keeping them in place was quite a task. See 'Tips' for advice on this part of the assembly. Assembly takes around 3-8 minutes.The image below displays the assembled circuit.

Assembled and functional circuit 2.

     The programming for this circuit uses the same basics from the first circuit, (delaytime, HIGH, LOW, etc.), but with a few new concepts such as, utilizing an array, programming the number of repeats, and using the 'oneAfterAnotherNoLoop'. The array is used in the very beginning during the setup. In this case, it simply stores all possible values for the ledpin, which the program can access. Next, the number of repetitions is set using the variable i in the function: for(int i = 0; i < 8; i++){}.After setting i to the minimum, the limit (maximum) is stated using the less than sign, and is essentially the number of repetitions. By adding 'i++' afterwards, the program is allowed to increase the value of i till it reaches the maximum. Another way to be concise in this program is using the oneAfterAnotherNoLoop, which as its name suggests, performs everything in the loop one after another repeatedly. The loop in this circuit turns each LED on consecutively, with a pause identified by the variable 'delaytime', then turns all LEDs off in the same fashion.  

Results

     After uploading the program to the circuit, a minor error surfaced. Certain LEDs did not turn on at all, while the other LEDs followed the uploaded program. First we checked the program to see if the coding for the specific dysfunctional pins were the problem, however after checking everything, the source of error turned out to be the assembly of the resistors. Here we learnt that we have to wire the resistor specifically as shown in the breadboard sheet, so that the right side of the resistor was plugged into the right component in the breadboard. After rewiring the resistors, the circuit worked fine.

The final circuit.

Tips

     With the assembly of the circuit, the only thing to keep in mind is the fragility of the resistors. Assemble the resistors last, with patience, so you get it right the first time and also stays in place. In addition to the assembly, remember to keep the programming clean. Use comments so that you can refer back to what each component of the program is if something goes wrong. If you know it well, you don't have to. 

Next Steps & Associated Program Modifications


     There are many ways to go from here. You can add more pins, or play with the the pattern in which the LEDS are turned on and off. For instance, an arduino related forum, link here,  discussed manipulating the circuit to flash each LED in ascending/descending order. The following snip-it of new program (descending flashing lights) is from the website:


void descend()
{
  int descending[] = {9,8,7,6,5,4,3,2};
  
  for (int i = 0; i < PIN_COUNT; i++)
  {
    digitalWrite(descending[i], HIGH);
    delay(100);
    digitalWrite(descending[i], LOW);
  }
}



This coding can be integrated into the program for circuit two by simply adding this code after introducing the pins and setup. See below. New coding slightly modified, integration and comments original.


int ledPins[] = {2,3,4,5,6,7,8,9}; //this introduces the connected LEDs 
//that we'll be working with


void setup() //the coding below in setup turns all the LEDs on
{
  for (int i = 0; i < PIN_COUNT; i++)
  {
    pinMode(ledPins[i], OUTPUT);
  }
}



//now add the new codes!


void descend()  //loop for the descending pattern (repeats)
{
  int descending[] = {9,8,7,6,5,4,3,2}; //the order of the LEDs that will be used
//Note that this sequence is different from the regular one

    for (int i = 0; i < PIN_COUNT; i++) //the pattern will work up till the last 
//pin. From pin 2-9. However it starts off at nothing, 0.

  {    digitalWrite(descending[i], LOW); //the program originally said HIGH, but 
//since all the LEDs are already on, they will turn off first. 

    delay(100);  //wait a tenth of a second
    digitalWrite(descending[i], HIGH); //turn the LEDs off
  }
}







Finito!!


References

  1. http://forums.adafruit.com/viewtopic.php?f=21&t=17865
  2. http://docs.google.com/viewer?a=v&q=cache:oxirS_yKWpUJ:www.sparkfun.com/tutorial/AIK/ARDX-EG-SPAR-WEB.pdf+arduno+sparkfun+starter+kit+circ-01&hl=en&gl=ca&pid=bl&srcid=ADGEEShenZ1X6WUWJcmrXmkYtGjoNz6DylD1jf6bB0E9RT7CWJOitbc2DHxsFePHchtLV3h8TXOOjgqHR7i2hU07hfYY_j9QeHqE8q5dSw3xJbhtDK7njPAydUExPLnGZFfOq4ySJasd&sig=AHIEtbS9g6laYWNOfpgAqcqz8QvV9YxUVg&pli=1


No comments:

Post a Comment