Basic Course about ARDUINO - Lesson 7



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

Active and Passive Components and Series and Parallel Elements

With this Lesson we explore some very important aspects of electrical engineering that will help us understand many things about the electrical circuits that we have already made so far.

The Active and Passive components.

Components are the basis of electronic devices. They can be divided into active components and passive components. The definition of active or passive component in the bibliography (i.e. as it is described in books) is not always clear, indeed it is sometimes even contradictory.

As far as we are concerned, the definition I know and which I consider most relevant refers to the ability to enter or use energy in a given circuit, namely:

A component is said to be ACTIVE if it enters energy into a circuit, while it is PASSIVE if the component uses the energy introduced into the circuit.

To give some examples: a battery is an active component (because it inputs electricity), on the other hand an LED (it uses electricity to emit light, but also heat), a resistor (it uses electricity and produces heat), a servomotor (uses electrical energy and produces movement, but also heat),… so these are all passive components.

Series and Parallel connection of components.

A component is normally identified by two terminals, one indicated with the “+” and the other indicated with the “-” or even “GND”, these terminals identify the conventional direction of the current, entering from + and outgoing from -. The component with two terminals is called a “bipole”.

If we connect several bipoles together in such a way that the incoming terminal of one connects to the outgoing terminal of the other, there is a Series Connection.

In the series connection, all the components are passed through by the same current “I”.

If we connect more bipoles by joining the “+” and “-” terminals together, there is a Parallel Connection.

When connected in parallel, all components are subjected to the same voltage “V”.

The Series and Parallel Connection of Resistors.

For the moment let’s focus on the passive components and among these let’s see in detail what happens if we connect resistors in series or in parallel.

The connection principle is the one already described in the previous paragraphs, so let’s start immediately by making some examples to better understand.

First of all, let’s review what happens if we apply a voltage V to a resistance R:

By applying a voltage to the Resistance R, an electric current I is created which is calculated using Ohm’s Law:

Suppose we now have two 100 Ohm resistors connected in series and a voltage of 5V is applied to them:

When two resistors are in series, they behave as if there was a single “equivalent resistance” which is given by the sum of the two resistances, for which Req = 200 Ohm.

At this point, again with Ohm’s Law, we can calculate the current delivered by the 5V battery by applying the formula:

Substituting the letters for the numerical values:

Therefore, the current circulating in the circuit thus made is 0.025 A, i.e. 25 mA.

Now let’s calculate the voltage applied to the first resistor, again with Ohm’s Law:

from which:

The voltage applied to the second resistor is calculated by making the difference between the total voltage applied to both resistors, minus the voltage created on the first resistor. The calculation shows that also on the second resistance there is a voltage of 2.5V. Therefore a voltage of 2.5 V is applied to the individual resistors, that is half of that supplied by our battery.

Now suppose instead of having the two resistors in parallel:

In this case, the equivalent resistance of two resistors in parallel is calculated with the formula:

hence, by calculating the least common multiple and solving the sum of two fractions:

replacing the numerical values:

From which:

Let’s now calculate the current “I” with Ohm’s Law:

So putting two equal resistors in parallel means having an equivalent resistance equal to half the value of the single resistor that connects in parallel. While the current will be I = 0.1 A, i.e. 100 mA (i.e. 4 times higher than the previous circuit).

So be careful to put the resistors in parallel, you risk burning the components and our Arduino !.

And if the resistances are different, for example with value R1 and R2? Applying the previous rule, we obtain:

However, the resulting value for the equivalent resistance is less than the smaller resistance value of the two resistors. In fact, if for example the R1 is 100 Ohm and the R2 is 10 Ohm, the Req = 9.09 Ohm.

I wanted to insist on this theoretical part, a bit boring due to the presence of so many calculations, to make you understand two important concepts:

  • If we put two resistors in series, the current circulating in the circuit is reduced and a voltage lower than that generated is applied to each resistance (in technical terms, when the current passes through a resistor, it is said to cause a voltage drop).

In fact, the principle by which we put a resistor in series with an LED (considering the LED as if it were a resistor, because it has its own internal resistance) is precisely this, that is to reduce the voltage applied to the LED and therefore reduce the current that passes through.

  • If instead we put two resistors in parallel, the voltage applied to the resistors is always the same, i.e. that of the battery, the value of the equivalent resistance is reduced and consequently the value of the current delivered by the battery increases. So with Arduino we are very careful to insert resistors in parallel, because beyond certain current values ​​it cannot withstand and therefore burns out.

The voltage divider and the potentiometer

In the previous Lessons we have already used both the divider and the potentiometer, they have been used in specific applications such as, for example, in detecting the voltage across a photoresistor (use of the voltage divider) or to vary the light intensity of a RGB LEDs (use of the potentiometer), but we have not yet seen in detail their actual operation and their field of use, in this Lesson, after having seen what it means to put resistors in series and in parallel, we deepen these aspects.

The voltage divider

Sometimes it happens to have to create reference voltages for electrical measurements, as was the case with the photoresistor. To do this, just apply two very important laws of electrical engineering, one you know well by now and it is Ohm’s law which tells us that by applying an electric voltage to a resistor, it is crossed by an electric current given by the formula:

Or, interpreting the law in the opposite way: a current “I” flowing through a Resistance “R”, produces a “voltage drop V”, that is:

This principle of producing a voltage drop is used to create a reference voltage in electrical measurements. For example, suppose we want to create a reference voltage of 2.5 V starting from a voltage of 5 V, then (without having to repeat all the calculations already seen before), just put two resistors in series of equal value (for example from 100 Ohm) and the reference voltage across one of the two resistors is exactly 2.5 V.

The voltage across the R remains constant at 2.5 V only if you read it with an instrument called a voltmeter or with an Arduino (for example: using one of its analog pins), but if you want to use this voltage to power a load at 2.5 V, the value across the R changes, depending on the load we are going to connect (in parallel with R!).

The Potentiometer (for electronic applications it is called Trimmer)

The operating principle of a potentiometer is equivalent to a voltage divider, with the particularity that thanks to a knob it is possible to modify the resistance and therefore modify the voltage at the central point.

The operating principle of a potentiometer is equivalent to a voltage divider, with the particularity that thanks to a knob it is possible to modify the resistance and therefore modify the voltage at the central point.

  • Black element = wire with very specific characteristics and resistivity wound on insulating material and is called Fixed resistance.

  • Green element = cursor of conductive material and it is the sliding contact that rotates thanks to the knob.

    Basically, by varying the position of the central cursor with the knob, we do nothing but increase the length of the wire on which the current flows and therefore the resistance of the conductive material which is given by the following formula:

Where R is the resistance, “ρ” (pronounced “ro ‘”) is the resistivity of the material that constitutes the wire wound on the insulating material, “l” is the length and “s” is the section of the wire wound on the insulating material .

When the potentiometer is applied in low power circuits, such as those made by us, it takes the name of Trimmer, therefore between the Trimmer and the Potentiometer there are no substantial differences in their operating principle, but only constructive and therefore in the ability to be crossed by currents with higher values, for the potentiometer, compared to the lower ones for the trimmer.

Therefore the potentiometer is used in higher power circuits than those for which the trimmer is used.

Project 23 - The use and connection of the Potentiometer

For this project we need:

The purpose is to modify the voltage applied to an LED, thanks to the potentiometer, and then vary the brightness manually by acting on the knob of the same potentiometer.

To achieve this effect, on the basis of the knowledge acquired so far, we can create the following circuit:

The assembly scheme to be made is the following:

Pin 1 of the potentiometer is connected to the 5V of Arduino, from pin two you connect the anode of the LED (yellow) to which the classic 220 Ohm resistor has been connected in series. Finally, the third pin of the potentiometer is connected to ground (GND) through a 220 Ohm resistor.

By varying the resistance, or by turning the knob on the potentiometer, you can see the brightness of the LED vary, in fact, in this way, we have inserted another resistance of variable value in series with the LED resistance; the greater the resistance, the higher the voltage drop across the resistors and therefore the lower the voltage applied to the LED and therefore the lower brightness.

I would like to point out that in series with the third pin of the potentiometer, before connecting it to ground, I inserted a 220 Ohm resistor, this is because the Potentiometer has a variable resistance (in theory from 0 to 10 kOhm, or from 0 to 1 kOhm, it depends on the type of potentiometer we use), for low resistance values ​​Arduino would deliver high currents with the risk of burning it, however, putting a resistance in series, however even when the potentiometer assumes low values, we are limiting the supply of current.

Video-Project 23 - The use and connection of the Potentiometer

Curiosity: what is the temperature and what is the humidity

Temperature is that quantity that indicates the thermal state of a body or an environment, that is, how hot or how cold that particular body or environment is. The unit of measurement is the degree Celsius [° C] or better, in the International System, it is measured in degrees Kelvin [° K].

Humidity is that quantity that indicates how much water vapor is present in a given environment and is measured in percentage terms. With 0% humidity there is a dry and dry environment. In practice, 100% humidity is immersed in water vapor.

LM35 Temperature Sensor

The sensor is calibrated to give the results in ° C, so if we want the ° K it is necessary to convert them with the formula that says: 0 ° K = -273.1 ° C, that is, if we have 27.9 ° C, these correspond to 300 ° K. The applicable voltage ranges from 4V to 30V, but we will of course use it at 5V. For every 10 mV measured, we have 1 ° C. Since the function is linear, as you can see from the data-sheet graph, just measure the output voltage Vout with Arduino and apply the simple formula:

Project 24 - Taking the temperature of a body.

For this project we need:

The wiring diagram for the connection is:

The assembly diagram is:

Click on the Arduino icon and after opening a new file we copy the sketch shown below:

Once the sketch has been loaded and the serial monitor activated, the temperatures of the objects that are in contact with the sensor will be detected. As for the sketch, since there are no particular things to highlight, no analysis is carried out.

Video-Project 24 - Detecting the temperature of a body.

Project 25 - Luminous thermometer.

On the basis of the previous project, we create a fun luminous thermometer where we will use a decision algorithm based on the “switch-case” function, to establish whether a body is: cold, at room temperature, hot, or hot.

For this project we need:

The wiring diagram for the connection is:

The assembly diagram is:

Click on the Arduino icon and after opening a new file, copy the sketch shown below:

At this point we load the sketch on Arduino and with the tip of the sensor we touch the different bodies to measure their temperature. Depending on the temperature range measured, a particular colored Led will light up: Blue Led = cold, Green Led = room temperature, Yellow Led = hot, or Red Led = hot. We can enrich the project by also putting a cardboard with holes for the LED head and writing the detected temperature range on the cardboard.

Video-Project 25 - Luminous thermometer.

Analysis of the Sketch: Project 25 - Luminous Thermometer

Also for this sketch the control structure switch (..)… .. case… was used; which we review as being a very important facility.

This method of making decisions by the computer is used especially when there are many cases to be examined and on which to decide which actions to take. The use of the switch … case … simplifies the structure, in fact it is enough to define for each individual case what to do and then the selection of the case is done directly to the switch function. The general syntax of the control structure according to the Arduino Reference Book is:

switch (var) {

  case label1:

    // statements


  case label2:

    // statements



    // statements



Where var is a variable of type int or char and indicates the number of the “case” you want to process, while label1 is the label, also a variable of type int or char. In the syntax example there are only three cases, one of which is default. The last case, the default one is selected when there is none of the previous cases. The structure may also have a higher number of cases than those represented.

The DHT11 sensor for detecting the temperature and humidity of the environment

Sometimes it is necessary to detect the Temperature and Humidity present in an environment and according to these values it is possible to adjust the heating or air conditioning to achieve what is called the “optimal thermal comfort” of the environment .

The DHT11 sensor is nothing more than a mini-arduino where, thanks to its sensors and the presence of a processor, it is able to provide, in digital format, the temperature and humidity value.

Why did I want to clarify this aspect? The reason is that, like Arduino, even the DHT11 having a processor and sensors, in turn, would require specific programming and also in a particularly complicated language making the use of the DHT11 only for a select few. Instead, thanks to the presence of millions of makers like you, the use of the DHT11 sensor module is very simple as there are “Libraries” of instructions that thanks to which we can query the sensor module without worrying about writing hundreds of lines of code program in complex language.

Now let’s see how the DHT11 sensor module is connected:

As you can see, the Module has the third pin from the left which has no function and therefore should not be connected to anything.

A 4.7 kOhm resistor is normally connected between the pins of the Vcc and the Data:

Pay attention that on the market there are DHT11 sensor modules, mounted on a base, with the 4.7 kOhm resistor already connected and above all with only the 3 PINs needed.

Before moving on to the practical project, I would like to remind you that for the DHT11 it is necessary to add the related library to the IDE. In this regard, I refer to the paragraph:

What is a Library and how to add it to the IDE“.

Project 26 - Ambient temperature and humidity.

For this project we need:

The wiring diagram for the connection, in the case of using the sensor, is:

In case of use of the Sensor Module:

For the assembly diagram in the case of using the 4-PIN sensor:

In case of using the sensor module with 3 PINs):

Warning: Since there is no standard, pay attention to which PIN is attributed the abbreviation “S” or “DATA”, as well as the one with the “+” or “Vcc” symbol where they will connect respectively to the Digital PIN 4 and to the 5V of Arduino.

The sketch to be written (directly derived from the example in the Library):

Then, once the sketch has been loaded and waiting a couple of seconds, the values are printed on the Monitor Serial.

Video-Project 26 - Ambient temperature and humidity.

Analysis of the Sketch: Project 26 - Ambient temperature and humidity.

It is important to highlight, because it is very important, the insertion of the Library with the “#include” command

#include “DHT.h”

In addition, it is necessary to specify which sensor you are using because the same library contains multiple types of sensors, for which you need the instruction:

#define DHTTYPE DHT11   // DHT 11

and then you need to create an object called dht:



from that moment in the void loop () we can put the instructions that read the digital values of the temperature and humidity.

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