16/10/2019
Introduction to Arduino Microcontroller
What is a Microcontroller?
A microcontroller is a very small computer that has digital
1 electronic devices (peripherals) built into it that helps it control
things. These peripherals allow it to sense the world around it and
drive the actions of external devices.
Microcontroller is a small computer on a single integrated
circuit containing a processor (the CPU), non-volatile 2
memory for the program (ROM or flash), volatile memory
for input and output (RAM), a clock and an I/O control unit.
Microcontroller is an “embedded computer system”
3 that continuously repeats software (programming)
commands Examples: Arduino Uno, Raspberry Pi, etc
10/16/2019 1
Microcomputer, Microcontroller and Microprocessor
A computer is an electronic device with a microprocessor as
its central processing unit (CPU), memory in the form of read-
Microcomputer System only memory and random access memory, and input/output
(I/O) circuitry mounted on a single printed circuit board
usually called a motherboard.
Microcontroller is a small computer on a single
integrated circuit containing a processor (the CPU),
non-volatile memory for the program (ROM or flash),
volatile memory for input and output (RAM), a clock Microcontroller
and an I/O control unit.
ALU
The microprocessor is a multipurpose, clock
Interrupts
driven,Registers
register based, programmable electro
nic device which accepts digital or binary data
as input, processes it according to instructions
Microprocessor stored in &itsControl
Timing memory, and provides results as
output Unit
10/16/2019 2
1
16/10/2019
The Arduino Hardware
What is an Arduino? Arduino Starter Kit
Is an Open Source electronic prototyping platform
based on flexible easy to use hardware and software.
10/16/2019 4
2
16/10/2019
Arduino Starter Kit
10/16/2019 5
The Arduino Board
10/16/2019 6
3
16/10/2019
Connecting the Board
10/16/2019 7
Arduino Family
10/16/2019 8
4
16/10/2019
Microcontroller Specifications
10/16/2019 9
Arduino IDE (Integrated
Development
Environment)
5
16/10/2019
Arduino microcontrollers are programmed using the Arduino IDE (Integrated
Development Environment
Projects made using the Arduino are called sketches, and such sketches are usually written in a cut-
down version of C++ (a number of C++ features are not included). Because programming a
microcontroller is somewhat different from programming a computer, there are a number of device-
specific libraries (e.g., changing pin modes, output data on pins, reading analog values, and timers).
Arduino is programmed in C++, it just uses unique libraries for the device.
Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc.
For example, the built-in Liquid Crystal library makes it easy to talk to character LCD displays. There
are hundreds of additional libraries available on the Internet for download.
Every sketch must have a setup() function (executed just once) followed by a loop() function (potentially
executed many times); add “comments” to code to make it easier to read (technically optional, but actually)
10/16/2019 11
The Arduino Integrated Development Environment
Name of current sketch
Main menus
Action buttons/icons
Verify (AKA compile)
Text area for Upload (send to Arduino)
writing/editing
sketches. Start a new sketch
Open a sketch (from a file)
Save current sketch (to a file)
Open Serial Monitor window
Error messages and other
feedback show up here.
10/16/2019 12
6
16/10/2019
The Arduino Integrated Development Environment
Void setup(){// put your setup code here, to run
once:
}
Void loop() {// put your main code here, to run
repeatedly:
}
10/16/2019 13
Selecting the Arduino board Select Tools ->Board -> Type of Arduino e.g Uno
10/16/2019 14
7
16/10/2019
Setting the port the Arduino is connected
Select Tools Serial Port and select the COM
port number that appeared in the Software
window. This is likely to be COM3or higher
(COM1andCOM2are usually reserved for
hardware serial ports).
10/16/2019 15
Pin Mode
A pin on Arduino can be set as input or output by using pinMode function.
pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin
Reading/writing digital values
digitalWrite(13, LOW); // Makes the output voltage on pin 13 , 0V
digitalWrite(13, HIGH); // Makes the output voltage on pin 13 , 5V
int buttonState=digitalRead(2); // reads the value of pin 2 in buttonState
10/16/2019 16
8
16/10/2019
Whether you are creating a project that simply blinks a light or an automated model railway signal, a
detailed plan is the foundation of success. When designing your Arduino projects, follow these basic
steps:
Define your objective. Determine what you want to achieve.
Write your algorithm. An algorithm is a set of instructions that describes how to
accomplish your project. Your algorithm will list the steps necessary for you to
achieve your project’s objective.
Select your hardware. Determine how it will connect to the Arduino.
Write your sketch. Create your initial program that tells the Arduino what to do.
Wire it up. Connect your hardware, circuitry, and other items to the Arduino board.
Test and debug. Does it work? During this stage, you identify errors and find their
causes, whether in the sketch, hardware, or algorithm.
10/16/2019 17
10/16/2019 DEPARTMENT OF COMPUTER AND COMMUNICATIONS SYSTEMS ENGINEERING , UPM 18
9
16/10/2019
Goals of this Lecture
• microcontrollers their functions
• How to use a (solderless) breadboard to wire up sensors
and other hardware to an Arduino Uno.
• To understand, comment, upload/run, and edit Arduino
programs (AKA sketches).
• Difference between input, output, and power pins and also
between analog and digital pins.
• Learn to control things like LEDs and write information to
the serial monitor (a text window on the computer).
• Learn to read sensor values and log data to an SD card for
later retrieval and analysis.
• Learn the basics of using motors
• Put you in a position to implement an Arduino‐based
computer system for your own projects.
10