Blinking an LED
The LED blinking sketch is the first program that you should run to test whether your Arduino board is working and is configured correctly. It is also usually the very first programming exercise someone does when learning to program a microcontroller. A light-emitting diode (LED) is a small electronic component that's a bit like a light bulb, but is more efficient and requires lower voltages to operate.
Your Arduino board comes with an LED preinstalled. It's marked "L". You can also add your own LED—connect it as shown in Figure 4-2.
K indicates the cathode (negative), or shorter lead; A indicates the anode (positive), or longer lead.
Once the LED is connected, you need to tell Arduino what to do. This is done through code, that is, a list of instructions that we give the microcontroller to make it do what we want.

Figure 4-2. Connecting an LED to Arduino
On your computer, go open the folder where you copied the Arduino IDE. Double-click the Arduino icon to start it. Select File > New and you'll be asked to choose a sketch folder name: this is where your Arduino sketch will be stored. Name it Blinking_LED and click OK. Then, type the following text (Example 4-1) into the Arduino sketch editor (the main window of the Arduino IDE). You can also download it from www.makezine.com/getstartedarduino. It should appear as shown in Figure 4-3.
Example 4-1. Blinking LED
#define LED ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access