After understanding the hardware of the Arduino UNO board in the previous article, let's now get started with Arduino programming.
Arduino programs are written in the Arduino Integrated Development Environment (IDE). The Arduino IDE is software that lets you write sketches (Arduino programs) for various Arduino boards. The programming language is based on Processing, which resembles the C language. Once written, the sketch is uploaded to the board for execution.
The first step is downloading and installing the Arduino IDE, which is available for Windows, macOS, and Linux. Download the appropriate version from the official site and follow installation instructions.
Structure of Arduino Programs
Every Arduino program has at least two parts:
- Preparation block –
setup()
- Execution block –
loop()
void setup() {
// initialization code
}
void loop() {
// repeated execution code
}
setup()
runs once when the program starts and is typically used to set pin modes or start serial communication. Even if unused, it must be defined.
void setup() {
pinMode(pin_number, OUTPUT);
pinMode(pin_number, INPUT);
}
loop()
executes repeatedly after setup()
. It's used to read inputs, write outputs, and handle logic.
void loop() {
digitalWrite(pin_number, HIGH); // turn on
delay(1000); // wait 1 second
digitalWrite(pin_number, LOW); // turn off
delay(1000); // wait 1 second
}
Note: Time is measured in milliseconds in Arduino.
Experiments
- Blinking the LED
- Fade-in and fade-out the LED
Components Required
- Arduino UNO R3 – 1
- Breadboard – 1
- Breadboard connectors – 3
- LED – 1
- 1K resistor – 1
Blinking LED
Steps to build the circuit:
- Connect Arduino to system via USB cable.
- Connect digital pin 13 to breadboard positive rail; GND to negative.
- Use a 1K resistor between positive rail and terminal strip.
- Place LED in terminal strip below resistor.
- Connect LED cathode (short lead) to breadboard ground rail.

Code Version 1
int LED = 13;
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
Code Version 2
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Version 1 makes it easier to reuse or change pin numbers by using a variable.

Fade-In and Fade-Out LED
Note: Use pin 9 instead of pin 13 in this setup.

Code Version 1
int led = 9;
int brightness = 0;
int fade = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fade;
if (brightness <= 0 || brightness >= 255) {
fade = -fade;
}
delay(30);
}
Code Version 2
int led = 9;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
for (int fade = 0; fade <= 255; fade += 5) {
analogWrite(led, fade);
delay(30);
}
}
analogWrite
is used on PWM-capable digital pins to simulate analog output.
Next Steps: In the next article, we’ll explore conditional statements, loops, and analog/digital I/O in depth.
Congratulations! You've completed level-1 of Arduino programming. Move on to level-2 to keep learning!