Monday, May 28, 2012

0 Arduino Project 1 - Flashing LED's

In this post, i have aasumed that you have successfully installed the Arduino Environment. If not then please refer to this post .
This is the most basic of the sketches in Arduino and even comes bundled with the program but we've got to start somewhere don't we?
In this project we will learn to modify the Blink sketch, we will increase the frequency of the blinking and then install the modified sketch on our Arduino board. Then we advance by using an external resistor and LED instead of the tiny built in LED.
In this example I have used the Arduino Duemilanove

Editing the software

Loading the Original Sketch(which is Arduino term for program)


  • Open the Arduino Program
  • Select File -> Examples -> Digital -> Blink

 Modifing The Sketch

  • Find the code that says 'delay(1000) ;'. This line instructs the microcontroller to delay the blink by 1000 miliseconds or 1 second. We can change the value 1000 to whatever we like, for this post i will keep it to 500. (Dont keep the value as small as 1 ms , it will make the blink imperceptible).
  • Click the upload botton.
  • It will take 5-10 seconds for the sketch to upload
  • You will notice that the LED has started to blink much faster now!
Congratulations! You just uploaded your first sketch to the Duemilanov.
(Doesn't matter which Board you have, the sketches will always be the same)

Hardware

For this part, you will need
  • A 5mm red LED (However any commonly avalable LED will do.)
  • 270 ohm resistor
  • A pair of pliers
Note - LEDs cannot work standalone, they need a current limiting device to work, hence the resistor.

Procedure

  • Connect (just entangle) one end of the resistor (does not matter which one) with the shorter end of the LED (this is very important). If you do not connect it the correct way, it could fry your board, so be careful.
  • Put the free end of the LED into the 12 numbered pin of the Duemilanove, and the free end of the resistor to the GND pin.
We can now modify the sketch to accomodate the external LED
The only change to the sketch will be changing the line

int ledPin = 13;
// LED connected to digital pin 13

to 


int ledPin = 12;
// LED connected to digital pin 12


Thats because we have connected the LED to 12 pin.
Note - Anything written after // is not read by the arduino program. So it doesn't really matter what you write after it.
Here is the full code, just load it into the arduino environment and upload it to the board.
You can see the original code here


That's all for this post folks!
Please let me know if there is anything i should clarify or add in the comments.
Or if you would simply like to give a compliment, you are welcome! :P





0 comments:

Post a Comment

Do Comment on Anything you like or dont like!

 

The Engineer's Spot! Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates