Introduction to ATmega328p Pinout, datasheet and specifications

The ATmega328p is a single-chip, high-performance, efficient microcontroller created by Atmel in the megaAVR family. It is an 8-bit AVR RISC-based microcontroller chip. In this post, we will learn about the ATmega328p pinout, its datasheet, specifications, and programming methods in detail.

Atmega328p IC
Atmega328p IC

It consists of 32 KB ISP flash memory with read-while-write capabilities, 2 KB SRAM(Static RAM), 1 KB of EEPROM, 23 general-purpose I/O pins, a 16MHz clock, 32 general purpose working registers, three flexible timer/counters with compare modes (two 8 bits and one 16 bit), internal and external interrupts, serial programmable UART, a byte-oriented I2C (inter-integrated circuit) interface pins, SPI serial port, 6-channel 10-bit Analog to Digital converter, programmable watchdog timer with internal oscillator, and five software selectable power saving modes. The device operates between a voltage range of 1.8-5.5 volts.

Note: 328p in ATmega328p means: 32 for 32KB of flash memory, 8 for Bit RISC architecture(data bus), and p for “pico-power” (consumes less power under certain circumstances)

Atmega328P Pinout:

ATmega328P pinout
ATmega328P pinout
Pin No.Pin NamePin FunctionPin Function Description
1PC6ResetThis pin helps to reset the microcontroller.
2PD0Digital Pin (RX)This is the input pin for serial communication
3PD1Digital Pin (TX)This is the output pin for serial communication
4PD2Digital PinIt is used as an external interrupt 0
5PD3Digital Pin (PWM)It is used as an external interrupt 1
6PD4Digital PinIt is used for external counter source Timer0
7VccPositive VoltagePositive supply of the system.
8GNDGroundThe Ground of the system
9XTALCrystal OscillatorThis pin should be connected to one pin of the crystal oscillator to provide an external clock pulse to the chip
10XTALCrystal OscillatorThis pin should also be connected to the other pin of the crystal oscillator to provide an external clock pulse to the chip
11PD5Digital Pin (PWM)Pin 11 is used for external counter source Timer1
12PD6Digital Pin (PWM)Positive Analog Comparator i/ps
13PD7Digital PinNegative Analog Comparator i/ps
14PB0Digital PinCounter or Timer input source pin
15PB1Digital Pin (PWM)Counter or Timer compare match A.
16PB2Digital Pin (PWM)This pin act as a slave choice i/p.
17PB3Digital Pin (PWM)This pin is used as a master data output and slave data input for the SPI interface.
18PB4Digital PinThis pin act as a master clock input and slave clock output.
19PB5Digital PinThis pin act as a master clock output and slave clock input for SPI.
20AVccPositive VoltagePositive voltage for ADC (power)
21AREFAnalog ReferenceAnalog Reference voltage for ADC (Analog to Digital Converter)
22GNDGroundThe Ground of the system
23PC0Analog InputAnalog input digital value (channel 0)
24PC1Analog InputAnalog input digital value (channel 1)
25PC2Analog InputAnalog input digital value (channel 2)
26PC3Analog InputAnalog input digital value (channel 3)
27PC4Analog InputAnalog input digital value (channel 4). This pin can also be used as a serial interface connection for data.
28PC5Analog InputAnalog input digital value (channel 5). This pin is also used as a serial interface clock line.

Atmega328p Specifications

Program Memory TypeFlash
Program Memory Size (KB)32
SRAM (B)2,048
Data EEPROM/HEF (bytes)1024
Digital Communication Peripherals1-UART, 2-SPI, 1-I2C
Capture/Compare/PWM Peripherals1 Input Capture, 1 CCP, 6PWM
Timers2 x 8-bit, 1 x 16-bit
Number of Comparators1
Temperature Range (°C)-40 to 85
Operating Voltage Range (V)1.8 to 5.5
Pin Count32
Low PowerYes

ATmega328p Datasheet:

Atmega328p datasheet contains all the information you need to get started with it. 

**To download the Atmega328p datasheet, click here

ATmega328p based Microcontroller boards:

Adafruit METRO 328 – Adafruit METRO 328 is quite a user-friendly microcontroller. It has an ATmega328 at the core with 32KB of flash and 2KB of RAM running at 16MHz.

Arduino Pro Mini 328 – The Arduino Pro Mini 328 is a microcontroller board which that has an ATmega328 chip at its core. It consists of 14 digital input/output pins (of which 6 are PWM outputs), 6 analog inputs, an onboard resonator of 8 MHz, a reset button, and holes for mounting pin headers. A six-pin header can be connected to an FTDI cable or TTL serial adapter to power up the board and also for programming purposes.

Arduino Uno R3 – The Arduino Uno is an open-source microcontroller board that is based on the microchip ATmega328P. It consists of 6 analog input pins, 14 digital input/output pins (of which 6 are PWM enabled), a 16 MHz ceramic crystal resonator, a USB-B port, an ICSP header, a power jack, and a reset button.

Arduino Nano – Arduino Nano has the same functionality but is smaller in size than Arduino Uno. The other difference is that there is no DC power jack on Nano and is powered using a Mini-B USB cable instead of a standard one.

ATmega328p Programming Methods:

Programming microcontrollers can be difficult to some extent, as they require special programmers and .hex files. And also the expertise of the C programming language is needed to write the code.

To make it easier, Arduino created a .hex file that can be installed on AVR chips that allow us to program the board over a serial port. This ensures that in order to program a microcontroller (after installing the hex file) all you need is a serial connection between the microcontroller and the Computer which can be achieved using a USB to UART adapter. This hex file is called the Arduino Bootloader.

During the manufacturing process for electronic devices, microcontrollers are usually programmed after they have been mounted on the PCB. This programming method is called as In-System Programming (ISP) and it requires the PCB to have certain header pins through which the microcontroller can be accessed for programming.

Most Arduino boards come with 2×3 pin headers which are used for purpose of In-System programming known as in-circuit serial programming (ICSP). The Arduino ICSP header pins comprise of 3 SPI pins (MOSI(D11), MISO(D12), SCK(D13)), VCC, GND, and a reset pin. By connecting an Atmega328p microcontroller to ICSP pins, we can flash the Atmeg328p microcontroller with the Arduino bootloader.

Required Components

The following components are required to flash the bootloader in the ATmega328p chip:

  1. Arduino Uno
  2. Jumper Wires
  3. Breadboard
  4. Atmega328p microcontroller
  5. 16 MHz crystal oscillator
  6. 22pf capacitors

Procedure for Burning Bootloader to ATmega328p-

  1. Prepare the Arduino as an ISP Programmer

In the Arduino IDE, under the file tab>Examples one of the examples is the “Arduino as ISP” which when uploaded to an Arduino board transforms the board into an ISP programmer. Open this example and Upload it to the Arduino Uno board.

Preparing Arduino as an ISP Programmer
Preparing Arduino as an ISP Programmer

  1. Wiring 

Next, connect the Atmega328p to be flashed to the Arduino via a breadboard as shown in the Figure below.

Schematics for burning bootloader
Schematics for burning bootloader 

Below is a pin map of the connections of the above figure:

Arduino – Atmega328P D13 – Pin 19D12 – Pin 18D11 – Pin 17D10 – Pin 1 Reset (no Capacitor needed).VCC – 5VGND – GND

  1. Burn the Bootloader

With the connections done as shown in the figure, we can now burn the bootloader to the microcontroller chip. In the Arduino IDE under tools tab> Boards, then select the Arduino Uno as the board type. The next step is to go to tools>programmer and select “Arduino as ISP” as the programmer. The final step to burn the bootloader to the chip is to go to tools and select the burn Bootloader option.

Burn bootloader Atmega328p
Burn bootloader Atmega328p

How to program ATmega328p using Arduino IDE:

To program the ATmega328p microcontroller using the Arduino IDE, the microcontroller can be connected via some sort of hardware to the computer. This is usually done in two major ways:

  1. Using a USB to Serial/TTL Adapter
  2. Using an Arduino board

Using a USB to Serial/TTL Adapter:

The USB to Serial/TTL adapter is used to converts data signals from the USB on the computer to serial/TTL for the microcontroller and vice versa. This enables communication from the microcontroller (serial) with the Arduino IDE running on the PC (USB).

Required Components:-

The following components are required for this approach;

  1. Atmega328P microcontroller with the Arduino Bootloader installed
  2. Breadboard
  3. USB to serial/TTL Adapter
  4. 16MHz crystal oscillator
  5. 22pf capacitors x2
  6. 100nf capacitor
  7. Jumper Wires
  8. 100 ohms resistor
  9. LED


Connect USB to Serial/TTL adapter to the ATmega328p chip as shown in the figure below.

ATmega328p to serialTTL adapter connection
ATmega328p to serial TTL adapter connection

**Image source: programming ATmega328p

Uploading Code

Uploading code to the microcontroller is an easy task to be done, after typing in your code, select the port to which your adapter is connected, followed by the board type “ATmega328p” and hit the upload button. The upload will finish up only a few seconds and the ATmega328 chip will be ready to use.

Using an Arduino Board:

The second way involves the use of an Arduino board in either of two similar methods:

  1. By replacing the microcontroller on the Arduino Uno with the one to be programmed
  2. By using any of the Arduino boards as an In-system programmer.

The first way is the easier way to upload code to the ATmega328p chip, as it involves just replacing the microcontroller present on the Uno, with the one we need to program. Just swap the microcontrollers and hit the upload button.

The second method way involves the use of the Arduino Uno as an In-system programmer. Like we burn Bootloader in the chip, we can also use the Arduino ICSP header to upload code into the ATmega328 chip.

Required components

  1. Arduino Uno
  2. Breadboard
  3. USB to serial/TTL Adapter
  4. 16MHz crystal oscillator
  5. 22pf capacitors x2
  6. Jumper Wires
  7. 10k resistor
  8. 100 ohms resistor
  9. LED


Connect the components as shown in the figure below.

Arduino to ATmega328p connection to upload code
Arduino to ATmega328p connection to upload code

Note: While using this approach, it is important to remove the microcontroller of the Arduino board to prevent interference.

Upload Code

The code upload process is the same as already described. Select the code file that is to be uploaded on the ATmega328p, then select the board type (ATmega328p) and also the correct port, and click upload. The code will be uploaded to the microcontroller.

Projects and applications of ATmega328p:

There are many applications of Atmega328P in the real world.

The ATmega328P chip is compatible with a large set of program and system development tools such as C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits.

The fast PWM mode also provides a high-frequency PWM waveform generation. This allows it to be suited for power adjustment, rectification, and DAC (Digital to Analog Converter) applications. Some major applications for the chip are listed below:

  • Industrial machinery controlling systems
  • Solar-powered machinery and applications
  • IoT based applications
  • Power supply and charger-based applications
  • Weather systems
  • Wireless communication applications
  • Security-based applications
  • Medical & health-related projects & systems
  • Automobile related applications

Read Similar Articles:

| Arduino UNO pinout and specifications in detail

| Arduino Nano pinout and specifications in detail

Arduino Pro Mini pinout and specifications in detail

Leave a Comment