Arduino Microcontroller Practical Handbook
Arduino Microcontroller Practical Handbook
1
Preface
This booklet of practical work is addressed to second-year undergraduate students.
fundamental in electronics (Bachelor's in Embedded Systems and Bachelor's in Electronics)
Industrial). This support includes four manipulations to take control of programming on
the Arduino IDE software and communication with the Arduino Uno board. After this lab (having
as a load of 10 hours and a half per semester), students will be able to accomplish several
prototypes using Arduino microcontroller. It is noteworthy that this document includes a
section "Introduction to Arduino" allowing students to be able to realize the
practical work requested in the four proposed experiments.
The first manipulation involves knowing how to use and manage inputs/outputs.
digital pins of the Arduino Uno board. At this stage, the student will create several applications with
the Arduino board.
The second exercise allows students to learn how to use and manage input/output.
analog pins of the Arduino board.
2
Summary
Introduction to Arduino ....................................................................................................4
Manipulation 3: Display on the Liquid Crystal Display I2C, the display Seven
segments 5011 AS and the LED matrices (8x8) with MAX7219 .................................22
3
Introduction to Arduino
Arduino is an open-source electronic prototyping platform designed to be
accessible to beginners in electronics and programming. The platform is based on a
electronic card equipped with a microcontroller and a variety of input/output ports that
allow users to connect sensors, actuators, and other components
electronics.
The Arduino programming environment is also open-source and uses a language
simplified programming based on C/C++. Users can write programs
using the graphical interface of the programming environment, which allows them to
select functions and variables from drop-down menus, rather than having to
write code from scratch.
Thanks to its ease of use and its large online community, Arduino has become a
very popular platform for creating interactive electronic projects, whether for
rapid prototyping of concepts or for more advanced projects requiring integration
complex material.
1. Description of the Arduino board
There are different models of Arduino boards. Each model is characterized by a specification.
technique and a specific price. Let's give a few of them:
One: This is the most popular version, ~ 23.80€;
Mega: It is the most used version after the UNO, it is characterized by a
larger number of pins, ~ 45.60€ ;
Nano: This version of the cards is characterized by its minimized size. These
characteristics are slightly below the UNO card, on the contrary, it is impossible to
power it differently than via USB connection, ~ €22.80[1].
In this lab, we use the Arduino Uno board shown in figure 1, including a
ATMEGA328 microcontroller powered at 5 V. This board has 14 input/output pins.
digitals, 6 of which are usable in PWM (Pulse Width Modulation or MLI for modulator)
(of impulse width). These 14 pins can be used as input or output under control
of the program. Similarly, the Arduino board includes 6 analog inputs (A0....A5). The
The microcontroller has an analog-to-digital converter (ADC) with 10 bits of resolution.
4
Figure.1: Arduino Uno Map [2]
The maximum current delivered by the Arduino board is 0.40 mA. Therefore, we can calculate the
maximum power by the following relationship: P=U*I.
2. The microcontroller
The Arduino Uno board is essentially based on the ATMEGA328 microcontroller.
(ATMEGA microcontroller from the 8-bit AVR family) which will receive the program written in
Arduino language and stores it in its memory before executing it.
5
With this microcontroller, several industrial applications can be executed.
Indeed, microcontrollers have reduced performance, but they are characterized by a low
size and reduced energy consumption making them fundamental in systems
embarked (robots, cars). An internal architecture of the ATMEGA 328 microcontroller is
given by figure 2.
3. The Memoirs
To store the program to be executed, the Arduino microcontroller contains memory.
32KB flash. Similarly, it has SRAM volatile memory for storing results.
temporary during calculation. The ATMEGA 328 also integrates an EEPROM memory of size
1ko allowing to program the storage of data persistent
[2].
4. Digital inputs/outputs
The inputs/outputs are the means by which the Arduino board can communicate with
the outside. The inputs are read by the Arduino microcontroller to determine the state of the
system to which it is interconnected. The outputs are controlled by the microcontroller.
allowing actions to be performed (turning on/off a LED, activating a motor...). The board
Arduino includes 14 digital I/O (D0...D13). Pins D0 and D1 are reserved for the
communication series so they should not be used. The digital outputs cannot
deliver a power greater than 40 mA.
6
5.2. The analog outputs
On the Arduino board, there are no true analog outputs. Some pins
Digital outputs can be used as analog outputs using the PWM technique.
(see figure 4). Pins 3, 5, 6, 9, 10, and 11 can provide a voltage between 0V and 5V. The
The average voltage value is 2.5 V with a duty cycle of 50%. The Arduino board
varies the average value of these pins with an 8-bit sensitivity to give an integer
between 0 and 255the
andport provides an average voltage between 0 and 5V.
6. Food
The Arduino board can be powered at 5V through the USB port or by an external power supply.
(per Pile) which is between 7V and 12V. The USB cable (figure 5) allows both the power supply
from the card and the serial communication with it.
7
7. The connection cables
The Arduino board does not incorporate other components such as resistors, motors,
diodes except for pin 13... To carry out several applications, they need to be connected to the board.
This connection is made by cables (figure 6).
8
9. The resistors
A resistor is an electronic component mainly used for the purpose of
protection for the other components (to prevent components from burning out). The resistor R is
calculated by the equation. 2:
R=U/I (ohm). (Eqt.2)
To select the resistor R to be used in the prototype, one must refer to the
Color code presented by figure 8 using equation 3.
10. LEDs
The LED diode (figure 9) is an electronic component that allows current to pass in only one direction.
one way. Electric current can only flow through the diode from the anode to the
cathode.
9
the cardArduino. The programming interface is shown in figure 10:
Program
10
12. The stages of program development and uploading onto the
Arduino Uno board
The steps for uploading a program to the Arduino UNO board are given in figure 11.
[21].
Develop an Arduino code under Arduino IDE Compile the program using the compile button and verify
that the code does not contain errors. If there are no errors the console
display: "compilation completed".
12
MANIPULATION 1
3. Practical part
Exercise 1: Make an LED blink
13
2. What is the role of resistance?
3. Write an Arduino program to make an LED connected to blink.
digital pin number 13 of the Arduino Uno board. This LED must remain on during
2 s and turned off for 1 s.
3. Flash the LED 10 times to create a light SOS signal.
Exercise 2: Make four LEDs blink at the same time: one after another
the other
1. Carry out the assembly of the following figure noting that the resistors used have the value
220/470 ohm. The LEDs are connected to pins 10 to 13.
2. Write the Arduino program to make four LEDs blink at the same time.
3. Modify the program to make the four LEDs blink in a sequential manner (one
after the other).
14
Figure 15: Wiring for light rotation [7]
Lights 1
Lights 2
15
Fire 1: The red LED (R1) is connected to Pin 5, the yellow LED (J1) is connected to
Pin 6 and the green LED (V1) are connected to Pin 7 of the Arduino.
Fire 2: The red LED (R2) is connected to pin 8 and the yellow LED (J2) is connected to
pin 9 while the green LED (V2) is connected to pin 10.
2. Program code to turn on the LED when the push button is pressed and to
turn it off in the opposite case. Try to do the opposite by reversing the polarity.
3. Propose a program that allows the realization of a dual buzzer based on two buttons.
pushbuttons and two LEDs. The principle is that when one presses a pushbutton,
The corresponding LED lights up. If we press button 1, the LED lights up and if we press
On button 2, LED 2 lights up.
16
MANIPULATION 2
3. Practical part
Exercise 1: Read the temperature using an LM35 temperature sensor.
17
Figure 17: Assembly for reading temperature using an LM35 sensor [10]
Figure 18: Montage to vary the intensity of an LED with a potentiometer [11]
3. Write the Arduino program for blinking the LEDs (red, green, and
yellow) according to the temperature variation. Open the serial monitor for the
verification.
18
If the temperature is below 30 then the green LED is on.
If the temperature is between 30 and 40 then the red LED is on.
If (temperature above 40) then the yellow LED is on.
3. Code in Arduino to run two motors in one direction for 5 seconds with a
constant speed then in the opposite direction with a delay of 2s.
19
Make two motors turn in the same direction at different speeds:
(100%, 75%, 50%, and 25%) of the maximum speed for 5 seconds.
Stop the engines for 3 seconds.
- Run both motors in the opposite direction for 5 seconds.
Stop the engines for 3 seconds.
5. Carry out the assembly using the simulation tool ISIS.
20
6. Program an Arduino code to control a motor via the board
Arduino. A push button is used for the operation of the motor. A press on
The push button ensures the operation of the motor; otherwise, the motor does not work.
21
MANIPULATION 3
Affichage sur l’écran LCD I2C,
the Seven Segment Display and the Matrices
Leds.
4. Connection wires.
5. 2 LED Diodes
2. Practical Part
22
Figure 22: Setup for LCD display [16]
3. Add the Liquid Crystal library to control I2C screens.
4. Write the Arduino program to make the three LEDs blink according to
the temperature value controlled by the potentiometer and display this value
on the I2C LCD screen. The LEDs are connected to pins 11, 10 and
9 from the Arduino board.
5. Reassemble the setup using ISIS.
respectively to 6, 5, 2, 3, 4, 7, 8 and 9.
Figure 23: Setup for displaying numbers on the Seven Segment display [17]
23
5. Add the SevSeg library that allows controlling all the segments of
circuit 5011 AS.
6. Write the Arduino code to display all the numbers from 0 to 9 on the
common cathode device.
Figure 25: Assembly for displaying messages on the LED matrix [18]
4. Include the library for the MAX7219 device that allows control of the matrix.
5. Program an Arduino with code to display letters on the LED matrix.
(8x8).
24
MANIPULATION 4
Command robotic cars by
an Android application
4. Connection wires.
5. LED Diodes
7. 4 DC 5V motors.
8. H Bridge L298N
9V Battery
10. Bluetooth Module HC-05
11. Smartphone
3. Practical part
Exercice 1: Controller un dispositif (Led) avec un-Smartphone Android
using a Bluetooth module
25
For uploading the program, the Rx and Tx pins of the Bluetooth module will be
connected to the Arduino's serial connection pins Tx (pin 1) and Rx
(brooch 0).
Note well: You need to swap the Rx and Tx pins between the Arduino board and the module.
Bluetooth. When uploading, you must disconnect the Rx and Tx pins.
Figure 26: Montage for controlling an LED via smartphone using HC-05 module [19]
26
2. Write the Arduino code to control four motors using the Arduino board and
the Shiel L298N module. We want to turn the motors of the robotic car forward, in
backward, to the left and to the right with a maximum speed.
3. Modify the code to control the movement of the motors based on the state of a button.
push button. If a push button is pressed, then the motors run otherwise the motors are
in blocking mode.
27
References
[1][Link]
[2] [Link]
[3] This link leads to an article about the ATmega328 microcontroller, detailing its features, specifications, and applications in various electronic projects.
[4] [Link] [Link]/cours/electronique/resistances/[Link]
[5][Link] led
0j4&sourceid=chrome&ie=UTF8#imgrc=6O3VsH5pVskU_M&imgdii=m7zW2X1NpG6VRM
How to continuously power an LED with Arduino.
Arduino: First steps in embedded computing
management-of-entries-exits/3422_tp-traffic-signal-lights/
LED with button
[9][Link]
[Link]
and an Arduino board
Starting with LED Arduino: RGB Color Intensity
[12] [Link]
[13][Link]
Control of one or two [Link]
https:[Link]/tutorial/control-a-dc-motor-with-Arduino/
[16][Link]
[17][Link]
arduino/#check.
18[Link]
[19] [Link]
[20[Link]
28
29