To make an LED that is connected to the output pins of the Arduino board blink, perform the following steps:
- Open the Arduino IDE. Arduino opens up with a file showing the default content, as follows:
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
- Connect the Arduino board to the PC.
- From the Tools menu, select Port and confirm whether it shows COM3 (Arduino/Genuino Uno) or whatever Arduino board you have attached to your PC. Additionally, confirm whether the Board option from the Tools menu indicates the Arduino board that is attached to your PC. In my case, the Board option will show Arduino/Genuino Uno.
- Remember, the LEDs have polarity; hence, they will only glow when they are connected properly. The long leg is positive and should connect to a digital pin on the Arduino board. I am using the 13th pin of the Arduino board for the output, so connect the long leg of the LED to the 13th pin of the Arduino board (refer to Figure 5.10). Then, connect the short leg of the LED, which is negative, to the GND on the Arduino board.
- Type the following program in the editor window:
int Led = 13;
void setup() {
pinMode(Led, OUTPUT);
}
void loop() {
digitalWrite(Led, HIGH);
delay(1000);
digitalWrite(Led, LOW);
delay(1000);
}
6. Save the application by clicking on File | Save As. Specify the application name when prompted. Select the desired folder location and specify the application name. Let's name the application ArduinoLedBlink. A folder will be created with the specified application name (ArduinoLedBlink), and, within the ArduinoLedBlink folder, the application will be created with the filename ArduinoLedBlink.ino.
7. Upload the application to Arduino by clicking on the Upload icon in the toolbar.
Now, let's go behind the scenes to understand the steps better.