0% found this document useful (0 votes)
3 views37 pages

Iot-Arduino Board

Uploaded by

funnymine04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views37 pages

Iot-Arduino Board

Uploaded by

funnymine04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 37

Outlines

• What is Arduino?

• Arduino Terminology

• Arduino Type

• Shield, Module, Sensor

• Arduino UNO R3

• Programming Language for Arduino UNO

• Serial Communication in Arduino UNO

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 1/35


What is Arduino?
• The Arduino is a programmable hardware board that runs an 8-bit /16
Mhz microcontroller with a special bootloader that allows users to upload
programs to the microcontroller.
– It has digital input pins for input from switches and output to Actuators (LEDS or electrical
motors)
– It also has analog pins to accept inputs from voltage based sensors.

• Arduino can be used to develop stand-alone interactive objects or can be


connected to software on your computer.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 2/35


What is Arduino? Open Source

• Open Source Hardware


– The Arduino system is open source - all hardware (made by Arduino
distributors) has the schematics and PCB layouts available online.

• Open Source Bootloader


– The bootloader is what runs on the chip before the program is run. It
boots the chip and executes the program.

• Open Source Development Kit


– The development kit - what you use to program an Arduino board - is
also available online. It is free, open-source.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 3/35


Arduino Terminology

Terminology Description
The I/O Board is the "brain" of the operation (main
I/O Board
microcontroller you program it from your computer).
A Shield is a device that plugs into an I/O Board. These
Shield
extend the capabilities of the I/O Board.
Sketch A Sketch is a program written for the board and shields.
Sensor components (Gas, etc.)
Module serial data (GPS module, etc.).
Pin an input or output connected to something.
values have the resolution of 0 to 1024, and in terms of
Analog
voltage the 5 volts will be 1024.
Digital value is either HIGH or LOW.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 4/35


Arduino Type
• Many different versions depend on the number of input/output pin or
processor.

Arduino Nano Arduino LilyPad Arduino Mega

Arduino Uno Arduino Mini Arduino Leonardo

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 5/35


Arduino Uno

• The pins are in three groups:


– 6 analog inputs (can be used as
digital outputs).
– 14 digital input/output pins (of which
6 can be used as PWM outputs).
– Power

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 6/35


Arduino Uno – Shields
• Arduino Shields are add-on boards than can be plugged on top of an Arduino
board and provided additional capabilities and functionalities to an Arduino Board.

Wireless Network Shield Color LCD Shield

GPS Shield Power Driver Shield

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 7/35


Arduino Uno – More Shields
• Communication shields: XBee, Ethernet, and Wifi.

XBee Shield

Ethernet Shield WiFi Shield

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 8/35


Arduino Uno – Modules
• Module is a ready-to-use board with a Sensor or an IO device on it. Modules send
serial data strings to the Arduino.

Bluetooth Module

GPS Module

Ultrasonic Module RFID Module

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 9/35


Arduino Uno – More Modules

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 10/35


Arduino Uno – Sensors
• A sensor is a device that detects and responds to some type of input from the
physical environment.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 11/35


Arduino Uno R3 - Hardware
• Arduino hardware is a PCB-mounted microcontroller that you can
program and use for simple daily tasks, mathematical computations, and
prototyping and testing.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 12/35


Arduino Uno R3 – Hardware (cont’)
• An Arduino development
board consists of the core
microcontroller with its
supplementary components
and the necessary circuitry to
communicate with the PC
which we will be using for
both communications as well
as programming the
microcontroller.

• For communication or programming purposes, we will be using a USB-USB-


to-
to-TTL converter, which will be embedded within the Arduino board.
• The Arduino is NOT limited to the capabilities of an ATMEGA328
ATMEGA328 chip.
chip
There are plenty of board variants available, with an entirely different set
of features like different microcontrollers, layout, number of I/O ports, etc.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 13/35


Arduino Uno R3 - Schematic

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 14/35


Arduino Uno R3 – USB-B Socket
• The USB socket on the UNO has two functions. One is for communication,
communication
to connect with the computer through a USB port, and also to load the
firmware into the Arduino with the help of the bootloader. The second is
to power the Arduino. You can use the USB port to power the Uno directly
from any USB port.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 15/35


Arduino Uno R3 – ISCP Pins
• In the UNO you can find two 6 pin connectors. One is near the USB – TTL
Chip and the other one is at the end of the board
board. These pins are used to
program those two microcontrollers. The USB – TTL chip on this board is
an ATMgega16U. The connector marked as 1 is used to program the USB-
TTL firmware into this chip. And the connector marked as 2 is used to burn
the bootloader into the ATMega328 microcontroller.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 16/35


Arduino Uno R3 – Reset Button
• As the name indicates this tactile switch is used to reset the ATMega328
microcontroller. It’s connected to the PC6/Reset pin, which is pulled up
through a 10K. When the switch is pressed the pin is pulled to the ground
and the chip will reset.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 17/35


Arduino Uno R3 – USB-TTL Interface Chip
• To communicate with the computer, the Arduino relies on a USB-TTL
interface. In UNO, ATMega16U with custom firmware act as a USB – TTL
interface chip.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 18/35


Arduino Uno R3 – Crystal Oscillator
• For a microcontroller to work it needs a clock source. The clock circuit
determines the speed with which the microcontroller operates.
• The ATMega series microcontrollers can use two types of clock sources.
– Internal RC oscillator: built into the microcontroller, but its maximum frequency is limited
and it is not that accurate.
– External clock generator: a Quartz crystal oscillator or a ceramic resonator.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 19/35


Arduino Uno R3 – Power Path Control
• If you inspect a UNO, you can find an LM358. It’s used as a comparator to
control the input power path.
– When the input power is provided through the barrel jack or Vin pin, the power path
control circuit will cut off the USB power pin from the circuit which in fact will protect the
USB port.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 20/35


Arduino Uno R3 – Voltage Regulator
• The ATMega328 and ATmega16U2 have a maximum input voltage of around 5V
and most modules or accessories work on either 5V or 3.3V. The Arduino can
accept 7-12V through the Vin pin or the DC barrel jack. So, to step it down, there
are two regulators onboard. One is a 5V regulator (marked as 1) for the
microcontrollers and the other one is a 3.3V regulator which is used to provide 3.3V
through 3.3V pin.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 21/35


Arduino Uno R3 – DC Barrel Jack
• The DC barrel jack is used to supply power to the UNO. We can supply 7-
12V through it and hence we can use a 12V DC adapter or 9V DC adapter
on this Jack to power the Arduino board.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 22/35


Arduino Uno R3 – Digital and Analog I/O
• The Arduino UNO has 14 digital I/O pins and 6 Analog inputs.
inputs The digital
I/O pins are 5V logic level and you can also use the Analog pins as digital
I/O too. Arduino UNO supports 6 channel 10 bit ADC inputs through A0-
A5, which can be sampled and analyzed using UNO.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 23/35


Arduino Uno R3 – Status LEDs and Inbuilt LED
• Uno has 4 LEDs onboard. One is used as a power indicator and two are
used to show the activity of the Rx and Tx pin. The other one is tied to the
Digital pin 13, which can be used to test the Arduino board or simply as an
indicator.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 24/35


Arduino Uno R3 – ATMega328P - The Brain
• The main component on the Arduino board – the ATMega328
ATMega328P
328P
Microcontroller. UNO uses a 28
Microcontroller 28Pin
Pin DIP version of ATMega328P.
Atmega328P is pre-
pre-programmed with a bootloader that allows you to
directly upload the program to Arduino through USB without the need for
an external programmer.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 25/35


Arduino Uno R3 – Technical Specifications

Component Specification
Microcontroller ATmega328P
Operating voltage 5V
Input voltage (recommended) 7 – 12 V
Input voltage (limits) 6 – 20 V
Digital I/O pins 14 (of which 6 provide PWM output)
Analog input pins 6
DC current per I/O pin 20 mA
Flash memory 32 KB
SRAM 2 KB
EEPROM 1 KB
Clock speed 16 MHz
Weight 25 g

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 26/35


Arduino Uno – Programming Language
• Arduino programming language can be divided in three main parts:
parts
functions, values (variables and constants), and structure.
Functions
(for controlling the Arduino board and performing computations)
noTone() pulseIn()
Advanced I/O pulseInLong() shiftIn()
shiftOut() tone()
analogRead() analogReference()
Analog I/O
analogWrite()
bit() bitClear()
bitRead() bitSet
Bits and Bytes
bitWrite() highByte()
lowByte()
isAlpha() isAlphaNumeric()
isAscii() isControl()
isDigit() isGraph()
Characters isHexadecimalDigit() isLowerCase()
isPrintable() isPunct()
isSpace() isUpperCase()
isLowerCase()
Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 27/35
Arduino Uno – Programming Language
Functions
(for controlling the Arduino board and performing computations)
Serial SPI
Communication
Stream Wire
digitalRead() digitalWrite()
Digital I/O
pinMode()
External Interrupts attachInterrupt() detachInterrupt()
abs() constrain()
map() max()
Math
min() pow()
sq() sqrt()
Random Numbers random() randomSeed()
cos() sin()
Trigonometry
tan()
USB Keyboard Mouse

Zero, Due & MKR Family analogReadResolution() analogWriteResolution()

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 28/35


Arduino Uno – Programming Language
Variables
(Arduino data types and constants)
HIGH | LOW INPUT | OUTPUT | INPUT_PULLUP
Constants LED_BUILTIN true | false
Floating Point Constants Integer Constants
(unsigned int) (unsigned long)
byte() char()
Conversion
float() int()
long() word()
array bool
boolean byte
char double
float int
Data Types long short
size_t string
String() unsigned int
unsigned long void
word
const scope
Variable Scope & Qualifiers
static volatile
Utilities PROGMEM sizeof()
Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 29/35
Arduino Uno – Programming Language

Structure
(The elements of Arduino (C++) code)
% (remainder) * (multiplication)
Arithmetic Operators + (addition) - (subtraction)
/ (division) = (assignment operator)
& (bitwise and) << (bitshift left)
Bitwise Operators >> (bitshift right) ^ (bitwise xor)
| (bitwise or) ~ (bitwise not)
! (logical not) && (logical and)
Boolean Operators
|| (logical or)
!= (not equal to) < (less than)
Comparison Operators <= (less than or equal to) == (equal to)
> (greater than) > = (greater than or equal to)
%= (compound remainder) &= (compound bitwise and)
*= (compound multiplication) ++ (increment)
Compound Operators += (compound addition) -- (decrement)
-= (compound subtraction) /= (compound division)
^= (compound bitwise xor) |= (compound bitwise or)

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 30/35


Arduino Uno – Programming Language

Structure
(The elements of Arduino (C++) code)
break continue
do …while else
Control Structure for goto
if return
switch…case while
#define (define) #include (include)
Further Syntax /* */ (block comment) // (single line comment)
; (semicolon) {curly braces}
Pointer Access Operators & (reference operator) * (dereference operator)

Sketch loop() setup()

• Refer to https://www.arduino.cc/reference/en for detailed information.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 31/35


Arduino Uno – Serial Communication
• RX LED blinks when the Arduino is receiving data.
data
• TX LED blinks when the Arduino is transmitting data.
data

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 32/35


Arduino Uno – Serial Data Transfer
• Universal asynchronous receiver/transmitter (UART) is a hardware
communication protocol that uses asynchronous serial communication
with configurable speed.
• Serial Peripheral Interface (SPI) is a synchronous serial data protocol used
by microcontrollers for communicating with one or more peripheral
devices quickly over short distances. It can also be used for
communication between two microcontrollers.
• Inter-
Inter-integrated Circuit (I2
(I2C) or Two-
Two-Wire Interface (TWI) is a two-wire
serial communication protocol for connecting low speed peripherals to a
microcontroller or computer motherboard.

[UART device communication diagram] [I2C two wire bus layout]


Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 33/35
Arduino Uno – UART
• All Arduino boards have at least one serial port (also known as a UART). It
communicates on digital pins 0 (RX) and 1 (TX) between the Arduino
board or other devices, as well as with the computer via USB
USB.

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 34/35


Arduino Uno – SoftwareSerial Library
• The SoftwareSerial library allows serial communication on other digital
pins of an Arduino board, using software to replicate the functionality
(hence the name "SoftwareSerial").
• It is possible to have multiple software serial ports with speeds up to
115200 bps.
bps
• To use this library: #include <SoftwareSerial.h>
• SoftwareSerial library has the following known limitations:
– It cannot transmit and receive data at the same time.
– If using multiple software serial ports, only one can receive data at a time.
– Not all pins on the Mega and Mega 2560, the Leonardo and Micro boards support change
interrupts
– On Arduino or Genuino 101 boards the current maximum RX speed is 57600bps
57600bps.
bps
– On Arduino or Genuino 101 boards RX doesn't work on digital pin 13.
13

Le The Dung, Ph.D. Arduino Board and ATMega328 Architecture 35/35


THANK YOU ALL FOR LISTENING

Arduino Board and ATMega328 Architecture


QUESTIONS AND ANSWERS

Arduino Board and ATMega328 Architecture

You might also like