Basic Course about ARDUINO - Lesson 1

TOPICS INDEX

Warnings

Regarding the safety aspects, since the projects are based on a very low voltage power supply supplied by the USB port of the PC or by backup batteries or power supplies with a maximum of 9V output, there are no particular risks of an electrical nature. It is however necessary to specify that any short circuits caused during the exercise could cause damage to the PC, to the furnishings and in extreme cases even to burns, for this reason every time a circuit is assembled, or modifications are made on it, it will be necessary to do it in power failure and at the end of the exercise it will be necessary to disconnect the circuit by removing both the USB cable for connection to the PC and any batteries from the appropriate compartments or external power connectors. Furthermore, again for safety reasons, it is strongly recommended to carry out the projects on insulating and heat resistant mats that can be purchased in any electronics store or even on specialized websites.

At the end of the exercises it is advisable to wash your hands, as the electronic components could have processing residues that could cause damage if swallowed or if in contact with eyes, mouth, skin, etc. Although the individual projects have been tested and safe, those who decide to follow what is reported in this document assume full responsibility for what could happen in the execution of the exercises provided for in it. For younger children and / or for their first experiences in the field of electronics, it is advisable to perform the exercises with the help and in the presence of an adult.

Roberto Francavilla

Current, Voltage and Electrical Resistance

Let’s start with some theory, but don’t worry I won’t bore you.

To give an intuitive explanation of what electric current and voltage are and how they work, it is useful to think of water. In fact, the current flowing in the electric wires is very similar to a flow of water. The substantial difference between current and water is that, while for water it is the molecules (of water) that flow in the pipes, in the electric wires, it is the electrons (elements that make up the “atom”). This flow of electrons is called “electric current”.

To give an intuitive explanation of what electric current and voltage are and how they work, it is useful to think of water. In fact, the current flowing in the electric wires is very similar to a flow of water. The substantial difference between current and water is that, while for water it is the molecules (of water) that flow in the pipes, in the electric wires, it is the electrons (elements that make up the “atom”). This flow of electrons is called “electric current”.

We can think of electrons as balls and just as water is able to drive water mills, electrons can also drive similar objects, similar to the sort of electron mills. These electron-driven mills can produce light, noise, sound or motion!

So: the current is made up of electrons that flow in a wire and can operate electrical components, which we can imagine as small mills. Electric current is measured in “A” that is in Ampere (we read “amper” because it derives from the French).

Let’s now make the analogy with water more specific, and let’s think of a waterfall that derives from an artificial basin (that is, created by means of a man-made dam). In a waterfall the water descends from the highest point and falls to the lowest point (due to the effect of gravity), where it collects, and there we suppose there is a system of pumps that bring the water just collected back up to the artificial basin after the fall from the waterfall. In this way the water is ready to carry out a new cycle of falling from the waterfall and rising through the pumps. The highest point of the cascade is the one with a “higher potential” (conventionally it is indicated with the “+”), the lowest one is the one with “lower potential” (conventionally it is indicated with the “-“). So the water goes from + towards -, the same thing conventionally does the electric current, that is, it goes from the + (point with the highest potential) to the “-” (point with the lowest potential). This, in electrotechnical terms, is called potential difference (ddp), or also electrical voltage and is measured in “V” that is Volts.

The water in its descent to the valley certainly meets rock, narrowings, becomes a river and finds loops … such elements that oppose the intensity of the flow of water, in electrical engineering, are called “resistances” and they oppose the flow of current electric. Resistance is measured in Ohm, or also indicated with “Ω” (Omega).

Ohm's law.

At this point we can already identify one of the first laws of electrical engineering, that is: with the same voltage (therefore of the jump in altitude of the waterfall), the higher the resistance is (i.e. the more rocks and obstacles to the flow of water are present) and the lower the electric current (i.e. there is less water flow). This law of electrical engineering is called Ohm’s law and is represented as follows:

The inverse formulas are:

and

What is an LED

Although the shape is very reminiscent of an incandescent light bulb, its operation is completely different. In the incandescent light bulb the current passes through a very thin filament of material with high electrical resistance and therefore becoming incandescent, because the electrical resistance tries to prevent the passage of current, the incandescence generates light, but also a lot of heat which is dispersed energy because it is not used for the purpose of better brightness.

Lampadina a risparmio energetico ad incandescenza illuminata | Vettore Premium

In an LED, the current passes through a semiconductor (i.e. a conductor that can conduct current only in a predefined direction) and the material that constitutes the semiconductor, crossed by the current, emits light (i.e. photons).

This method of producing light energy is much cheaper, in fact there is no waste of energy which is transformed into heat and the LED is also more reliable as a light source, because it is not subject to temperature changes that cause the breaking of the filaments. incandescence, as happens with normal light bulbs.

Remember that the LED is a semiconductor, so the polarity with which we power it is important, the anode (i.e. the longest terminal) must be connected to the positive, otherwise it will not light up and if a reverse voltage is applied to it (with interchanged poles ), higher than the allowed threshold, we definitely burn the LED.

In reality, even feeding the LED correctly you risk burning it, in fact you have to be careful not to exceed what is called “junction voltage”, which is why in series with the LED in the previous project we put a resistance of 220 Ohm (I’ll explain later how to determine the correct resistance value according to the LEDs and the number of LEDs to be powered).

The LED, as you can see from the figures above, is made up of two plates between which there is the semiconductor which once excited (ie made to pass through by an electric current) emits photons (ie light!). The platelets end with “terminals” one longer (the anode) and the other shorter (the cathode). Therefore the positive voltage, the one indicated with the “+”, must be connected to the anode, the negative one, indicated with the “-“, must be connected to the cathode. The two plates, with the semiconductor, are then covered with a light-transparent plastic capsule that protects the components and directs the same light outwards.

Project 1 - Turning on an LED

The first project that I would like to introduce is the power supply of a LED.

For this project we need an Arduino, a breadboard, an LED (of any color), a 220 Ohm resistor (the Ohm, also indicated with “Ω”, is the unit of measurement of electrical resistance) and Dupont jumper cables (male-male, i.e. those that have a silver tip on both sides):

Be careful!

The 220 Ohm resistor is identified through the colored rings, in particular if the resistor has 5 colored rings, it must have the rings as follows: red-red-black-black – brown. If the resistor has 4 colored rings, then the colors of the rings must be: red-red-brown and then a silver or gold colored ring. In the next lesson we will learn how to read the resistance values using the color table.

Resistance to 5 colored rings

Resistance with 4 colored rings

For the LED, pay attention to the terminal pins, one is longer and one is shorter:

NOTE: The longer terminal (anode), in the connection diagrams is represented “bent” ……

The connections to be made are:

If everything has been connected well, when you insert one side of the USB cable to the USB port of the Arduino and the other side of the cable to the USB port of the PC, the LED should light up, because it is powered.

At the bottom there is the electrical symbol of the LED and the classic electrical connection circuit by means of a resistor:

In the electrical circuit the resistor can be placed before or after the LED, it does not matter because the two components are crossed by the same current “I” (they belong to the same electrical branch), the voltage drop across the resistor is identical. This method of connecting the resistor to the LED is called, in electrotechnical terms, “in series”, the meaning will be seen better later.

So, with this project, you are starting to have your first contacts with the world of electrical engineering and electronics, but let’s take a closer look at what we have done.

Basically to a passive element, such as the LED, [passive element means that it needs electricity to work], we have applied an electrical voltage. The electric voltage is also called FEM (electromotive force), in fact it indicates how strongly we push the electrons to come out of their orbits and to create that flow called electric current. The electric current thus generated, passing through the semiconductor material that makes up the LED, transfers this energy to the same material which transforms it into “photons”, that is, into light.

So Arduino worked as a power supply, that is energy supplier, the electric wires made sure that this energy was transferred to what is called the user, that is the LED.

A part of this energy is dissipated in the resistance in series with the LED in the form of heat, this to reduce the amount of energy otherwise it would be too high and there would be a risk of burning the LED.

Video-project 001 - Lighting of an LED

The Button: how it works and how to use it

Before moving on to the next project it is good to see how it works and how to use a very important component: the button.

The principle of operation of a button is very simple and the animated gif below visually summarizes this operation.

The button consists of a movable and a fixed part, the movable part consists of a metal blade fixed to a plastic support which is the button of the button that will be pressed, below this blade there is a spring that holds pushed up the mobile part.

The fixed part, on the other hand, is made up of two separate blades that continue forming the feet of the button. The whole is enclosed in a plastic case.

When the button is pressed, the spring compresses and the movable blade brings the two fixed blades into contact. If an electrical voltage is applied to one of the two blades (indicated with the “+”), this voltage is also transferred to the other blade, so there is what in electrical jargon is called “closure of an electrical circuit”.

The buttons we use are characterized by having 4 pins (or also called terminals) of which they are in two by two metallically connected to each other.

So connecting pin A or pin C is the same thing, as is pin B with respect to D. The pins that are metallically separated, as also shown in the figure above, are the closest to each other, i.e. pin A is separated from the B, as C is separated from D.

Another type of push button, but whose functionality is identical to the one seen above, is the two-terminal button:

However, now let’s run a project that better than anything else illustrates how the button works.

Project 2 - The use of a button to switch on an LED

In this project I want to show you how to power an LED through the use of a button that will allow us to turn the LED on and off at will.

The material needed for this project is identical to the previous one, but we also need a micro button.

Let’s proceed with the connections as shown in the diagram below, keeping the USB cable disconnected from Arduino. In particular, it is necessary to pay attention to the longer terminal of the LED which must be connected in series to the 220 Ohm resistor. The resistor in turn is in series with the button terminal. The red dupont cable that carries the 5V, must be connected to the other terminal of the button and the yellow dupont cable must be connected to the Arduino GND and to the cathode of the LED.

If everything has been connected well, when you insert the cable to the USB port of the PC, the LED should be off and by pressing the button it lights up, because only by pressing the button the LED is powered, i.e. the button closes the circuit and gives electrical continuity .

Video-Project 2 - The use of a button to switch on an LED

Now let’s try to understand what we have done.

Let us remember the flow of water from a waterfall, or from a river.

With the insertion of the button we have done nothing but place a dam, that is an obstacle that cannot be crossed by the water and only when the pipes are opened, the water flows through the waterfall. Then the button stops the flow of current with a circuit break, only when it is pressed does the circuit reset and the current can flow into it.

Another example to understand the function of the button is to imagine that you have a tap, only when you open the tap does the pressure difference be created such as to let the water out (and therefore circulate the current).

IMPORTANT: I would like to point out that I used the term conventional direction of the current, this is because at the time of the studies of this phenomenon it was thought that it was the positive charges that moved from + towards – (because they were attracted by the opposite sign), actually subsequently it was found that electrons generate the current flow and since they have a negative charge, they are attracted to the positive pole, so the current actually goes from the negative pole to the positive pole, but conventionally we have continued to maintain the convention that the current goes from + towards -.

Curiosity: A bit of scientific history

In 1799, the Italian scientist Alessandro Volta (hence the name Volt for the unit of measurement of voltage), who had studied for years the then mysterious phenomena of electromagnetism, managed to build a first, rudimentary but effective electric battery.

In the early 1800s Charles Augustin de Coulomb discovered that electrons, sub-atomic particles with a negative electric charge, are naturally attracted to areas where the electric charges are of lower intensity, and therefore can be seen as ‘holes’, valence positive.

In the mid-1800s, around 1860, the French physicist André-Marie Ampère, one of the leading scholars of electromagnetism, gave the name to the unit of measurement of electric current.

The Ohm (symbol: Ω) is the unit of measurement of electrical resistance, its name derives from that of the German physicist Georg Simon Ohm, who discovered Ohm’s law of the same name. In fact, in 1827, his main discovery was that the electric current flowing through a conductor is directly proportional to the voltage applied to its ends. Obviously I have mentioned only a few physicists, in fact between the beginning and the end of the 1800s, there were 100 years of exceptional scientific discoveries in the field of electrotechnics, electronics and electromagnetism.

In 1889, after the agreement of various states, the International System was born in Paris, that is, the units of measurements “meter [m]“, “kilogram [kg]” were attributed to fundamental physical quantities such as: length, mass and time. and “second [s]”, then over time the following were added: degrees kelvin [K] for the temperature, amperes [A] for the current, candela [cd] for the luminosity and mole [mol] for the quantity of substance. These are the units of measurement that all scientists use to exchange information and scientific research around the world.

What is a Breadboard.

The Breadboard is for a maker like the blank canvas for a painter…

[Roberto Francavilla]

The Breadboard is a base in insulating material with many small holes. There are different sizes on the market, the most common being the 400 hole one. The various holes are electrically connected to each other in a particular way that I will show you later. Basically, the terminals of the various electronic components are inserted into these small holes and without welding, therefore with a considerable saving of time and above all of re-use of the components, it allows the connection between the various electronic components.

In fact, the Breadboard is used to test the functionality of the circuits that makers develop with the possibility of reusing components and with the speed of modifying and testing different circuit solutions. As can be seen from the photo, the metal strips arranged horizontally and vertically allow connections between the holes of the same horizontal and vertical row.

The columns of the Breadboard are identified by numbers, the rows by capital letters.

The only rows whose holes are all electrically connected to each other are those identified with the “+” and “-“. The holes of the other rows (A, B, C, D, E, F, G, H, J), as seen from the photo above and from the lines of the figure, are not connected to each other horizontally, but they are in vertical direction, i.e. in a column. This means that inserting a pin in column 6 to any staff in the group between A and E is the same thing. The Breadboard, as you can always see from the figure, is divided into two parts isolated from each other.

Immagine correlata

Project 3 - Hello World

With this project we begin to use Arduino in its true functionality, in fact in projects 1 and 2 our board for Maker was used as a simple battery (power supply), now we will use it for what it is, that is a development board with a microcontroller powerful and flexible.

For the project we will only need an Arduino development board and a USB cable. This project is not only a communication test between our Arduino board and the PC, but also a basic project in the Arduino world that introduces programming.

And as usual, when you start learning a new programming language, one of the first things to learn is to have our system that we are programming write the phrase “Hello Word”.

Then we connect our development board to the PC via the USB cable and launch the Arduino IDE application by double clicking on its icon.

An empty window opens, or you need to open a new empty one:

We type the sketch below in the window:

Once the sketch has been written, first click on the “V” (check mark), if there are no errors *, then upload it to Arduino by clicking on “->” and finally, once loaded, click on the lens (top To the right).

The Serial Monitor window appears:

Whenever we type the R (capital) and then on Send (or Send), the message Hello World! Appears on the Serial Monitor.

* In the event that by clicking on the check mark you should get an error, then there can be three possible causes:

  • Incorrect typing of the sketch, so double-check the individual lines paying attention to the “;” at the end of the instructions or at the double lines for comments… we will talk about this in detail later on.
  • Incorrect configuration of the serial port on the PC, in this regard, I invite you to see the procedure provided in the initial activities of the Course
  • Incorrect installation of the development board driver, in fact some compatible Arduinos install microcontrollers that require special drivers to be installed on your PC in order to be seen from the serial port. Also for this problem see the procedure foreseen in the initial activities of the Course.

Video-Project 3 - Hello World

Arduino digital PINs

Before proceeding with the next project it is useful to know what digital PINs are and how they work on our development board. The Arduino board has 14 digital PINs.

The digital PINs are particular PINs that can function as an input for Arduino or even as an output (the same PIN cannot function at the same time as an input and an output) and is characterized by the fact that it can only assume two values: High – High state or 5 V and Low – Low status that is 0 V. Some digital PINs (to be exact 6) are indicated with a wave “⁓”, these digital PINs are characterized by the fact that they can produce a PWM type signal, but we will talk about this more in there.

In the next project we begin to see the use of Digital PINs.

Project 4 - Police car with flashing lights

This is a simple project that shows the use of Arduino digital PINs.

For this project we need:

With this project we also learn the use of electrical diagrams and symbols to be used to represent the various components. The wiring diagram to be made is the following:

For the connections, instead, refer to the assembly diagram below:

After the connections we move on to write the sketch.

Connect the Arduino to the PC via the USB cable and launch the Arduino IDE application by double clicking on its icon as done previously and create a new window with a new sketch.

Type the sketch below in the window:

Once the code has been written, launch the verification precompilation (check mark), it will ask you to save the sketch (you can change its name) and then click on the arrow to load:

 

The result will be that the two red and blue LEDs, alternately, will turn on and off after every second.

If you position the police car, previously printed and cut out, in such a way that the two LEDs come out from the top flashing light of the car, by drilling two holes at an appropriate distance for how the LEDs are positioned, you will get a beautiful effect.

Video-Project 4 - Police car with flashing lights

If you found the lesson interesting, make a donation you will help me realize many others.