Logo ilsitodelfaidate.it

1.1 The Program Code

To perform operations, a computer needs to be programmed, meaning it must receive instructions that tell it what to do.
To program a computer, you write a program using a suitable programming language.
A program is often also referred to as program code, or more simply code.
A programming language is not the language the computer uses directly to carry out operations. Computers actually use a language called machine language, made up of instructions expressed in a form the machine can understand and execute directly, but which would be very difficult for us humans to use.
For this reason we use programming languages, which allow us to write instructions in a much more understandable form.
A program written in a programming language must then be translated into machine language before the computer can run it.
This translation, when it is done before the program is executed, is called compilation and is carried out by a program called a compiler.
Arduino also uses a programming language. In our case we will mainly use the C/C++ language, through the Arduino IDE programming environment.

An educational comic-style illustration explaining what a computer is: a system that receives information as input, processes it via a CPU and memory, and produces results as output—sent to devices such as monitors or motors. Designed in the style of a textbook for an Arduino robotics course.

1.2 The I/O Ports

A computer needs to communicate with the outside world. It must be able to receive information and data to process, and it must be able to send out the results of its processing or commands that trigger specific actions.

For example, when we press a key on the keyboard, the computer receives information. When the computer displays an image on the monitor, on the other hand, it is sending information out.

The terms Input and Output are used to describe the operations through which a computer receives or sends data.

Input means information entering the computer. Output means information leaving the computer. The abbreviation I/O, which we will often come across, comes precisely from the initials of Input/Output.

From the computer’s point of view, for example, the keyboard and the microphone are Input devices, because they send information to the computer.

The monitor and the headphones, on the other hand, are Output devices, because they receive information from the computer in order to display or play it back externally.

There are also devices that can perform both functions. A USB flash drive, for example, can be used to read data stored inside it and transfer it to the computer (Input), but it can also be used to write and store new data coming from the computer (Output).

Arduino’s Input/Output Pins

In the world of Arduino we will very often encounter the concept of Input and Output, because the board must be able to receive information from sensors and, based on that information, control devices such as LEDs, motors, buzzers and other components.

To carry out these operations, Arduino uses connections called Input/Output pins, often abbreviated as I/O pins. Through these pins the board can receive signals from the connected electronic components or send commands to them.

On the Arduino UNO R3 board we can mainly use two types of signals: digital and analog.

Digital Signals: HIGH and LOW

A digital signal, in its simplest form, can take on only two logic states, which Arduino identifies with the words HIGH and LOW.

  • HIGH indicates a high logic level, generally associated with a voltage close to 5 V on the Arduino UNO R3.
  • LOW indicates a low logic level, generally associated with a voltage close to 0 V.

We can picture these two states as a switch that can be in one of two conditions: on or off. This is only an example to make it easier to understand, because the actual meaning of HIGH and LOW depends on the connected circuit.

When Arduino uses a digital pin as an Input, it can read whether the signal it receives corresponds to HIGH or LOW. For example, it can detect whether a pushbutton is pressed or released.

When it uses a digital pin as an Output, on the other hand, it can set the signal level to HIGH or LOW. For example, it can turn an LED connected to the pin on or off.

Analog Signals

An analog signal can take on many different values within a range, rather than being limited to the two states HIGH and LOW.

One example is the voltage produced by a circuit containing a photoresistor (also called an LDR, or light-dependent resistor): as the light changes, the voltage can increase or decrease.

The Arduino UNO R3 has analog inputs that make it possible to measure these voltage changes. The board’s internal converter turns the measured voltage into a numerical value between 0 and 1023, when the normal analog reference of about 5 V is used.

This way, the program can distinguish between different lighting conditions and use them to decide how to behave.

However, it is important to know that on the Arduino UNO R3 the analog pins are mainly used to read analog signals. To generate a variable output signal, the board can use a technique called PWM, which we will cover in more detail later in the course.

Why Are These Differences Important?

Let’s imagine we want to build a system that automatically turns on an LED when the light in the room decreases.

Arduino can read the analog value coming from the light sensor and compare it with a threshold set in the program. If the light is too low, it can set a digital output to HIGH to turn the LED on; when the light increases, it can set the output back to LOW to turn it off.

We have therefore used an analog Input to receive information and a digital Output to control a component.

Later on we will learn how to configure the pins, read signals and control devices through the program.

An educational illustration that distinguishes between hardware—the physical components of a computer, such as the keyboard, CPU, RAM, and sensors—and software—the set of invisible programs and instructions that make the hardware function. Basic robotics course for young people.

 

1.3 Bits, Bytes and the Binary Number System

We have seen that a computer’s memory is used to store data and instructions. But how is this information represented inside the memory?

Computers use a binary number system, based on only two values: 0 and 1. This is because the electronic circuits of a computer can easily be used in two different states, for example on/off or presence/absence of an electrical signal.

The smallest piece of information that can be represented in this way is called a bit, short for binary digit. A bit can therefore take only two values:

0 or 1

To represent more complex information, several bits are used together.

The Byte

A group of 8 bits is called a Byte (abbreviated with a capital B).

For example:

10110010

is a sequence made up of 8 bits, and therefore represents one Byte.

Using 8 bits we can represent 256 different combinations, because each bit can take two values. The possible combinations therefore range from:

00000000 = 0

up to:

11111111 = 255

In this way, a single Byte can represent a number between 0 and 255, when it is used to represent unsigned integers.

However, it is important to remember that a sequence of bits does not necessarily represent a number: the same bits can be used to represent, for example, a character, a part of an image, a program instruction or other types of data. It is the way the computer interprets those bits that determines which information they represent.

Binary Numbering

In the number system we normally use, the decimal system, we have ten digits available: from 0 to 9. The value of a digit depends on its position.

In the binary system, on the other hand, we have only two digits: 0 and 1.

For example, the decimal number 5 can be represented in binary as:

5₁₀ = 101₂

In fact:

101₂ = 1 × 2² + 0 × 2¹ + 1 × 2⁰ = 4 + 0 + 1 = 5

For the moment, it is not necessary to learn how to quickly convert all decimal numbers into binary. However, it is important to understand that all the information the computer has to process is ultimately represented through sequences of bits.

Bits, Bytes and Memory Capacity

When we talk about the amount of data a memory can hold, we generally use multiples of the Byte:

  • 1 Byte (B) = 8 bits
  • 1 Kilobyte (KiB or KB) = 1024 Bytes
  • 1 Megabyte (MiB or MB) = 1024 KB
  • 1 Gigabyte (GiB or GB) = 1024 MB

For example, if we say that a memory has a capacity of 2 KB, we mean a memory that can hold 2048 Bytes, that is, 16384 bits.

These units of measurement allow us to describe in a simple way the amount of information a memory is able to store. When we talk about the memories on Arduino, we will therefore be able to better understand what it means to have, for example, 32 KB of Flash memory, 2 KB of SRAM and 1 KB of EEPROM.

An educational comic strip that illustrates a program as a recipe, featuring numbered instructions written in a programming language; these are translated and stored in Flash memory, to then be executed one by one by the CPU.

 

1.4 Computer Memory

A computer’s memory is used to store the data and instructions needed for the system to operate and for programs to run.

There are different types of memory, which differ mainly in how they store information and in how they behave when power is removed.

RAM

RAM (Random Access Memory) is used to temporarily store the data and information the computer is currently using.

It is a volatile memory: when power is removed, its contents are lost.

There are several types of RAM. Among them are SRAM (Static RAM) and DRAM (Dynamic RAM). SRAM is used, for example, in the microcontroller of the Arduino UNO R3.

ROM and Non-Volatile Memory

The term ROM (Read Only Memory) historically refers to memory whose contents are retained even when the device is turned off.

Over time, non-volatile memories that can be programmed and reprogrammed have been developed, such as EPROM, EEPROM and Flash.

EPROM is now mostly a historical technology: it could be erased using ultraviolet light and then reprogrammed.

EEPROM (Electrically Erasable Programmable ROM), on the other hand, can be erased and rewritten electrically, and it retains its data even when power is removed.

Flash is a non-volatile memory that can also be rewritten electrically, and it is particularly well suited to storing larger amounts of data. Today it is widely used in computers, smartphones, USB flash drives and electronic devices.

The Memories of the Arduino UNO R3

The ATmega328P microcontroller, used in the Arduino UNO R3, has three main types of memory:

  • 32 KB of Flash → stores the program;
  • 2 KB of SRAM → temporarily holds the variables and data used while the program is running;
  • 1 KB of EEPROM → stores small amounts of data even when the Arduino is turned off.

So we can remember:

Flash → program
SRAM → temporary data
EEPROM → permanent data

This distinction will be very useful when we start programming the Arduino and see where the different pieces of information used by our programs are stored.

NOTE: The Arduino UNO R3 has 2 KB of SRAM, 32 KB of Flash and 1 KB of EEPROM (referring to the ATmega328P microcontroller).

The 3 types of Arduino memory—Flash, RAM, and EEPROM—explained as storage facilities Alt Text: An illustration of Arduino’s three storage areas: a 32KB Flash "warehouse" (permanent, for the program), a 2KB RAM "warehouse" (volatile/temporary, for data), and a 1KB EEPROM "safe" (permanent, for small configuration settings). Includes an explanation of 0 and 1 bits, as well as 8-bit bytes, within the context of the ATmega328P microcontroller.

 

1.5 The CPU

The CPU (Central Processing Unit) is the component of the computer that executes program instructions and processes data.

We can think of the CPU as the computer’s “processing center”: it receives instructions, interprets them, and performs the operations needed to carry them out.

When we start a program, the instructions that make it up are made available to the CPU, which executes them one at a time in the order set by the program, except when an instruction changes the normal flow of execution, for example to make a decision or to repeat some instructions.

To do its job, the CPU must be able to read instructions and data from memory, process them and, when necessary, produce results that are then used by the program or sent to other components of the computer.

The operation of the CPU can therefore be simplified into three fundamental steps:

  1. Fetch an instruction from memory.
  2. Decode the instruction to understand which operation must be performed.
  3. Execute the requested operation.

This cycle is repeated continuously while a program is running.

However, the CPU does not carry out every operation directly. Inside it there are several units, each specialized in certain tasks.

Among these is the ALU (Arithmetic Logic Unit), which handles arithmetic and logic operations.

CPU Speed

The speed at which a CPU can execute instructions depends on several factors. One of these is the operating frequency, normally expressed in Hertz (Hz) and its multiples, such as Megahertz (MHz) and Gigahertz (GHz).

In simplified terms, the frequency indicates how many times per second the clock signal used to synchronize the CPU’s operations is generated.

For example, a CPU with a frequency of 16 MHz receives a clock signal with 16 million cycles per second.

However, it is important not to confuse the clock frequency with the number of instructions the CPU can execute each second. A single instruction may take one or more clock cycles, and different CPUs can do different amounts of work even when running at the same frequency.

Illustration of the conductor CPU with Central Processing Unit chip in tailcoat conducting with a baton: he reads instructions from the music stand Memory, follows the rhythm of the metronome Clock at 16MHz equal to 16 million cycles per second, and delegates the calculations to the first violinist ALU Arithmetic Logic Unit.

1.6 The ALU

The ALU (Arithmetic Logic Unit) is a part of the CPU that carries out the mathematical and logical operations required by program instructions.

When a program needs to perform a calculation or compare two values, the CPU uses the ALU to carry out the necessary operation.

The simplest mathematical operations the ALU can perform include, for example:

  • addition
  • subtraction
  • increment and decrement

The ALU also performs logical operations, that is, operations that make it possible to process and compare values using binary logic. These include, for example:

  • AND
  • OR
  • NOT
  • XOR
  • Comparison of two values

A very simple example is the comparison of two numbers. If the program needs to check whether:

A > B

the CPU uses its processing units, including the ALU, to perform the comparison and determine the result of the operation.

The result produced by the ALU can be used by the CPU to continue running the program. For example, the result of a comparison can determine which instruction to execute next.

It is therefore important to distinguish between the two concepts:

  • CPU → coordinates and executes the program’s instructions
  • ALU → performs the arithmetic and logic operations the CPU needs

The ALU is therefore not a component separate from the CPU, but one of the units that make up the CPU.

In the case of the microcontrollers used in Arduino boards, such as the ATmega328P found in the Arduino UNO R3, the CPU also contains an arithmetic logic unit that allows it to perform the operations required by programs.

An educational courtroom scene: a CPU judge, wearing a robe and wig, presides over robot defendants A and B. An expert investigator—the ALU—equipped with a magnifying glass and a calculator, delivers a verdict on the comparison "A greater than B," declaring the result "True." The scene illustrates the arithmetic operations (addition and subtraction) and logical operations (AND, OR, NOT, XOR) that take place within the CPU of an Arduino UNO R3.

 

1.7 How the CPU, Memory and Input/Output Ports Work Together

We have seen that a computer is made up of several elements that work together to run a program and carry out the required operations.

A program contains a series of instructions written using a programming language. Before they can be executed, these instructions must be translated into a format the processor can understand, and they are then stored in the computer’s memory.

The CPU (Central Processing Unit) is the component that reads, interprets and executes the program’s instructions. To do this, it uses the information stored in memory and, when it needs to perform calculations or comparisons, it relies on the ALU (Arithmetic Logic Unit), the unit that carries out arithmetic and logic operations.

While the program is running, several types of memory are used, each with a specific function:

  • Flash stores the program even when the computer is turned off.
  • RAM temporarily stores the data needed while the program is running.
  • EEPROM makes it possible to store small amounts of data even when power is removed.

Information is represented inside memory as sequences of bits, that is, 0 and 1 values. Eight bits make up a Byte, which is the basic unit of measurement used to indicate memory capacity.

A computer must also be able to communicate with the outside world. For this reason it uses Input/Output (I/O) interfaces, through which it can receive information from input devices, such as keyboards and sensors, and send commands or data to output devices, such as monitors, LEDs and motors.

We can therefore summarize the general operation of a computer with this outline:

  1. INPUT: the computer receives information from the outside.
  2. PROCESSING: the CPU executes the program’s instructions, using the data in memory and the ALU to perform calculations and comparisons.
  3. OUTPUT: the computer produces results or sends commands to the connected devices.

These operations can repeat continuously, allowing the computer to react to the information it receives and carry out even very complex tasks.

From the Computer to Arduino

The concepts we have just seen are essential for understanding how an Arduino board works.

Arduino uses an electronic component called a microcontroller, which integrates a CPU, memory and Input/Output peripherals in a single chip.

This means that, even though it is much smaller and less complex than an ordinary computer, the principle of operation is essentially the same.

A program loaded onto an Arduino can, for example, read the value of a sensor connected to one of its inputs, process the data using the CPU, and control a motor or turn on an LED through one of its outputs.

This is exactly the principle that will allow us to build our robotics projects: gather information from the environment, process it with a program, and produce actions in response to what happens.

Fundamental principle of robotics:

  • INPUT (The sensor detects something in the environment)
  • PROCESSING (Arduino runs the program and decides what to do)
  • OUTPUT (The motor moves or the LED turns on)

A factory-style layout divided into three zones: Zone 1 (Input) features sensors and keypads that feed data into a temporary RAM storage area; Zone 2 (Processing) consists of a CPU "worker" and an ALU "assistant" that reads instructions from a 32KB Flash memory; and Zone 3 (Output) includes a monitor, an LED, and a motor. An inset at the bottom shows the Arduino ATmega328P microcontroller, which integrates the CPU, Flash/RAM/EEPROM memory, and input/output ports. The fundamental principle of robotics: a sensor detects, the Arduino makes a decision, and the motor and LED take action.

 

Coming Up in the Next Chapter...

Now that we have a general understanding of what is inside a computer and how it works, we can move on to the principles of electronics. We will need them to understand what external components are and how they are connected, especially those connected to the Input and Output ports.

We will cover these topics in Chapter 2 – Electricity and Electronics Basics for Arduino Beginners.

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)

Warning!

The advice and instructions provided on this site come from hobbyists rather than professional technicians, meaning there is no guarantee that they are accurate or represent the best solution.
Additionally, using the tools and techniques described here should be done with careful consideration of one’s own abilities.
These articles assume that the tasks will be performed by individuals with the necessary skills and knowledge to use the required tools safely, without risking harm to themselves, others, or property.
Therefore, the owners of this site cannot be held responsible for any direct or indirect damages resulting from the application of the content found here.
Before undertaking any DIY activity, it is strongly recommended to read the Safety Notice, which provide a basic (though non-exhaustive) list of precautions to follow.

Copyright

The republication of full articles is strictly prohibited. However, it is permitted to publish brief excerpts of the articles or images, provided that the source is clearly credited at the end. This must include a hyperlink directing readers to the original page from which the content was taken.

The site icon ilsitodelfaidate.it was downloaded from 123rf.com. © captainvector, 123RF Free Images

Disclaimer

Privacy Policy

Cookie Policy

Terms and Conditions

Consent Preferences