This post is the first in a series of posts on the Arduino development boards and the stuff you can do with them. Arduino development boards come in different versions with different controllers in them. All of these Arduino boards have ATMega controllers in them. Right now, I have an Arduino Mega 2560 development board with me, so I will be testing all the circuits and programs that I put here on this board. These have to work on other Arduino boards as well without any alterations. Also, with a little bit of change in the port declaration, you can use the same programs and circuit diagrams with the Texas Instruments MSP430 as well. Anyway, let us get started now.
In this post, we are going to have a look at how you can blink an LED using your Arduino in less than 5 minutes. For this program, you will need a resistor of some value, I will be using a 1K resistor. You will need an LED or any color. You will also need an Arduino board. The connections are as shown in the circuit diagram.
You can literally connect the resistor to any pin on your Arduino board. This doesn’t matter. But usually, every Arduino board will have an LED connected to pin 13, and this LED will be mounted on the board as well. And as a matter of fact, you can just dump the code below to your Arduino board and just blink the LED which is present on the board.
The resistor is used to limit the current flowing through the LED. This will also limit the intensity or the brightness of the LED. You can connect the LED directory without a resistor, but it’s not advised. You need to connect the positive/longer lead of the LED to the other end of the resistor, as shown in the circuit diagram, and you need to connect the shorter lead of the LED to the ground. You can use the Gnd output pin on your Arduino board for better results.
Now, you can take an output from any pin on your Arduino port and connect it to the resistor. But for convenience, we are going to use pin 13. Once this is done, connect your Arduino board to your computer and write the following code in a new file in the Arduino IDE. Copying the code below and pasting it in the IDE will also do.
int led=13; //declaring pin 13 on the Arduino board as the LED pin void setup() //function which sets up the Arduino board { pinMode(led, OUTPUT); //telling the controller that the LED pin is an OUTPUT pin digitalWrite(led, HIGH); //writing a HIGH to the LED pin, which will turn ON the LED } void loop() //function which will be executed continuously on the controller { delay(1000); //delaying the execution of the next instruction by 1000 msec(1 sec). //This will keep the LED ON for one second. digitalWrite(led, LOW); //Turning OFF the LED delay(1000); //waiting for one second again digitalWrite(led, HIGH); //Turning ON the LED }
The above program will blink an LED connected to pin 13 of the Arduino board every one second. The delay() function takes one integer argument. This argument is the time in milliseconds for which you to delay the execution of the next instruction in the program. You can change the value passed to this function (1000 in this example) to any value of your choice to see the difference.
Hope I have been clear with my post and the way it works. If you cannot get this circuit or program to work or if you have any other doubts, please comment in the section below so that I can get back to you. If you have any suggestions, please comment that as well. You can watch the output in the video below.