Friday, 24 January 2014

ARDUINO INSIGHT- LED's


I'm going to show you

* Write a simple program for glowing LED
* Group of LED program
* Explain analog output (PWM)
* Create a simple project of (4 bit binary counter).


Step 1: Materials required

  • 1 x Bread board
  • 4 x LED
  • 4 x 1k ohm resistors
  • Arduino UNO r3
  • USB cable of Arduino.

Friends this is enough for doing all the things specified in this tutorial,,,!!!!!!!!!!

NOTE : I have used a led array on strip board for my convenience SORRY......Besides that you can design the led array on bread board itself.


Step 2: Schematics











Friends these are the schematics for glowing LED'S. PWM is a seprate thing so that I have highlighted the specific (figure no2).

Step 3: Glowing a single LED

The thumb rule is that writing a "Simple program" to understand the hiearchy of Arduino programming.



  • The Setup Function
The next stage in creating any sketch is to add the void setup() function. This function contains a set of instructions for the Arduino to execute once only, each time it is reset or turned on. To create the setup function, add the following lines to your sketch.

void setup()
{
........
}

  • Controlling the Hardware
Our program will blink the user LED connected to pin 2. A digital pin can either detect an electrical signal or generate one on command. In this project, we’ll generate an electrical signal that will light the LED. This may seem a little complicated, but you’ll learn more about digital pins in future chapters. For now, just continue with creating the sketch. The number 2 in the listing represents the digital pin you’re addressing. You’re setting this pin to OUTPUT, which means it will generate (output) an electrical signal. If you wanted it to detect an incoming electrical signal, then you would use INPUT instead

void setup()
{
pinMode(2, OUTPUT); // set digital pin 2 to output
}

  • The Loop Function
Remember that our goal is to make the LED blink repeatedly. To do this, we’ll create a loop function to tell the Arduino to execute an instruction over and over until the power is shut off or someone presses the RESET button.
void loop()
{
// place your main loop code here:
}

  • Summing up
void setup()
{
pinMode(2, OUTPUT); // set digital pin 2 to output
}
void loop()
{
digitalWrite(2, HIGH); // turn on digital pin 2
delay(1000); // pause for one second
digitalWrite(2, LOW); // turn off digital pin 2
delay(1000); // pause for one second
}

Thats all friends I hope you completed the first task of lighting up and off of LED.This is the basis for all the further concepts.

Step 4: Glowing multiple LED

In this section it's time to hook up multiple LED with our Arduino. We can use 1k ohm resistor for current limiting...so that our LED stays alive :)

When interfacing multiple LED'S with Arduino we can follow the same procedure for glowing a single LED from step 3.The concept of programming is same, whilst you have to keep in mind that multiple LED'S are used. I have uploaded a simple program for glowing 4 LED'S with some (delay of half second).

Algorithm :

  • Initialize void setup function.
  • create a repeating loop function.

Thats all friends you have successfully made group of LED glow.

_4_led_s.ino463 bytes

Step 5: For loop usage



  • For loop :
When designing a sketch, you’ll often repeat the same function. You could
simply copy and paste the function to duplicate it in a sketch, but that’s inefficient and a waste of your Arduino’s program memory. Instead, you can use for loops. The benefit of using a for loop is that you can determine how many times the code inside the loop will repeat. I have made for loop inside the sketch for pins 2 to 5. This technique hepls to reduce the program memory.


Friends now we have seen sor far glowing a single LED then multiple and finally to use (for loop) in Arduino programming. lets move on!!!!!

Step 6: PWM OUTPUT (pulse width modulation)

Arduino UNO has about 14 input and output pins of which 6 are analog outputs (PWM) pins. And there are about 6 analog inputs which are ADC'S. The PWM pins give analog output which is used in majority of projects.In this tutorial we are going to demonstrate with the help of LED'S.
  • Varying LED Brightness with Pulse-Width Modulation :
    Rather than just turning LEDs on and off rapidly using digitalWrite(), we can define the level of brightness of an LED by adjusting the amount of time between each LED’s on and off states using pulse-width modulation (PWM). PWM can be used to create the illusion of an LED being on at different levels of brightness by turning the LED on and off rapidly, at around 500 cycles per second. The brightness we perceive is determined by the amount of time the digital output pin is on versus the amount of time it is off—that is, every time the LED is lit or unlit. Because our eyes can’t see flickers faster than 50 cycles per second, the LED appears to have a constant brightness.


OK friends I think I have given everything that you should know about LED programming.The next part is going to be very intresting we are going to make a project based on the things that we have learned. :)

PWM.ino255 bytes

Step 7: 4 Bit binary counter

If you are a electronics engineer you should know binary counter program....Well it's a crime if you don't know...beacuse these things are the very basic of every digital systems LOL :).....Cool,!!!! it's a easy concept if you look at it.
Guys lets get started to it..............

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

"If you observe 4 bit sequence it is well understood that LSB is toggling every cycle while the bit next to it is toggling every 2 cycles and bit next to it toggles at every 4 cycle to achieve this effect we use MOD operator %"...and so on if you can imagine... :)
Remember friends this forms the basis for any number of BINARY SEQUENCES.

  • CONCEPT FOR PROGRAMMING 4 BIT COUNTER :
Counter%2 for LSB ie ( 01010101010101...)
(Counter/2)%2 for (00110011....)
(Counter/4)%2 for (0000111100001111....)
(Counter/8)%2 for MSB (0000000011111111)

Guys that's the concept....>> just go ahead and don't be afraid !!!!!! to add up some more LED'S to create 5 bit binary or 6 bit binary counter. :) :) Afterall you have Arduino.............Break the barriers....
Thank you..hope you like my tutorial see ya guys.....!!!! Happy Arduinoing.

No comments: