0% found this document useful (0 votes)
12 views29 pages

Arduino Microcontroller Practical Handbook

This document presents an introduction to the Arduino platform. It describes the key components of the Arduino Uno board, including the ATmega328 microcontroller, its digital and analog inputs/outputs, as well as the Arduino programming software.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views29 pages

Arduino Microcontroller Practical Handbook

This document presents an introduction to the Arduino platform. It describes the key components of the Arduino Uno board, including the ATmega328 microcontroller, its digital and analog inputs/outputs, as well as the Arduino programming software.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tunisian Republic

MINISTRY OF HIGHER EDUCATION


AND RESEARCH
UNIVERSITY OF SCIENCE

FACULTY OF SCIENCES OF MONASTIR

Practical Work Handbook:


Arduino Microcontroller

Prepared by: Amal Hafsa

Classes: LEI2, LSE2

Academic Year: 2022-2023

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.

The third manipulation involves using display devices for display of


messages such as the Liquid Crystal Display screen LCDI2C, the 5011 AS seven-segment display
(common cathode) and the LED matrix (8x8) with MAX7219.

The fourth manipulation involves controlling robotic cars via an application.


Android using HC-05 Bluetooth modules.

2
Summary
Introduction to Arduino ....................................................................................................4

Manipulation 1: Use of digital inputs/outputs .........................................13

Manipulation 2: Use of analog inputs/outputs ........................................17

Manipulation 3: Display on the Liquid Crystal Display I2C, the display Seven
segments 5011 AS and the LED matrices (8x8) with MAX7219 .................................22

Manipulation 4: Controlling robotic cars via an Android application ...25

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.

Figure 2: Internal architecture of ATMEGA 328 microcontroller [3].

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.

5. The analog inputs/outputs


5.1. The analog inputs

The Arduino board includes 5 analog ports (A0…A5) as shown in figure 3.


map reads the voltage applied to the port. It is an analog value while the microcontroller
only works with numerical values (0 or 1). This voltage must be converted to its
numerical value. Hence the role of the analog-to-digital converter (ADC). The latter
works on 10 bits. It receives an input voltage between 0 and 5V and sends to the microcontroller
an integer between 0 and 1023.

Figure 3: The analog inputs

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.

Figure 4: The Analog Outputs

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.

Figure 5: USB cable and battery

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).

Figure.6: The connection cables

8. The test plate


A test board allows us to create several electronic prototypes. It can
integrate several electronic components that communicate with the Arduino board. All the
connectors in a line of 5 are interconnected with each other. The lines of red connectors
are used for 5V power supply while the blue lines are used for the mass
(figure.7).

The connectors are interconnected.

Blue line: Food Red line: Power supply 0v

Figure.7: Test plaque

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.

R = C1 * C2 * 10 exp (C3) ± C4 (Eqt.3)

Figure 8: Reading color codes[4]

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.

Figure 9: LED Diode [5]

11. The Arduino IDE software


The Arduino software is a downloadable Integrated Development Environment (IDE).
free from the Arduino site. It is used to create, test, and upload programs onto

9
the cardArduino. The programming interface is shown in figure 10:

Open the Serial Monitor


Compilation Upload

Program

Create a new project

Open an existing project

Console Project recording

Figure.10:I programming interface

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".

Find the type of the card used from the


menu Tool→Map type Communicate the Arduino board with the computer via the USB cable

Check the correct port by clicking Tools→Serial Port

Check the proper functioning of the program


On the ARDUINO board

Upload the program to the microcontroller by clicking on the


Upload button.

Once the loading is complete, the ARDUINO software must


afficher un message " Téléversement terminé"
Press Reset to reset the card.

Figure 11: Steps for uploading to the microcontroller


11
13. Structure of a program
In an Arduino program, three parts are fundamental for the description as
indicated in figure 12.

Figure.12: Arduino program structure [2]

Part 1 is responsible for declaring constants and adding the library.


Part 2 is the void setup() part in which we configure the inputs and outputs.
The void loop () part which contains the program instructions.

12
MANIPULATION 1

Use of digital inputs/outputs


Objectives: The goal of this practical work is to understand how to use and manage inputs/outputs.
digital pins of the Arduino Uno.

2. Necessary materials and starter kits


Arduino Uno board
USB Computer Cable Arduino board
Test plate
4. Resistors 3×470ohm/2×10 kiloohm
5. Two push buttons
6. Connecting wires
7. LED Diodes

3. Practical part
Exercise 1: Make an LED blink

1. Assemble the figure below.

Figure.13: Wiring for the blinking of an LED [6]

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.

Figure.14Wiring for the simultaneous blinking of four LEDs [2]

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).

Exercise 3: Light Rotation


1. Assemble the following figure.
2. Write the Arduino program to create a traffic light.
controlled by the Arduino Uno board where the LEDs are connected respectively to the terminals
2, 3, 4, 6, 7 and 8 with a delay of 1000 ms.

14
Figure 15: Wiring for light rotation [7]

Exercise 4: Traffic lights


1. Write the Arduino program to manage two traffic lights in a way
synchronous.
Phase 1: R1 and V2 are on, J1, V1, R2, J2 are off.
Phase 2: R1 and J2 are on and J1, V1, R2, and V2 are off.
Phase 3: V1, V2 are on and the others are off.
Phase 4: J1 and R2 are on and the others are off.

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. Create the corresponding circuit using an Arduino UNO, LEDs,


resistors, connection cables, and the test plate.

Exercise 5: Turn on an LED according to the state of the push button


Carry out the following assembly.

Figure.16: Wiring to light up an LED according to the state of a push button

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

Use of analog inputs/outputs


1. Objectives: The aim of this lab is to know how to use and manage input/output.
analog inputs of the Arduino board. A set of applications to be developed such as the
temperature detection by an LM35 temperature sensor, the variation of
the intensity of an LED connected to a PWM (Pulse Width Modulation) pin
the Arduino by a potentiometer, the control of the brightness of an LED according to the

temperature variation at the terminals of the temperature sensor, the control of


DC motors (speed variation and direction of rotation) and state control
of a direct current motor by a push button. After this operation, the
students will learn about power components such as the Relay and the H-Bridge
L298N.

2. Necessary materials and starter kits


Arduino Uno Board
2. Computer USB Cable Arduino board.
3. LEDs
Test plaque.
5. Connection wires.
6. 2 LED Diodes
7.1 H Bridge L298N.
8. 1 Potentiometer.
9. Temperature sensor
10. 1 DC Motor 5v.
11. 1 push button.
12. 1 Relay

3. Practical part
Exercise 1: Read the temperature using an LM35 temperature sensor.

1. Make the following assembly.


2. Code an Arduino program to measure the temperature read on the pin.
A0. Open the serial monitor to check the proper functioning of the assembly.

17
Figure 17: Assembly for reading temperature using an LM35 sensor [10]

Exercise 2: Variation of the intensity of an LED by a potentiometer.

1. Assemble the following figure.

Figure 18: Montage to vary the intensity of an LED with a potentiometer [11]

2. Write the Arduino program to vary the intensity of an LED connected


on a PWM pin according to the voltage measured by a potentiometer.

3. Code an Arduino program to vary the brightness of an LED.


25%, 50%, 75% and 100% of maximum power.

Exercise 3: Control the blinking of an LED according to the variation of the


Temperature at the terminals of a temperature sensor.

1. Carry out the following assembly:

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.

Temperature = Voltage on pin A0 * 100.0

Figure 19: Montage for blink control by


temperature variation [12]

Exercise 4: Control of direct current motors (variation of


speed and direction of rotation

1. Indicate which electronic components can be added to the Arduino.


allowing to supply sufficient intensity to control a motor.
2. Understand the role and functioning of an H Bridge (L298N).

Figure.20: H Bridge (L298N) [13]

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.

4. Write the Arduino program to:

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.

Figure 20: Assembly to control two motors [14]

Exercise 5: Control the state of a direct current motor with a


push button.
1. Carry out the following assembly:

Figure 21: Assembly to control the state of a direct current motor by a


push button.

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.

1. Objectives: The aim of this lab is to learn how to display messages on


several types of displays, such as displaying the temperature on an I2C LCD screen,
the display of numbers from 0 to 9 on the 5011 AS seven-segment displays and the display
letters on LED matrices (8x8).

2. Necessary materials and starter kits


1. Arduino Uno board
2. USB Computer Cable Arduino board.
3. Test plaque.

4. Connection wires.

5. 2 LED Diodes

6. 220 Ohm resistors

7. I2C LCD screen 2x16.


8. 1 Potentiometer.
9. 7-segment display 5011 AS (common cathode).
10. LED Matrix (8x8) with MAX7219.

2. Practical Part

Exercise 1: Measuring temperature and displaying it on an I2C LCD screen


1. Build the following circuit using a potentiometer, an I2C LCD screen
2x16, three 220 Ohm resistors and three Leds.

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.

Exercise 2: Display numbers on the seven-segment displays

1. Understand how a seven-segment BCD decoder works.

2. What are the types of seven-segment displays?


3. How to distinguish between common anode and common cathode displays
community?
4. Carry out the following assembly with A, B, C, D, E, F, G, and DP are connected.

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.

Exercise 3: Write and display letters on LED matrices (8x8) with


MAX7219
1. Understanding the operation of 8x8 LED matrices
2. Understand the usefulness of the Max7219 device.

Figure 24: LED Matrix with MAX7219 [18]

3. Assemble the following figure:

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

1. Objectives: The aim of this lab is to control devices with a smartphone.


Android using a Bluetooth module.
2. Necessary materials and starter kits
[Link] Uno board
2. USB Computer Cable Arduino board.
3. Test plate.

4. Connection wires.

5. LED Diodes

220 Ohm resistors

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

1. Write the Arduino program to turn a LED on or off from a


smartphone (Android). The assembly will consist of an LED connected to the pin
13 from the Arduino board and a Bluetooth HC-05 module.
The principle is as follows:
The information is transmitted via Bluetooth from the smartphone to a Bluetooth module.
HC-05 then to the Arduino board via theseries liaison.
2. Achieve the montage of the figure below.

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]

Exercise 2: Command a four-motor DC robotic car to


5V.
1. Do the assembly wiring according to the following steps:

1- We connect the L298N Shield module to the Arduino UNO board.

We connect motor 1 to port M1 of the Shield

3- We connect motor 2 to port M2 of the Shield

4- We connect motor 3 to port M3 of the Shield.

5- We connect motor 4 to port M4 of the Shield.

Figure.27: Assembly to control a robotic car

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.

Exercise 3: Control a robot using an Android application

Write an Arduino program to control a robot via a smartphone.


Android using a Bluetooth HC-05 module
2. Carry out the following assembly.

Figure.28: Setup for controlling a robot using an Android application and a


Bluetooth module [20]

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

You might also like