GEC225 Module6 - Arduino
GEC225 Module6 - Arduino
3
iii) Cross-platform: Arduino Software Integrated Development
Environment runs on Windows, Mac and Linux operating
systems.
iv) Open source software: Arduino IDE is published as open
source tools, which can be extended by experienced
programmers through C++ libraries.
v) Simple and clear programming environment: Arduino IDE
is easy-to-use for beginners and also flexible for advanced
programmers.
4
2.0 Microcontrollers and the Arduino
board
• A microcontroller(µC or MCU) is a
computer on a single integrated
chip that contains:
Processor
Memory: RAM, ROM and Flash memory
I/O ports: USB, Ethernet, Inter-Integrated Circuit
(I2C) and Serial Peripheral Interface (SPI).
5
• The most common microcontroller
families are Intel(4004,8008, 80286), Atmel(AT
and AVR), Microchip(PIC) and ARM(Cortex-A,
Cortex-M)
6
• Atmel microcontrollers(shown in Table 1) are
commonly used in Arduino boards.
7
• Arduino has several brands which
include - Arduino Uno, Arduino Yun, Arduino
Leonardo, Arduino LilyPad, Arduino Mega,
Arduino Nano, Arduino Mini, Arduino Mini Pro,
Arduino BT
8
• Arduino also have shields, which
can be plugged on top of the
Arduino PCB to extend its
capabilities. Examples of Arduino
shields are: Motor shield, TFT touch screen
shield, Ethernet shield, GSM shield, WiFi
shield, eHealth shield and etc.
9
A sample project with Arduino and motor shield
10
• The different parts of an Arduino
board are shown below:
11
3.0 Arduino IDE
• Just like other computers, any MCU
requires program instructions to
work.
• The Arduino IDE is a software that
contains all you need to write
program codes.
• The Arduino programming language
that you write in the IDE is a
simplified version of C language.
12
• The elements of the IDE are:
Text editor: for code writing, syntax
and keyword coloring, automatic
indentation
Compiler: for source code
compilation.
Hardware interface: to upload
programs and communication with
Arduino board through USB.
13
3.1 Installing Arduino IDE on Linux
Step1: Download the latest package for Linux 32-bit
or Linux 64-bit from:
www. arduino.cc/en/Main/Software
Step 2(a): Open the terminal and navigate to your
downloads folder
cd ~/Downloads
(b) Decompress the downloaded archive with the
command:
tar –xvf arduino-nightly-linux64.tar.xz
(c) Move the result folder to /opt/ directory for
global access:
sudo mv arduino-nightly/opt
14
Step 3 (a): Navigate to install folder
cd /opt/arduino-nightly
(b) Give executable permission to install.sh
script in that folder:
chmod +x install.sh
Step 4 (a) Plug in your board using USB cable and
note that external power is unnecessary.
(b) Run arduino
./arduino
15
3.2 Arduino IDE
16
3.3 Selecting the right arduino board
17
3.3 Selecting the right port
18
3.4 Arduino IDE Command Icons
19
3.5 Arduino Code Structure
• There are two major blocks in the text
area of Arduino IDE.
i) void setup(): The code written in
this block is executed only when the
program begins or reset button is
pressed.
ii) void loop(): The code written inside
this block will be executed
repeatedly.
• Note that programs are called
sketches in Arduino.
20
Example 1: Open your IDE and type
the “Hello World” code:
21
Click the Compile and then the
Upload icons in order to compile
the program and load on the
Arduino board.
Click the Serial Monitor button to
see the code as shown:
22
23
Example 2: Open the LED blink
code example in the IDE as follows:
24
The code is shown in the IDE as follows
25
Compile and upload the code to
obtain:
26
Exercise
Run the Fade code example in the
IDE(File>Examples>Basics>Fade).
27
www.covenantuniversity.
Thank you.