In this post, we are going to make our first Arduino program. We assume you have an Arduino UNO board or similar, as seen in this post, and the standard Arduino IDE correctly installed, as shown in this post.
Preparing the Connection
First, connect your Arduino board using an A-B USB cable, the type commonly used to connect printers. For now, no additional power supply or cable is needed for programming; the USB connection alone is sufficient.

Next, open the Arduino IDE. Select the board model you are using.

Select the communication port it is connected to.

- On Windows, it will be something like COM1, COM3…
- On Linux, it will be like /dev/ttyACM0
Now we have the connection configured and ready to load our first program.
Basic Program Structure
In the standard Arduino IDE, programs always have the following structure:
//DECLARATIONS AREA
void setup()
{
// SETUP function area
}
void loop()
{
// LOOP function area
}
Where each part has the following function:
- Declarations Area: In this part, variables, functions, objects, and structures are declared.
- Setup function: This function runs every time the Arduino board is powered on or the Reset button is pressed. It performs initialization of peripherals, communications, variables, etc.
- Loop function: This function runs continuously. It performs the main tasks of the automaton.
This configuration (a setup function and a continuously running loop) is common in automation programming and is the only one allowed by the standard Arduino IDE. Other configurations are possible using other IDEs.
Loading an Example
To test our setup, we will use one of the examples included in the Arduino IDE.

Select the example Basics / Blink, and a code similar to the following will appear.
const int pinLED= 13; //assign LED variable as 13
void setup()
{
pinMode(pinLED, OUTPUT); //define pin 13 as output
}
void loop() {
digitalWrite(pinLED, HIGH); // turn on LED
delay(1000); // wait one second
digitalWrite(pinLED, LOW); // turn off LED
delay(1000); // wait one second
}
This example turns an LED on and off every second. The LED used is integrated into many Arduino boards (UNO, MEGA, etc) physically connected to PIN 13.
The function of each line is commented on the right, but we won’t worry about the meaning for now (we’ll see these aspects later).
You can learn a lot by reading the examples; it’s highly recommended to take a look at all of them.
Finally, click the highlighted button to compile and upload the program to your Arduino board. After a few seconds, the IDE will compile the program and the screen should look similar to the following.

After a few blinks, the board will start executing the program, turning the LED on and off (we agree it’s not very spectacular).
But the important thing is that if you’ve made it this far, it means everything is working and properly configured, and from here you are ready to start playing 🎉.
Don’t forget about PIN 13 when writing your programs. It’s very helpful for debugging your programs.
External Power Supply
Once we have programmed our board, it’s time to remove the USB cable and use an external power supply, so that Arduino can run without a computer.
Arduino UNO and MEGA can be powered by two means. The power source is selected automatically.
Regulated 5V Power via the USB Port
We can connect a transformer, an external 5V battery, or any other 5V source using a USB connector.
This input must have regulated power, meaning it must be stable, constant, and fixed at 5V (since Arduino does not monitor the voltage introduced through this input).
Power via the Vin Connector
There is a pin called Vin, through which we can power Arduino. We must supply a voltage between 6 to 20 volts, although the ideal range is 7 to 12 volts. For example, we can:
- Connect a transformer
- A 9V battery
- A grouping of 4 or 6 1.5V batteries
Avoid voltages above 12 volts for prolonged periods. They can overheat the voltage regulators and damage the board.
If we connect our external power supply to our Arduino board, we will see it executes the program we uploaded, of course without the need for a connected computer.
Download the Code
All the code from this post is available for download on Github.

