Monday, August 24, 2015

10 led random pattern flashing using Arduino (Uno)

//Multi LED Blink

int led1Pin = 13;
int led2Pin = 12;
int led3Pin = 11;
int led4Pin = 10;
int led5Pin = 9;
int led6Pin = 8;
int led7Pin = 7;
int led8Pin = 6;
int led9Pin = 5;
int led10Pin = 4;

void setup() {  
  //initialize the led pins as an outputs
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  pinMode(led6Pin, OUTPUT);
  pinMode(led7Pin, OUTPUT);
  pinMode(led8Pin, OUTPUT);
  pinMode(led9Pin, OUTPUT);
  pinMode(led10Pin, OUTPUT);

}

void loop() {
  //pick a random color
  analogWrite(led1Pin, random(256));
  analogWrite(led2Pin, random(256));
  analogWrite(led3Pin, random(256));
  analogWrite(led4Pin, random(250));
  analogWrite(led5Pin, random(256));
  analogWrite(led6Pin, random(256));
  analogWrite(led7Pin, random(256));
  analogWrite(led8Pin, random(256));
  analogWrite(led9Pin, random(256));
  analogWrite(led10Pin, random(256));
  delay(300);//wait one second



/*  digitalWrite(led1Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led1Pin, LOW);//turn LED off
  delay(100);

  //do the same for the other 3 LEDs
  digitalWrite(led2Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led2Pin, LOW);//turn LED off
  delay(100);

  digitalWrite(led3Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led3Pin, LOW);//turn LED off
  delay(100);

  digitalWrite(led4Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led4Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led5Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led5Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led6Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led6Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led7Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led7Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led8Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led8Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led9Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led9Pin, LOW);//turn LED off
  delay(100);


  digitalWrite(led10Pin, HIGH);//turn LED on
  delay(100);
  digitalWrite(led10Pin, LOW);//turn LED off
  delay(100);
  */
}

Above is the code that i wrote which will randomly light colored leds at different times and different brightness. You can use this light code and these lights to light up a part and, if you expanded the code and light, you can light your room in different colored variation. In the circuit with the arduino, you would use pins 4 to 13. These are the pins that i used in the code. It doesn't matter which type of led goes where, but make sure to put a 100 to 200 ohm resistor in series with the led, unless you want to burn out your leds.

Below, is a video of the code lighting lights using the arduino uno and  10 leds with colors of  red, green and yellow.