Tuesday, 9 September 2014

Blinking a LED

Blinking a LED

            This example will explain you how to make a LED to blink continuously with a set time delay. The digital out put pin being used in the following circuit is 13 of Arduino Uno. Any LED should not be directly connected to the digital output of Arduino. You have to control the current to the LED. In this schematic a resistor of 220 ohm, 1/4 w is used to limit the current to 23 mA (5V/220 ohm = 23 mA). Anode of the LED is to be connected to Pin 13 of Arduino through a 220 ohm resistor. Cathode of the LED is to be connected to the ground. Both +5V and Ground terminals are available in the Arduino Board itself. After making the following wiring, write code in the Arduino IDE.

      

Code 1:
/*
  Blink
  LED connected to the pin of Arduino is made ON and OFF for one second each alternatively.
This is repeated for ever. 
 */

int led = 13;

void setup()
{                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

void loop()
{
  digitalWrite(led, HIGH);   // turn ON the LED (HIGH  = 1 level)
  delay(1000);                    // wait for a second (i.e. 1000 mS)
  digitalWrite(led, LOW);   // turn OFF the LED (LOW = 0 level)
  delay(1000);                      // wait for a second  (i.e. 1000 mS)
}

compile the above code with the Arduino IDE you can see the magic in the LED burning. If you want to make LED to blink fast, the milli second delay can be reduced and checked. If you want to experiment another circuit mentioned below, you can do so.


       By making the above circuit, you can have the circuit as decorative lamps running. For making the above circuit, either you can use same colour LEDs or different colour LEDs. For the above circuit, you can use the following code.

Code 2:
/*
  Blink3Led
  LED connected to the pins of Arduino are made ON and OFF one by one with a delay of one second. 
This repeated for ever. 

 */

int led1 = 11;
int led2 = 12;
int led3 = 13;

void setup()
{                
  // initialize the digital pins as outputs.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);     
}

void loop()
{
  digitalWrite(led1, HIGH);   // turn ON the LED1 (HIGH  = 1 level)
  digitalWrite(led2, LOW);   // turn OFF the LED2(LOW = 0 level)
  digitalWrite(led3, LOW);   // turn OFF the LED3 (LOW = 0 level)
  delay(1000);                      // wait for a second  (i.e. 1000 mS)
  digitalWrite(led1, LOW);   // turn OFF the LED1(LOW = 0 level)
  digitalWrite(led2, HIGH);   // turn ON the LED2 (HIGH  = 1 level)
  digitalWrite(led3, LOW);   // turn OFF the LED3 (LOW = 0 level)
  delay(1000);                      // wait for a second  (i.e. 1000 mS)
  digitalWrite(led1, LOW);   // turn OFF the LED1(LOW = 0 level)
  digitalWrite(led2, LOW);   // turn OFF the LED2(LOW = 0 level)
  digitalWrite(led3, HIGH);   // turn ON the LED3 (HIGH  = 1 level)
  delay(1000);                      // wait for a second (i.e. 1000 mS)
}

 While experimenting the above, you can learn some thing in the field of micro-controller programming and hardware. If you really enjoyed my posts. Please comment, that will encourage me to post many more. You can also comment in both ways!     

      
  
           

No comments:

Post a Comment