Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ARDUINO UNO Document

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

What is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software.


Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter
message - and turn it into an output - activating a motor, turning on an LED, publishing
something online. You can tell your board what to do by sending a set of instructions to the
microcontroller on the board. To do so you use the Arduino programming language (based on
Wiring), and the Arduino Software (IDE), based on Processing.

Over the years Arduino has been the brain of thousands of projects, from everyday objects to
complex scientific instruments. A worldwide community of makers - students, hobbyists,
artists, programmers, and professionals - has gathered around this open-source platform, their
contributions have added up to an incredible amount of accessible knowledge that can be of
great help to novices and experts alike.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it
reached a wider community, the Arduino board started changing to adapt to new needs and
challenges, differentiating its offer from simple 8-bit boards to products for IoT applications,
wearable, 3D printing, and embedded environments. All Arduino boards are completely
open-source, empowering users to build them independently and eventually adapt them to
their particular needs. The software, too, is open-source, and it is growing through the
contributions of users worldwide.

2 Why Arduino?

Thanks to its simple and accessible user experience, Arduino has been used in thousands of
different projects and applications. The Arduino software is easy-to-use for beginners, yet
flexible enough for advanced users. It runs on Mac, Windows, and Linux. Teachers and
students use it to build low cost scientific instruments, to prove chemistry and physics
principles, or to get started with programming and robotics. Designers and architects build
interactive prototypes, musicians and artists use it for installations and to experiment with
new musical instruments. Makers, of course, use it to build many of the projects exhibited at
the Maker Faire, for example. Arduino is a key tool to learn new things. Anyone - children,
hobbyists, artists, programmers - can start tinkering just following the step by step
instructions of a kit, or sharing ideas online with other members of the Arduino community.
Arduino also simplifies the process of working with microcontrollers, but it offers some
advantage for teachers, students, and interested amateurs over other systems:

Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller


platforms. The least expensive version of the Arduino module can be assembled by hand, and
even the pre-assembled Arduino modules cost less than $50

Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.

Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well. For teachers,
it's conveniently based on the Processing programming environment, so students learning to
program in that environment will be familiar with how the Arduino IDE works.

Open source and extensible software - The Arduino software is published as open source
tools, available for extension by experienced programmers. The language can be expanded
through C++ libraries, and people wanting to understand the technical details can make the
leap from Arduino to the AVR C programming language on which it's based. Similarly, you
can add AVR-C code directly into your Arduino programs if you want to.

Open source and extensible hardware - The plans of the Arduino boards are published
under a Creative Commons license, so experienced circuit designers can make their own
version of the module, extending it and improving it. Even relatively inexperienced users can
build the breadboard version of the module in order to understand how it works and save
money.

The Arduino Software (IDE) allows you to write programs and upload them to your board.
Arduino boards are able to read inputs

 Sensors (Analog / Digital)

 Button

And turn it into an output

 Motor
 LED

 Display Unit

All this is defined by a set of instructions programmed through the Arduino Software (IDE).

3 Open Source Platform

Most of us using the internet would have came across the word “open-source”. Open-source
is a methodology where, the developers of a software/hardware give the end user to access
their end product’s design and implementation. That means the end user has rights to
modify/change the way a software looks/works and redistribute it. Examples of open-source
software are Linux operating system, freePCB, openBSD etc. 

Open-source hardware, also called open hardware, is electronic or computer hardware built
from design information that could be copyrighted or licensed but has instead been made
available for public use at no charge. Such information can include documentation, schematic
diagrams, construction details, parts lists and logic designs.

There’s also a growing community of companies, individuals, and groups designing and
making lots of cool open-source hardware! Some examples include microcontroller
development platforms, satellites and 3D printers. Open source hardware is a great way to
share knowledge and facilitate development of new products.

4 Arduino Products:
Figure 1: Different Arduino Products.

ATMEGA 328P (ARDUINO UNO)

The Arduino Uno is a microcontroller board based on the ATmega328. It has a 16 MHz
ceramic resonator, 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a USB connection, a power jack, an ICSP header, and a reset button. This
board is very simple and can be easily used, everything you need to support the
microcontroller is in this board, just plug it in a computer via USB cable and power using an
AC-to-DC adapter or battery to get started.
The difference seen in the Arduino Uno is that it does not use the FTDI USB-to-serial driver
chip but, it has the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB to-
serial converter.
Picture 6: Arduino-Uno Structure

Arduino-Uno specifications

Microcontroller ATmega328
Operating-Voltage(OV) 5Volts
Recommended input voltage 7 to 12 Volts
Limits of inputs voltage 6 to 20 Volts

Digital I/O Pins 14 (of which 6 provides PWM output)


Analog Input Pins 6 Pin
DC Current per I/O 40 mA
DC Current for 3.3V Pin 50 mA

Flash Memory 32 KB (ATmega328) of which 0.5 KB used


by bootloader
SRAM 2 KB (ATmega328)

EEPROM 1 KB (ATmega328)

Clock Speed 16 MHz

Table 1 – Arduino-Uno Specification


The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16
MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.
It contains everything needed to support the microcontroller; simply connect it to a computer
with a USB cable or power it with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial
driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed
as a USB-to-serial converter. Revision 2 of the Uno board has a resistor pulling the 8U2
HWB line to ground, making it easier to put into DFU mode. Revision 3 of the board has the
following new features:
 pinout: added SDA and SCL pins that are near to the AREF pin and two other new
pins placed near to the RESET pin, the IOREF that allow the shields to adapt to the
voltage provided from the board. In future, shields will be compatible both with the
board that use the AVR, which operate with 5V and with the Arduino Due that
operate with 3.3V. The second one is a not connected pin, that is reserved for future
purposes.
 Stronger RESET circuit.
 Atmega 16U2 replace the 8U2.

"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The
Uno and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is
the latest in a series of USB Arduino boards, and the reference model for the Arduino
platform; for a comparison with previous versions, see the index of Arduino boards.

Power
The Arduino Uno can be powered via the USB connection or with an external power supply.
The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm center-positive plug into the board's
power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the
POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using
more than 12V, the voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.
The power pins are as follows:
 VIN. The input voltage to the Arduino board when it's using an external power source
(as opposed to 5 volts from the USB connection or other regulated power source).
You can supply voltage through this pin, or, if supplying voltage via the power jack,
access it through this pin.
 5V.This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 12V), the USB connector
(5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins
bypasses the regulator, and can damage your board. We don't advise it.
 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw
is 50 mA.
 GND. Ground pins.

Memory
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library).
Input and Output
Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode(),
digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or
receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of
20-50 kOhms. In addition, some pins have specialized functions:
 Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.
 External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on
a low value, a rising or falling edge, or a change in value. See the attachInterrupt()
function for details.
 PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite()
function.
 SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI
communication using the SPI library.
 LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though is it possible to change the upper end of their range using the AREF pin and the
analogReference() function. Additionally, some pins have specialized functionality:
 TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the
Wire library.

There are a couple of other pins on the board:


 AREF. Reference voltage for the analog inputs. Used with analogReference().
 Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.

Communication
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on
the board channels this serial communication over USB and appears as a virtual com port to
software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no
external driver is needed. However, on Windows, a .inf file is required. The Arduino software
includes a serial monitor which allows simple textual data to be sent to and from the Arduino
board. The RX and TX LEDs on the board will flash when data is being transmitted via the
USB-to-serial chip and USB connection to the computer (but not for serial communication on
pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Uno's digital pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software
includes a Wire library to simplify use of the I2C bus; see the documentation for details. For
SPI communication, use the SPI library.

Features
• High Performance, Low Power AVR® 8-Bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single Clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20 MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory Segments
– 4/8/16/32K Bytes of In-System Self-Programmable Flash program memory
(ATmega48PA/88PA/168PA/328P)
– 256/512/512/1K Bytes EEPROM (ATmega48PA/88PA/168PA/328P)
– 512/1K/1K/2K Bytes Internal SRAM (ATmega48PA/88PA/168PA/328P)
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– Programming Lock for Software Security
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel 10-bit ADC in TQFP and QFN/MLF package
Temperature Measurement
– 6-channel 10-bit ADC in PDIP Package
Temperature Measurement
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby,
and Extended Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
• Operating Voltage:
– 1.8 - 5.5V for ATmega48PA/88PA/168PA/328P
• Temperature Range:
– -40°C to 85°C
• Speed Grade:
– 0 - 20 MHz @ 1.8 - 5.5V
• Low Power Consumption at 1 MHz, 1.8V, 25°C for ATmega328P:
– Active Mode: 0.2 mA
– Power-down Mode: 0.1 μA
– Power-save Mode: 0.75 μA (Including 32 kHz RTC)

PINOUT (ATMEGA328 PDIP)


PIN DESCRIPTIONS OF ATMEGA328P (ARDUINO UNO)

VCC
Digital supply voltage.
GND
Ground.
Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
The Port B output buffers have symmetrical drive characteristics with both high sink and
source capability. As inputs, Port B pins that are externally pulled low will source current if
the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition
becomes active, even if the clock is not running. Depending on the clock selection fuse
settings, PB6 can be used as input to the inverting Oscillator amplifier and input to the
internal clock operating circuit. Depending on the clock selection fuse settings, PB7 can be
used as output from the inverting Oscillator amplifier. If the Internal Calibrated RC Oscillator
is used as chip clock source, PB7..6 is used as TOSC2..1 input for the Asynchronous
Timer/Counter2 if the AS2 bit in ASSR is set.
The various special features of Port B are elaborated in table

The alternate pin configuration is as follows:


• XTAL2/TOSC2/PCINT7 – Port B, Bit 7
XTAL2: Chip clock Oscillator pin 2. Used as clock pin for crystal Oscillator or Low-
frequency crystal Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.
TOSC2: Timer Oscillator pin 2. Used only if internal calibrated RC Oscillator is selected as
chip clock source, and the asynchronous timer is enabled by the correct setting in ASSR.
When the AS2 bit in ASSR is set (one) and the EXCLK bit is cleared (zero) to enable
asynchronous clocking of Timer/Counter2 using the Crystal Oscillator, pin PB7 is
disconnected from the port, and becomes the inverting output of the Oscillator amplifier. In
this mode, a crystal Oscillator is connected to this pin, and the pin cannot be used as an I/O
pin.
PCINT7: Pin Change Interrupt source 7. The PB7 pin can serve as an external interrupt
source. If PB7 is used as a clock pin, DDB7, PORTB7 and PINB7 will all read 0.
• XTAL1/TOSC1/PCINT6 – Port B, Bit 6
XTAL1: Chip clock Oscillator pin 1. Used for all chip clock sources except internal
calibrated RC Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.
TOSC1: Timer Oscillator pin 1. Used only if internal calibrated RC Oscillator is selected as
chip clock source, and the asynchronous timer is enabled by the correct setting in ASSR.
When the AS2 bit in ASSR is set (one) to enable asynchronous clocking of Timer/Counter2,
pin PB6 is disconnected from the port, and becomes the input of the inverting Oscillator
amplifier. In this mode, a crystal Oscillator is connected to this pin, and the pin can not be
used as an I/O pin.
PCINT6: Pin Change Interrupt source 6. The PB6 pin can serve as an external interrupt
source.
If PB6 is used as a clock pin, DDB6, PORTB6 and PINB6 will all read 0.
• SCK/PCINT5 – Port B, Bit 5
SCK: Master Clock output, Slave Clock input pin for SPI channel. When the SPI is enabled
as a Slave, this pin is configured as an input regardless of the setting of DDB5. When the SPI
is enabled as a Master, the data direction of this pin is controlled by DDB5. When the pin is
forced by the SPI to be an input, the pull-up can still be controlled by the PORTB5 bit.
PCINT5: Pin Change Interrupt source 5. The PB5 pin can serve as an external interrupt
source.
• MISO/PCINT4 – Port B, Bit 4
MISO: Master Data input, Slave Data output pin for SPI channel. When the SPI is enabled as
a Master, this pin is configured as an input regardless of the setting of DDB4. When the SPI
is enabled as a Slave, the data direction of this pin is controlled by DDB4. When the pin is
forced by the SPI to be an input, the pull-up can still be controlled by the PORTB4 bit.
PCINT4: Pin Change Interrupt source 4. The PB4 pin can serve as an external interrupt
source.
• MOSI/OC2/PCINT3 – Port B, Bit 3
MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI is enabled as
a Slave, this pin is configured as an input regardless of the setting of DDB3. When the SPI is
enabled as a Master, the data direction of this pin is controlled by DDB3. When the pin is
forced by the SPI to be an input, the pull-up can still be controlled by the PORTB3 bit.

OC2, Output Compare Match Output: The PB3 pin can serve as an external output for the
Timer/Counter2 Compare Match. The PB3 pin has to be configured as an output (DDB3 set
(one)) to serve this function. The OC2 pin is also the output pin for the PWM mode timer
function.
PCINT3: Pin Change Interrupt source 3. The PB3 pin can serve as an external interrupt
source.
• SS/OC1B/PCINT2 – Port B, Bit 2
SS: Slave Select input. When the SPI is enabled as a Slave, this pin is configured as an input
regardless of the setting of DDB2. As a Slave, the SPI is activated when this pin is driven
low. When the SPI is enabled as a Master, the data direction of this pin is controlled by
DDB2. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by
the PORTB2 bit.
OC1B, Output Compare Match output: The PB2 pin can serve as an external output for the
Timer/Counter1 Compare Match B. The PB2 pin has to be configured as an output (DDB2
set (one)) to serve this function. The OC1B pin is also the output pin for the PWM mode
timer function.
PCINT2: Pin Change Interrupt source 2. The PB2 pin can serve as an external interrupt
source.
• OC1A/PCINT1 – Port B, Bit 1
OC1A, Output Compare Match output: The PB1 pin can serve as an external output for the
Timer/Counter1 Compare Match A. The PB1 pin has to be configured as an output (DDB1
set (one)) to serve this function. The OC1A pin is also the output pin for the PWM mode
timer function.
PCINT1: Pin Change Interrupt source 1. The PB1 pin can serve as an external interrupt
source.
• ICP1/CLKO/PCINT0 – Port B, Bit 0
ICP1, Input Capture Pin: The PB0 pin can act as an Input Capture Pin for Timer/Counter1.
CLKO, Divided System Clock: The divided system clock can be output on the PB0 pin. The
divided system clock will be output if the CKOUT Fuse is programmed, regardless of the
PORTB0 and DDB0 settings. It will also be output during reset.
PCINT0: Pin Change Interrupt source 0. The PB0 pin can serve as an external interrupt
source.

Port C (PC5:0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
The PC5..0 output buffers have symmetrical drive characteristics with both high sink and
source capability. As inputs, Port C pins that are externally pulled low will source current if
the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition
becomes active, even if the clock is not running.
PC6/RESET
If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the electrical
characteristics of PC6 differ from those of the other pins of Port C.
If the RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level on this
pin for longer than the minimum pulse length will generate a Reset, even if the clock is not
running. Shorter pulses are not guaranteed to generate a Reset.
The various special features of Port C are elaborated in table
The alternate pin configuration is as follows:
• RESET/PCINT14 – Port C, Bit 6
RESET, Reset pin: When the RSTDISBL Fuse is programmed, this pin functions as a normal
I/O pin, and the part will have to rely on Power-on Reset and Brown-out Reset as its reset
sources. When the RSTDISBL Fuse is unprogrammed, the reset circuitry is connected to the
pin, and the pin can not be used as an I/O pin. If PC6 is used as a reset pin, DDC6, PORTC6
and PINC6 will all read 0.PCINT14: Pin Change Interrupt source 14. The PC6 pin can serve
as an external interrupt source.
• SCL/ADC5/PCINT13 – Port C, Bit 5
SCL, 2-wire Serial Interface Clock: When the TWEN bit in TWCR is set (one) to enable the
2-wire Serial Interface, pin PC5 is disconnected from the port and becomes the Serial Clock
I/O pin for the 2-wire Serial Interface. In this mode, there is a spike filter on the pin to
suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain
driver with slew-rate limitation. PC5 can also be used as ADC input Channel 5. Note that
ADC input channel 5 uses digital power. PCINT13: Pin Change Interrupt source 13. The PC5
pin can serve as an external interrupt source.

• SDA/ADC4/PCINT12 – Port C, Bit 4


SDA, 2-wire Serial Interface Data: When the TWEN bit in TWCR is set (one) to enable the
2-wire Serial Interface, pin PC4 is disconnected from the port and becomes the Serial Data
I/O pin for the 2-wire Serial Interface. In this mode, there is a spike filter on the pin to
suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain
driver with slewrate limitation. PC4 can also be used as ADC input Channel 4. Note that
ADC input channel 4 uses digital power. PCINT12: Pin Change Interrupt source 12. The PC4
pin can serve as an external interrupt source.

• ADC3/PCINT11 – Port C, Bit 3


PC3 can also be used as ADC input Channel 3. Note that ADC input channel 3 uses analog
power. PCINT11: Pin Change Interrupt source 11. The PC3 pin can serve as an external
interrupt source.

• ADC2/PCINT10 – Port C, Bit 2


PC2 can also be used as ADC input Channel 2. Note that ADC input channel 2 uses analog
power. PCINT10: Pin Change Interrupt source 10. The PC2 pin can serve as an external
interrupt source.

Port D (PD7:0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
The Port D output buffers have symmetrical drive characteristics with both high sink and
source capability. As inputs, Port D pins that are externally pulled low will source current if
the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition
becomes active, even if the clock is not running.

The alternate pin configuration is as follows:


• AIN1/OC2B/PCINT23 – Port D, Bit 7
AIN1, Analog Comparator Negative Input. Configure the port pin as input with the internal
pull-up switched off to avoid the digital port function from interfering with the function of
the Analog Comparator. PCINT23: Pin Change Interrupt source 23. The PD7 pin can serve as
an external interrupt source.

• AIN0/OC0A/PCINT22 – Port D, Bit 6


AIN0, Analog Comparator Positive Input. Configure the port pin as input with the internal
pull-up switched off to avoid the digital port function from interfering with the function of
the Analog Comparator.
OC0A, Output Compare Match output: The PD6 pin can serve as an external output for the
Timer/Counter0 Compare Match A. The PD6 pin has to be configured as an output (DDD6
set (one)) to serve this function. The OC0A pin is also the output pin for the PWM mode
timer function. PCINT22: Pin Change Interrupt source 22. The PD6 pin can serve as an
external interrupt source.

• T1/OC0B/PCINT21 – Port D, Bit 5


T1, Timer/Counter1 counter source. OC0B, Output Compare Match output: The PD5 pin can
serve as an external output for the Timer/Counter0 Compare Match B. The PD5 pin has to be
configured as an output (DDD5 set (one)) to serve this function. The OC0B pin is also the
output pin for the PWM mode timer function. PCINT21: Pin Change Interrupt source 21. The
PD5 pin can serve as an external interrupt source.

• XCK/T0/PCINT20 – Port D, Bit 4


XCK, USART external clock. T0, Timer/Counter0 counter source. PCINT20: Pin Change
Interrupt source 20. The PD4 pin can serve as an external interrupt source.

• INT1/OC2B/PCINT19 – Port D, Bit 3


INT1, External Interrupt source 1: The PD3 pin can serve as an external interrupt source.
OC2B, Output Compare Match output: The PD3 pin can serve as an external output for the
Timer/Counter0 Compare Match B. The PD3 pin has to be configured as an output (DDD3
set (one)) to serve this function. The OC2B pin is also the output pin for the PWM mode
timer function. PCINT19: Pin Change Interrupt source 19. The PD3 pin can serve as an
external interrupt source.

• INT0/PCINT18 – Port D, Bit 2


INT0, External Interrupt source 0: The PD2 pin can serve as an external interrupt source.
PCINT18: Pin Change Interrupt source 18. The PD2 pin can serve as an external interrupt
source.

• TXD/PCINT17 – Port D, Bit 1


TXD, Transmit Data (Data output pin for the USART). When the USART Transmitter is
enabled, this pin is configured as an output regardless of the value of DDD1. PCINT17: Pin
Change Interrupt source 17. The PD1 pin can serve as an external interrupt source.

• RXD/PCINT16 – Port D, Bit 0


RXD, Receive Data (Data input pin for the USART). When the USART Receiver is enabled
this pin is configured as an input regardless of the value of DDD0. When the USART forces
this pin to be an input, the pull-up can still be controlled by the PORTD0 bit. PCINT16: Pin
Change Interrupt source 16. The PD0 pin can serve as an external interrupt source.

AVCC
AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should be
externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC through a low-pass filter. Note that PC6..4 use digital supply voltage,
VCC.
AREF
AREF is the analog reference pin for the A/D Converter.
ADC7:6 (TQFP and QFN/MLF Package Only)
In the TQFP and QFN/MLF package, ADC7:6 serve as analog inputs to the A/D converter.
These pins are powered from the analog supply and serve as 10-bit ADC channels.

Overview
The ATmega48PA/88PA/168PA/328P is a low-power CMOS 8-bit microcontroller based on
the AVR enhanced RISC architecture. By executing powerful instructions in a single clock
cycle, the ATmega48PA/88PA/168PA/328P achieves throughputs approaching 1 MIPS per
MHz allowing the system designer to optimize power consumption versus processing speed.

BLOCK DIAGRAM
The AVR core combines a rich instruction set with 32 general purpose working registers. All
the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two
independent registers to be accessed in one single instruction executed in one clock cycle.
The resulting architecture is more code efficient while achieving throughputs up to ten times
faster than conventional CISC microcontrollers.

The ATmega48PA/88PA/168PA/328P provides the following features: 4K/8K bytes of In-


System Programmable Flash with Read-While-Write capabilities, 256/512/512/1K bytes
EEPROM, 512/1K/1K/2K bytes SRAM, 23 general purpose I/O lines, 32 general purpose
working registers, three flexible Timer/Counters with compare modes, internal and external
interrupts, a serial programmable USART, a byte-oriented 2-wire Serial Interface, an SPI
serial port, a 6-channel 10-bitADC (8 channels in TQFP and QFN/MLF packages), a
programmable Watchdog Timer with internal Oscillator, and five software selectable power
saving modes. The Idle mode stops the CPU while allowing the SRAM, Timer/Counters,
USART, 2-wire Serial Interface, SPI port, and interrupt system to continue functioning. The
Power-down mode saves the register contents but freezes the Oscillator, disabling all other
chip functions until the next interrupt or hardware reset.

In Power-save mode, the asynchronous timer continues to run, allowing the user to maintain a
timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the
CPU and all I/O modules except asynchronous timer and ADC, to minimize switching noise
during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while
the rest of the device is sleeping. This allows very fast start-up combined with low power
consumption.
The device is manufactured using Atmel’s high density non-volatile memory technology.
The On-chip ISP Flash allows the program memory to be reprogrammed In-System through
an SPI serial interface, by a conventional non-volatile memory programmer, or by an On-chip
Boot program running on the AVR core. The Boot program can use any interface to
download the application program in the Application Flash memory. Software in the Boot
Flash section will continue to run while the Application Flash section is updated, providing
true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-
Programmable Flash on a monolithic chip, the Atmel ATmega48PA/88PA/168PA/328P is a
powerful microcontroller that provides a highly flexible and cost effective solution to many
embedded control applications.
The ATmega48PA/88PA/168PA/328P AVR is supported with a full suite of program and
system development tools including: C Compilers, Macro Assemblers, Program
Debugger/Simulators, In-Circuit Emulators, and Evaluation kits.

Start with Arduino Uno

While using Arduino, the programs are called Sketch. By default the Arduino IDE will be
open as shown in the Figure
Figure 3: Arduino IDE Start up page.

The pins on the Arduino can be configured as either inputs or outputs. If we want make a
particular pin as Input / Output, we have to use ‘pinMode’ function. In that we have to use
INPUT or OUTPUT of the pin.

Properties of Pins Configured as INPUT

Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs
with pinMode() when you're using them as inputs. Pins configured this way are said to be in a
high-impedance state. Input pins make extremely small demands on the circuit that they are
sampling, equivalent to a series resistor of 100 mega ohm in front of the pin. This means that
it takes very little current to move the input pin from one state to another, and can make the
pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a
photodiode, or reading an analog sensor with a scheme such as RCTime.

This also means however, that pins configured as pinMode(pin, INPUT) with nothing
connected to them, or with wires connected to them that are not connected to other circuits,
will report seemingly random changes in pin state, picking up electrical noise from the
environment, or capacitively coupling the state of a nearby pin.

Properties of Pins Configured as OUTPUT

Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This
means that they can provide a substantial amount of current to other circuits. Atmega pins can
source (provide positive current) or sink (provide negative current) up to 40mA (milliamps)
of current to other devices/circuits. This is enough current to brightly light up an LED (don't
forget the series resistor), or run many sensors, for example, but not enough current to run
most relays, solenoids, or motors.

Short circuits on Arduino pins, or attempting to run high current devices from them, can
damage or destroy the output transistors in the pin, or damage the entire Atmega chip. Often
this will result in a "dead" pin in the microcontroller but the remaining chip will still function
adequately. For this reason it is a good idea to connect OUTPUT pins to other devices with
470Ω or 1k resistors, unless maximum current draw from the pins is required for a particular
application.

GPIO Programming

Program 1:

Interfacing LEDs with Arduino Uno to the pins 6 & 7. Make that LEDs ON & OFF
Alternately.

Solution:

int led1=6;
int led2=7;
void setup() {
// put your setup code here, to run once:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
delay(300);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
delay(300);
}

Program 2:
Interfacing a Switch and LED to the pins 11 and 13 respectively with Arduino Uno. Write the
program for if we press the switch then only the LED need to be ON, else LED need to be
OFF.

Solution:

int sw1=11;
int led=13;
void setup() {
pinMode(sw,INPUT);
pinMode(led,OUTPUT);
}
void loop() {
if(digitalRead(sw)==HIGH) {
digitalWrite(led,HIGH);
}
else {
digitalWrite(led,LOW);
}
}

Serial Communication

Serial Communication, Used for communication between the Arduino board and a computer
or other devices. All Arduino boards have at least one serial port (also known as a UART or
USART), and some have several.

On Uno, Nano, Mini, and Mega, pins 0 and 1 are used for communication with the computer.
Connecting anything to these pins can interfere with that communication, including causing
failed uploads to the board. You can use the Arduino environment’s built-in serial monitor to
communicate with an Arduino board. Click the serial monitor button in the toolbar and select
the same baud rate used in the call to begin().

Serial communication on pins TX/RX uses TTL logic levels (5V or 3V depending on the
board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and
can damage your Arduino board. To use these extra serial ports to communicate with your
personal computer, you will need an additional USB-to-serial adaptor, as they are not
connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an
external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your
device’s TX pin, and the ground of your Mega to your device’s ground.

Serial.begin()

Sets the data rate in bits per second (baud) for serial data transmission. For communicating
with Serial Monitor, make sure to use one of the baud rates listed in the menu at the bottom
right corner of its screen. You can, however, specify other rates - for example, to
communicate over pins 0 and 1 with a component that requires a particular baud rate.
Serial.print()

Prints data to the serial port as human-readable ASCII text. This command can take many
forms. Numbers are printed using an ASCII character for each digit. Floats are similarly
printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character.
Characters and strings are sent as it is.

Serial.println()

Prints data to the serial port as human-readable ASCII text followed by a carriage return
character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes
the same forms as Serial.print().

Serial.write()

Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the
characters representing the digits of a number use the print() function instead.

Program 3:

Write a program to transmit some data serially to the computer using Serial.print(),
Serial.println() and Serail.write() functions.

Solution:

void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(“Hi Arduino..”);
Serial.println(“For New Line”);
Serial.write(0x41); // Display Ascii Value of 0x41
}

Analog to Digital Converter (ADC)

analogRead()

Reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit
analog to digital converter. This means that it will map input voltages between 0 and the
operating voltage (5V or 3V) into integer values between 0 and 102 On an Arduino UNO, for
example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts
(4.9 mV) per unit.

Syntax

analogRead(pin)
Returns the output by reading the voltage on this pin. Although it is limited to the resolution
of the analog to digital converter (0-1023 for 10 bits). Data type: int.

Program:

Example Code to read the voltage on analogPin and displays it.

Solution:

int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3,
// outside leads to ground and +5V
int val = 0; // variable to store the value read
void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}

You might also like