Indice
3.1 What Is Programming? From Problem to Code
Programming is the process by which we describe to a computer the operations it must perform to carry out a given task.
A computer can process data and execute instructions very quickly, but to get a result it must be given precise directions on what to do and how to do it.
These directions are collected in a program, an organized set of instructions that the computer executes to achieve a goal.
For example, we can write a program that performs a series of calculations, displays a message on the screen, or controls the operation of an electronic device.
In the case of Arduino, a program might read the value from a sensor, check a certain condition, and turn on an LED or activate a motor.
A Brief History of Programming
The first electronic computers, developed starting in the 1940s, were programmed in ways very different from those we use today. Instructions were represented directly in machine language, using sequences of binary numbers that the processor could understand.
This method was extremely complex for humans: even relatively simple operations required handling many low-level instructions.
To make programming easier and more productive, languages were developed that allowed the use of more understandable instructions. Among the first steps in this direction were Assembly language, followed by higher-level languages such as FORTRAN and COBOL, developed in the 1950s.
In the following years, many other languages emerged, each designed to make certain types of applications easier to build. Today there are languages used to develop operating systems, applications, websites, video games, and electronic devices.
The evolution of programming languages has made it possible to create increasingly complex programs, reducing the need to deal directly with the details of the processor’s internal workings.
Why Were Programming Languages Created?
A computer processes instructions in a form that depends on the processor’s architecture, while people need simpler tools to describe the operations to be performed.
Programming languages were created precisely to let people write instructions in a more readable and organized form.
Each language has precise rules, called syntax, that determine how instructions must be written so that development tools can interpret them correctly.
The code written by the programmer must then be translated or processed by software tools, such as compilers and interpreters, in order to be executed by the computer.
In the case of Arduino, we will use a language based on C/C++, which will allow us to describe the operations the microcontroller must perform.
Programming Means Solving a Problem
Programming is not just about writing instructions in a language. Before you start writing code, you need to understand the problem and determine which operations must be performed and in what order.
Let’s imagine, for example, that we want to create a program that turns an LED on for one second and then turns it off for another second, repeating this sequence continuously.
Before writing the code, we can describe the desired behavior as a series of steps:
- Turn on the LED.
- Wait one second.
- Turn off the LED.
- Wait one second.
- Repeat the sequence.
This description already represents the fundamental logic of the program, even though we haven’t yet written a single instruction in a programming language.
In the next sections, we’ll see how to organize this kind of reasoning using algorithms and flowcharts, tools that will help us design a program before turning it into code.

3.2 Algorithms and Sequential Logic
Before writing a program, it is important to understand which operations must be performed to solve the problem and in what order they must occur.
The ordered description of a series of operations needed to reach a goal is called an algorithm.
An algorithm is not necessarily tied to a computer or a programming language. Even the instructions for preparing a recipe, assembling an object, or following a route can be considered algorithms, as long as they are organized clearly and make it possible to achieve the desired result.
The Sequence of Instructions
The simplest form of an algorithm is a sequence of operations, executed one after the other in the established order. Let’s imagine, for example, that we want to turn an LED on for one second and then turn it off. We can describe the algorithm with these steps:
- Turn on the LED.
- Wait one second.
- Turn off the LED.
- End the execution.
The order of the operations is essential. If we tried to turn off the LED before turning it on, the program’s behavior would differ from what we wanted.
This way of executing instructions is called sequential logic: the instructions are executed one after the other, following the sequence defined by the program.
Why Is It Important to Design Before Programming?
When a problem becomes more complex, writing code directly without first organizing the operations can make it hard to find errors and to understand how the program works.
For this reason, it is good practice to design the program’s logic first and only then translate it into the chosen programming language.
We can do this by describing the operations in plain words or by representing them graphically with a flowchart. For example, for a program that must make an LED blink continuously, we can identify these operations:
- turn on the LED;
- wait one second;
- turn off the LED;
- wait one second;
- repeat the operations.
In this case, unlike the previous example, the sequence does not end but starts over continuously. We have therefore introduced a repetition, also called a loop, which we will explore in more depth in the following sections.
For now, it is enough to understand that a program can be built by organizing instructions in a precise sequence and deciding when that sequence must end or be repeated.
In the next section, we’ll see how to represent an algorithm graphically using flowcharts, with conventional symbols that describe the operations and the path the program follows.

3.3 Flowcharts
Flowcharts, also called flow diagrams or block diagrams, are a tool for representing the logic of a program graphically.
They use conventional symbols connected by arrows, which show the operations to be performed, the decisions to be made, and the path the program follows.
Flowcharts are useful because they let us visualize how a program works before writing the code. This makes it easier to organize the instructions, spot possible errors, and understand the behavior we want to achieve.
The Main Symbols
Each symbol has a precise meaning. The most commonly used are the following.
Start and End — Oval
Indicates the point where the procedure begins or ends. Every flowchart should have a starting point and, when applicable, an ending point.
Operation — Rectangle
Represents an action to be performed, such as turning on an LED, carrying out a calculation, or assigning a value to a variable.
Input and Output — Parallelogram
Indicates a data input or output operation. For example, reading the value from a sensor or displaying a result.
Decision — Diamond
Represents the check of a condition, whose result determines the path to follow. For example: Does the sensor detect an obstacle? Two paths can leave this check, one for the answer Yes and one for the answer No.
Arrows — Direction of Flow
They connect the symbols and show the order in which the operations must be performed. Arrows can also lead back to a previous block to represent a repetition.
An Example: Making an LED Blink
Let’s imagine we want to create a program that turns an LED on for one second, turns it off for one second, and repeats this sequence continuously. Before writing the code, we can describe the behavior with these steps:
- Start.
- Turn on the LED.
- Wait one second.
- Turn off the LED.
- Wait one second.
- Go back to step 2 and repeat the sequence.
In the flowchart, the actions of turning the LED on and off are represented by rectangles, while the waits are operations too. The arrows show the order of the steps, and the connection that leads back to the turn-on step represents the continuous repetition.
In this example there is no need for a diamond to represent a decision: the loop always repeats, without checking any specific condition.
Why Use Flowcharts?
Flowcharts help us focus on the logic of the program, without having to worry right away about the rules of the programming language.
They are especially useful for beginners, because they make it possible to break a problem down into simple operations and to see the relationship between one step and the next.
There are also other tools for describing an algorithm, such as pseudocode, which uses sentences similar to natural language, and UML diagrams. To get started with Arduino programming, flowcharts and descriptions in plain words are already effective tools.
In the next section, we’ll see how to move from the description of an algorithm to writing a program, turning the planned operations into instructions Arduino can understand.

3.4 From Flowchart to Program
After defining an algorithm and, if necessary, representing it with a flowchart, we can turn it into a program written in a programming language.
This phase consists of translating the operations described in the algorithm into instructions that the computer or microcontroller is able to execute.
Before writing the actual code, it can be useful to describe the steps using pseudocode.
What Is Pseudocode?
Pseudocode is a way of describing a program’s logic using simple words and organized instructions, without having to follow the precise syntax of a programming language.
There is no single, mandatory syntax: its purpose is to make the algorithm’s operation clear before moving on to writing the code.
Let’s go back to the example of the LED that must blink continuously.
We can describe the behavior with this pseudocode:
- START
- REPEAT CONTINUOUSLY:
- Turn on the LED
- Wait 1 second
- Turn off the LED
- Wait 1 second
This description is easy to understand even without knowing a programming language. Each instruction represents an operation that will have to be translated into code.
From Pseudocode to Arduino Code
To program Arduino we will use a language based on C/C++. The operations described in the pseudocode will therefore be expressed through instructions that follow the rules of this language.
For example, to turn an LED connected to a digital output on and off, Arduino provides specific instructions:
- digitalWrite() sets a digital output to a high (HIGH) or low (LOW) level;
- delay() waits for a time interval expressed in milliseconds.
One second is equal to 1000 milliseconds. Therefore, to wait one second, we use the instruction delay(1000);.
The complete program for making an LED blink will be covered in detail once we know the structure of an Arduino sketch and the main instructions of the language.
Why Follow These Steps?
Organizing the work in phases — algorithm, flowchart, pseudocode, and code — helps separate the logic of the problem from the details of the language.
It is not always necessary to use all of these tools: for a very simple program, it may be enough to identify the operations to be performed. When the project becomes more complex, however, designing the behavior first can make the work clearer and reduce errors.
In the next sections, we’ll see how to build algorithms that, in addition to executing instructions in sequence, can make decisions and repeat certain operations. These mechanisms are the foundation of almost all programs, including those used to control robots and electronic devices.

3.5 Sequence, Decisions, and Repetition
A program can be built by combining three fundamental mechanisms: sequence, decision, and repetition. These make it possible to establish which operations to execute, when to execute them, and how many times to repeat them.
Sequence
Sequence consists of executing instructions one after the other, in the order in which they were written.
For example, to turn on an LED, wait one second, and then turn it off, the program must execute these operations in the correct order.
Sequence is the simplest mechanism in programming and is the basis of all programs.
Decisions: The if Statement
Often a program has to behave differently depending on the situation. To do so, it can check a condition and choose which operation to execute.
In Arduino and in C/C++, one of the main tools for making decisions is the if statement, which means if.
Let’s imagine a robot equipped with a sensor that can detect an obstacle. The logic could be described like this:
IF the sensor detects an obstacle:
Stop the robot
ELSE:
Keep moving forward
The program checks the condition and, based on the result, executes one of the two actions. The word else, which means otherwise, lets us specify what to do when the condition is not true.
In this way, the robot’s behavior can adapt to what happens in its surroundings.
Repetition: Loops
Another very common operation is repeating one or more instructions several times. In programming, a repetition is called a loop.
There are several types of loops. Two of the most commonly used are for and while.
The for loop is often used when we know how many times we want to repeat an operation. For example, we can imagine wanting to make an LED blink five times.
The while loop, on the other hand, lets us repeat instructions as long as a certain condition remains true.
For example:
WHILE the sensor detects an obstacle:
Keep the robot stopped
In this case, the robot stays stopped as long as the condition is true. When the condition becomes false, the program can move on to the following instructions.
It is important to remember that a loop must be designed carefully: if the condition never changes and there is no other way to exit the loop, the program could get stuck in the repetition.
How Do These Mechanisms Work Together?
In real programs, sequences, decisions, and repetitions are often used together.
A robot, for example, can continuously repeat these operations:
- Read the value from a sensor.
- Check whether an obstacle is present.
- Stop if an obstacle is detected.
- Keep moving forward if the path is clear.
- Repeat the check.
This simple logic is already enough to describe the behavior of a robot that can react to the presence of obstacles, even though building it will require sensors, motors, and the related code.
In the next sections, we’ll begin learning about the tools we need to write and run our programs, starting with the Arduino IDE development environment.

3.6 The Arduino IDE Development Environment
To write a program, check that it is correct, and transfer it to Arduino, we need a dedicated piece of software called an integrated development environment, known by the acronym IDE (Integrated Development Environment).
The IDE provides the tools needed to work on the program in a single environment, without having to use separate applications for each operation.
What Is the Arduino IDE?
The Arduino IDE is the official program for writing, verifying, and uploading sketches to Arduino boards.
A sketch is the name used in the Arduino environment for a program intended for the board.
The Arduino IDE can be downloaded for free from the official website, arduino.cc, and is available for the major operating systems.
The Main Operations
Throughout the course, we will use the Arduino IDE mainly for three operations.
1. Writing the Program
In the text editor, we enter the instructions that Arduino will have to execute. The program is written in a language based on C/C++ and must follow precise syntax rules.
2. Verifying the Program
The Verify command checks the code and starts compilation, that is, its translation into the form required for the selected board.
If errors are detected, the IDE displays messages that help identify the problem. However, verification does not guarantee that the program will work correctly in every situation: it mainly checks that the code can be compiled.
3. Uploading the Program to Arduino
After compilation, the Upload command transfers the program to the board through the USB connection, when the board and the configuration allow it.
Once the upload is complete, the microcontroller can run the program. In normal operation, the sketch runs directly on the board even after the computer is unplugged, as long as Arduino keeps receiving the power it needs.
Selecting the Board and the Port
Before uploading a program, it is necessary to tell the Arduino IDE which board you are using and which communication port it is connected to on the computer.
For our first exercises, we will mainly use the Arduino UNO R3. We will therefore need to select the correct model and the port corresponding to the connected board.
The port allows the computer to communicate with Arduino. The name and number displayed may vary depending on the operating system and the computer’s configuration.
Our Working Environment
Throughout the course, we will gradually learn to use the main features of the Arduino IDE, without having to know all of its capabilities right away.
To get started, it will be enough to learn how to write a simple sketch, verify it, and upload it to the board. Later, we will also use the diagnostic tools and the Serial Monitor, which lets Arduino and the computer exchange information.
In the next section, we’ll see how an Arduino program is structured and get to know the first instructions of the language, starting with the basic structure of a sketch.

3.7 Introduction to the Arduino Programming Language
Arduino is programmed using a language based on C/C++, two languages that are very widely used in software development and electronic systems.
You don’t need to know these languages already to get started: throughout the course, we will gradually learn the instructions we need to control LEDs, sensors, motors, and other components.
The Structure of an Arduino Program
An Arduino program is called a sketch and, in its simplest form, contains two fundamental functions: setup() and loop().
A function is a block of code that groups a series of instructions with a specific purpose.
- setup() runs only once, when Arduino starts up or is restarted. It is used to initialize the settings the program needs.
- loop() runs repeatedly, after setup() has finished, for as long as the board stays on.
The minimal structure of a sketch is as follows:
void setup() {
** // Initialization instructions**
}
void loop() {
** // Instructions to repeat**
}
The curly braces { } enclose the block of instructions that belongs to each function. Lines that start with // are comments: they explain the code to whoever reads it and are not executed.
The First Instructions
To control the components connected to Arduino, we will use several instructions. Two of the most important to start with are pinMode() and digitalWrite().
pinMode() — Configuring a Pin
A pin is a terminal on the board to which we can connect an electronic component. The pinMode() instruction lets us configure a digital pin as an input (INPUT) or as an output (OUTPUT).
For example:
pinMode(13, OUTPUT);
This instruction configures digital pin 13 as an output, so that it can be used to control a component, such as an LED.
digitalWrite() — Setting a Digital Output
The digitalWrite() instruction lets us set a digital output to one of two logic levels:
- HIGH: high level;
- LOW: low level.
For example:
digitalWrite(13, HIGH);
This instruction sets pin 13 to the high level. If the LED is correctly connected between this pin and GND through a resistor, it will turn on.
With:
digitalWrite(13, LOW);
the pin is set to the low level and the LED turns off, in the circuit described.
delay() — Waiting for a Time Interval
To insert a pause in the program’s execution, we can use the delay() instruction, which takes as its parameter the wait time expressed in milliseconds.
For example:
delay(1000);
This instruction waits about one second before continuing, because 1000 milliseconds equal one second.
The Semicolon
In C/C++, many instructions end with a semicolon (;). For example:
digitalWrite(13, HIGH);
delay(1000);
Forgetting the semicolon where it is required can cause a compilation error.
Toward the First Program
We now have the elements we need to understand a simple sketch: the setup() and loop() structure, configuring a pin, controlling a digital output, and waiting for a set amount of time.
In the next chapter, we will put this knowledge into practice by connecting the first components to Arduino and writing our first program to make an LED blink.

Coming Up in the Next Chapter...
Now that you know the fundamental building blocks of electronics (voltage, current, resistance, and the main components), it’s time to give them instructions.
Chapter 4 – Your First Arduino Program: How to Turn On and Control an LED, we will finally put what we’ve learned into practice with our first project using the Arduino UNO R3: turning on and controlling an LED.
We’ll gather the materials we need, learn how to use the breadboard and identify the LED’s polarity, and then build the circuit by connecting the LED and the resistor to digital pin 13. Next, we’ll write our first sketch using the pinMode() and digitalWrite() instructions and upload it to the board with the Arduino IDE.
Once the LED is on, we’ll make it blink using the delay() function, going through the program instruction by instruction to understand the role of setup() and loop(). Finally, we’ll change the blinking speed and test our knowledge with some hands-on exercises.
If you’re curious to see where this journey will take us, have a look at the page Beginner's Guide to Robotics with Arduino: there you’ll find the full contents list, from the first chapter to the final project, and you can choose whether to carry on in order or go back and review a topic.
If you’ve found this course useful and would like to explore other robotics or hobby electronics projects, you can keep reading by visiting the other content in the Electronics and Robotics section of the site, where you’ll find plenty more practical guides and step-by-step explanations.
I’d like to point out that some of the images in the course were generated by artificial intelligence (AI), and I apologise for any inaccuracies they may contain. The course itself was also written with the help of AI, but the structure is the result of my own experience: I’m a retired programmer and, over the course of my career, I’ve taught several courses. So I chose the topics, organised the whole structure of the course and reviewed the text myself.
I care a great deal about the quality and originality of the content I publish. That’s why I’d prefer it not to be copied or republished elsewhere. If you think this guide could be useful to other people, though, I’ll be really happy if you share the link to the page: it’s the right way to spread the information and to support the work behind every article.
Thank you
Luciano (Capitan Farloc)

English (United Kingdom)
Italiano (Italia)