Technical Training I Manual 2022 Sem A - R1
Technical Training I Manual 2022 Sem A - R1
Technical Training 1
Laboratory Manual
(Arduino IDE and Programming)
2022/23 Semester A
P.1
Purposes of this training
• To get familiar with Arduino board and the programming platform (Arduino IDE)
• To get familiar with Arduino basic programming
Schedules
1. Each individual practices the exercises and completes the tasks given in this
manual. Remember to give demo to the tutors as specified in the manual.
2. If you finish this manual fast, you can go ahead to read Technical Training II manual and
start to work on it
3. Take some time to read the report template to understand what are required.
Note: Students are not expected to leave earlier from the lab session.
P.2
1. Arduino Boards
Arduino is an open-source platform used for building electronic systems. It consists of hardware
(microcontroller) and software tool (Integrated Development Environment, IDE). The IDE
facilitates the programming and also downloads program to the hardware board.
More details can be found in the Arduino website. (http://arduino.cc/en/Guide/Introduction)
There are different types of Arduino boards with different features available in the market. In
this technical training, two types of Arduino boards may be used. They are Mega 2560 ver 3 and
Micro.
1.1 Arduino Mega 2560
Fig. 1 shows a photo of Arduino Mega 2560 ver 3. It provides many I/O pins and memory, so
that complex projects can be implemented. Pin layout of Mega 2560 ver 3 is given in Fig. 2.
Self-Reading Material: https://store-usa.arduino.cc/products/arduino-mega-2560-rev3
Arduino Programming
To program an Arduino board, you need to use the Arduino IDE. A web-based version and a
downloaded version are available. Here, only the downloaded version is focused. If you are going
to use the web-based version, you may visit the following URL and create your own account.
URL for web editor: https://create.arduino.cc/editor
1.3 Installation of Arduino IDE
The followings describe the procedures for installing the Arduino IDE and drivers to your
PC/notebook.
a) According to the OS of your PC/notebook (eg. Windows or Mac OS X), download the
corresponding Arduino IDE from https://www.arduino.cc/en/Main/Software. You can click
Just Download.
Windows
Mac OS X
P.4
Click this to just download
Fig. 4. Screen showing the download of Arduino IDE.
P.5
• Port: Select the proper communication port; Com XX (Arduino Micro) or (Arduino Mega)
[Your Port number may be different from the example shown in Fig. 6]
b) Search the library by typing its name and press Enter. The corresponding library will be
shown. You can then install the version that you want.
Insert library name here
Select latest
version
Click Install
P.7
2. Software Design
Arduino program (also called sketch) follows C++ syntax, but with some functions related to the
hardware. As a controller program (called as “sketch”), it has a basic structure.
2.1 Basic Structure of a Sketch
The sketch (i.e. a program) in Arduino consists of two inevitable functions, called setup() and
loop(). (See Fig. 10)
a) setup()
The setup() function is called when a sketch starts. You can use it to initialize variables, set pin
modes, start using libraries, etc. The setup function will only run once, after each power-up or
reset of the Arduino board.
b) loop()
After running the setup(), the loop() function will be run. It will loop consecutively.
c) Before setup(), we usually include libraries, define some global variables, create some other
functions [Note: Those variables and functions can then be used in setup() and loop()].
P.8
3. Serial Monitoring
We can establish Serial communication between a PC and an Arduino board, if they are
connected via an USB cable. It is useful for debugging and also as an I/O interface of your
program.
3.1 Functions/Commands
a) Set up
• Serial.begin(val) : val is the baud rate.
• Serial.end(): disable the serial communication
Note: The baud rate in the program and the serial monitor should be the same.
b) Sending data to PC
• Serial.println and Serial.print: print the texts (with or without line return)
You need to make sure the baud rate setting at the terminal matching with your program.
If error occurs, some error messages would be displayed. For example, below shows the case
that Arduino IDE cannot find the board on the given port. Correction is then needed, say, go
to Tool ➡ Port and select the correct port for the IDE.
P.10
Practice 2:
Modify the BlinkwithoutDelay as follows and observe the output
P.11
After you finished Practice 1 and 2, you can start on the following Training Tasks.
Training Tasks
Task 1. Understanding the Arduino Board
(You can refer to Self-reading Materials in Sec. 1.1 and 1.2)
Task 1.1
By checking the technical specification of MEGA 2560 ver 3, answer the following questions
Questions Your answers
1) What is the operating voltage of Mega 2560
ver 3?
P.12
Task 1.2
Answer questions to get familiar with pin assignment for communications.
This project will make use of different types of serial communications. They are based on
UART, I2C and SPI, respectively. [Please refer to Lecture notes]
a. There are four default UART Serial communications. One of them is also used for the
Serial monitor (So, you are not to use that serial, if you use Serial monitor). Circle the
transmitter and receiver pins of that serial port, and mark as UART
b. I2C communications use 2 pins, one is clock SCL and one is data SDA. Circle the default
pins that assigned for these functions, and mark as I2C.
c. SPI communications use 4 pins. They are clock (SCK), slave select (SS), master-input-
slave-output (MISO) and master-output-slave-input (MOSI). Circle the default pins that
assigned for these functions and mark as SPI.
P.13
Task 2 Get Familiar with the project platform
Task 2.1 Get Familiar with the modules
You’ll be given a project platform. Followings are the photo that contain all modules. In your
board, you may not have all the modules, but you should be able to identify their locations.
I
J
G
E
P.14
Task 2.2 Transistor Circuit to drive LEDs
The driving circuit for RGB LED is shown below. For clarity, only one circuit is given.
common
anode
RGB LED
P.15
Task 3. Programming Tasks
You are to complete all programming tasks given below.
Task 3A: Display color with RGB LED
Turn on the RGB LED to show three colors in sequence repetitively, each holds for 1 second
(Color 1→ Color 2 → Color 3 → Color 1 → …)
i) Draw the connection (in block diagram)
ii) Draw the flow chart of your design
iii) Do the actual programming
B.LED Input
Transistor
G.LED Input driving RGB
circuit LED
R.LED Input
Arduino
Jumper box
P.16
Flow Chart (Specify how to control the I/O pins, instead of giving the colors)
P.17
Task 3B: Display colors based on command inputs
Control the color display of a RGB LED by entering commands in the Serial monitor. You have
to describe your own mapping between the commands and the colors.
i) Give a description on your function mapping
ii) Do the actual programming
Remarks: Save your program as SID_task3B.ino for later report usage
P.18