Parts
ATmega328P: DIP-28 pinout, Arduino pin map, ratings and a standalone circuit
By Bulan Sarkar
On the DIP-28 ATmega328P, pin 1 is RESET, VCC is pin 7, ground is pins 8 and 22, AVCC is pin 20 and the crystal goes on pins 9 and 10. Arduino Uno pins D0 to D7 are port D, D8 to D13 are PB0 to PB5 (chip pins 14 to 19), and A0 to A5 are PC0 to PC5 (pins 23 to 28).
This page covers which chip you are holding, the limits in Microchip's datasheet DS40002061B, how fast it may run at a given supply, how much current its pins can take, and a standalone circuit with a 16 MHz crystal. The ATmega328 and ATmega328PB come in only where their datasheets say they differ.
Datasheet: Microchip ATmega48A/PA/88A/PA/168A/PA/328/P megaAVR Data Sheet, DS40002061B (PDF)Ask Datasheet Guru about the ATMEGA328P-PU
Pinout by package
Top view, notch up: pin 1 (RESET) top left, pins 1 to 14 down the left side and 15 to 28 back up the right.
Pin 20 (AVCC) must go to VCC even if you never use the ADC.
Source: Microchip ATmega48A/PA/88A/PA/168A/PA/328/P megaAVR Data Sheet, DS40002061B, p. 12 (Figure 1-1, 28 SPDIP top view with every pin and its alternate functions); Microchip ATmega48A/PA/88A/PA/168A/PA/328/P megaAVR Data Sheet, DS40002061B, p. 14 (AVCC must be connected to VCC even when the ADC is not used; ADC6 and ADC7 exist only on TQFP and VQFN); Microchip ATmega48A/PA/88A/PA/168A/PA/328/P megaAVR Data Sheet, DS40002061B, p. 635 (ordering information: ATmega328P-PU is the 28P3 package, 28-lead 0.300 inch SPDIP)
Which one do you have?
The through-hole part is the ATmega328P-PU: P for picoPower, PU for the 28-lead 0.3 inch SPDIP (Microchip's code 28P3). The same chip also comes as ATmega328P-AU (32-lead TQFP) and -MU (32-pad VQFN), which add ADC6 and ADC7 on pins the DIP does not have. An -PN suffix is the same DIP rated to 105 °C.
The ATmega328 without the P has the same pins and memory but lacks the brown-out switch-off in sleep and has a different signature byte. The ATmega328PB is a different chip: 32 pins, TQFP or QFN only, no DIP. A programmer tells all three apart by their signature, which is the first test to run on a chip of unknown origin (see the bench check below).
Arduino Uno pin numbers
The D and A numbers are the Arduino Uno board's convention, set by the Arduino software, not by Microchip. The port names and the functions in the right-hand column are from the datasheet's pin figure (p. 12).
| Arduino | Port pin | DIP pin | Datasheet functions |
|---|---|---|---|
| D0 | PD0 | 2 | RXD |
| D1 | PD1 | 3 | TXD |
| D2 | PD2 | 4 | INT0 |
| D3 | PD3 | 5 | INT1, OC2B (PWM) |
| D4 | PD4 | 6 | T0, XCK |
| D5 | PD5 | 11 | T1, OC0B (PWM) |
| D6 | PD6 | 12 | AIN0, OC0A (PWM) |
| D7 | PD7 | 13 | AIN1 |
| D8 | PB0 | 14 | ICP1, CLKO |
| D9 | PB1 | 15 | OC1A (PWM) |
| D10 | PB2 | 16 | SS, OC1B (PWM) |
| D11 | PB3 | 17 | MOSI, OC2A (PWM) |
| D12 | PB4 | 18 | MISO |
| D13 | PB5 | 19 | SCK |
| A0 | PC0 | 23 | ADC0 |
| A1 | PC1 | 24 | ADC1 |
| A2 | PC2 | 25 | ADC2 |
| A3 | PC3 | 26 | ADC3 |
| A4 | PC4 | 27 | ADC4, SDA |
| A5 | PC5 | 28 | ADC5, SCL |
The six PWM outputs are D3, D5, D6, D9, D10 and D11, one pair per timer. The ISP programming pins are D11, D12 and D13 (MOSI, MISO, SCK) plus RESET.
Absolute maximum ratings
Only Microchip makes the ATmega328P, so there is no second maker to compare. The disagreement is inside the one datasheet: the maximum ratings allow 6.0 V and 40 mA per pin, but the chip is specified only up to 5.5 V, and the output voltages are guaranteed only up to 20 mA per pin. Design to the lower figures: 5.5 V and 20 mA.
| Parameter | ATmega328P-PUDIP-28 |
|---|---|
| Supply voltage, absolute maximum VCC | 6.0 V |
| Voltage on any pin except RESET | −0.5 V to VCC + 0.5 V |
| Voltage on RESET | −0.5 V to +13.0 V |
| DC current per I/O pin | 40.0 mA |
| DC current, VCC and GND pins | 200.0 mA |
| Operating temperature (absolute) | −55 to +125 °C |
| Storage temperature | −65 to +150 °C |
The RESET pin is the exception that tolerates more than the supply: up to 13 V. Every other pin is held to 0.5 V outside the rails, which is why a 5 V signal must not reach a chip running at 3.3 V.
Clock, pin levels and supply current
| Parameter | ATmega328P-PUDIP-28 |
|---|---|
| Operating supply VCC | 1.8 to 5.5 V |
| Maximum clocklinear between the corners (Figure 29-1) | 4 MHz at 1.8 V, 10 MHz at 2.7 V, 20 MHz at 4.5 to 5.5 V |
| Output low voltage VOLIOL = 20 mA, VCC = 5 V, 85 °C | 0.9 V max |
| Output low voltage VOLIOL = 10 mA, VCC = 3 V, 85 °C | 0.6 V max |
| Output high voltage VOHIOH = −20 mA, VCC = 5 V, 85 °C | 4.2 V min |
| Output high voltage VOHIOH = −10 mA, VCC = 3 V, 85 °C | 2.3 V min |
| Input thresholds, I/O pins VIL / VIHVCC = 2.4 to 5.5 V | low below 0.3 VCC, high above 0.6 VCC |
| Sum of sink current per pin groupsteady state, three groups | 100 mA per group |
| Sum of source current per pin groupsteady state, two groups | 150 mA per group |
| I/O pull-up resistor RPU | 20 to 50 kΩ |
| RESET pull-up resistor RRST | 30 to 60 kΩ |
| RESET threshold VRST | 0.2 VCC to 0.9 VCC |
| Minimum RESET pulse tRST | 2.5 µs |
| Crystal capacitors C1 = C28 to 16 MHz crystal | 12 to 22 pF |
| Internal RC oscillatorfactory calibration, 3 V, 25 °C | 8.0 MHz ±10% |
| Supply current, active ICC8 MHz, VCC = 5 V | 5.2 mA typ, 9 mA max |
| Supply current, power-down ICCwatchdog off, VCC = 3 V | 0.1 µA typ, 2 µA max |
| Analog supply AVCC | VCC − 0.3 V to VCC + 0.3 V |
| Internal ADC reference VINT | 1.0 to 1.2 V (1.1 V typ) |
The pin voltages, pull-ups and group current limits come from Table 30-1. This revision of the datasheet prints no common DC table in its 85 °C chapter, and Table 30-1 gives the 85 °C limits beside the 105 °C ones.
Between the corners the line is straight, so the limit at any supply can be worked out. From 10 MHz at 2.7 V to 20 MHz at 4.5 V the clock rises 10 MHz over 1.8 V. For 16 MHz: 2.7 + (16 − 10) × 1.8 / 10 = 3.78 V. At 3.3 V the limit is 10 + 0.6 × 10 / 1.8 = 13.3 MHz. A 3.3 V board with a 16 MHz crystal runs the chip outside its rating, which is why 3.3 V designs use 8 MHz.
At 5 V an input reads low below 1.5 V and high above 3.0 V. A 3.3 V sensor output clears that by 0.3 V at best, with no margin for noise; see the 3.3 V to 5 V level shifter guide and the logic levels lesson.
What it is good for
- Moving an Arduino Uno project off the board and onto a stripboard or PCB: the chip, a crystal, two capacitors and a resistor, as in the example below.
- Battery sensor nodes. Power-down with the watchdog off is 0.1 µA typical at 3 V, and the 328P can switch its brown-out detector off while it sleeps.
- Small control jobs needing up to six PWM outputs, six ADC inputs on the DIP, one UART, one SPI and one I²C bus.
- Learning AVR registers and ISP programming on a chip that fits a breadboard.
It is the wrong chip for 16 MHz at 3.3 V, for two serial ports at once, or for USB. The ATmega328PB adds a second UART, SPI and I²C but has no DIP. For the older 8051 family in a 40-pin DIP, see the AT89S52 page.
Worked example: a standalone ATmega328P at 16 MHz
The circuit an Arduino Uno runs its chip in, built from parts: 5 V supply, 16 MHz crystal, reset button, and an LED on D13 to prove it works.
1. Check the clock against the supply. 16 MHz needs at least 3.78 V (Figure 1). At 5 V there is 1.22 V to spare.
2. Pick the crystal capacitors. For an 8 to 16 MHz crystal the datasheet recommends 12 to 22 pF, equal on both sides. We use 22 pF. The crystal sees the two in series, 22 × 22 / (22 + 22) = 11 pF, plus the board and pin capacitance.
3. Pull RESET up. The chip has its own pull-up of 30 kΩ to 60 kΩ. A 10 kΩ resistor to 5 V in parallel brings that to 7.5 kΩ to 8.57 kΩ, which keeps a long wire from picking up a stray reset. The button pulls the pin to ground; while it is held it passes at most 5 V / 7.5 kΩ = 0.7 mA. Any press is far longer than the 2.5 µs minimum reset pulse.
4. Wire both supplies. VCC (pin 7) and AVCC (pin 20) both go to 5 V, each with a 100 nF capacitor to the ground pin beside it (pins 8 and 22). AVCC must stay within 0.3 V of VCC. A 100 nF capacitor from AREF to ground steadies the ADC reference; the datasheet suggests one without giving a value.
5. Size the LED resistor. A red LED drops about 2 V. For 10 mA or less, R ≥ (5 − 2) V / 10 mA = 300 Ω. The next E12 value up is 330 Ω, giving at most 9.1 mA, well under the 20 mA the pin is specified to.
6. Add up the pins. 6 such LEDs on PB0 to PB5 (D8 to D13) draw 54.5 mA together. Those pins share one 100 mA sink group and one 150 mA source group, and the whole chip's VCC pin is rated 200 mA, so this is inside every limit.
One step is not wiring. A new chip leaves the factory running on its internal 8 MHz oscillator divided by 8, so 1 MHz, and ignores the crystal until its clock fuses are changed. Program the fuses (or burn an Arduino bootloader, which sets them) before you expect 16 MHz. At the factory 1 MHz, the programmer's SPI clock must stay below 250 kHz; at 16 MHz it may go up to 2.67 MHz.
The sink groups are PC0 to PC5 with ADC6 and ADC7; PB0 to PB5 with PD5 to PD7 and the crystal pins; and PD0 to PD4 with RESET. The two source groups split the pins differently, so check both lists in the notes to Table 30-1 when a design loads many pins at once. The LED resistor calculator does step 5 for other colours.
Worked example in numbers
- Minimum supply at 16 MHz
- 3.78 V
- Crystal capacitors
- 22 pF
- RESET pull-up, total
- 7.5 kΩ to 8.57 kΩ
- LED current, D13
- 9.1 mA
Tips and checks
- Put the crystal and its two capacitors right against pins 9 and 10, with the capacitor grounds going straight to pin 8. Long leads here are the usual reason a breadboard build will not start.
- Keep any pin at 20 mA or less. Above that, or for anything inductive, drive a transistor; the MOSFET guide for Arduino and ESP32 picks one.
- Use the internal pull-ups (20 to 50 kΩ) for buttons. They are weak, so for I²C on A4 and A5 fit proper external pull-ups.
- At 3.3 V, run at 8 MHz or less. The internal oscillator gives 8 MHz without a crystal, but only to ±10% as shipped (±1% after you calibrate it), so keep a crystal for serial links.
- On the DIP there are six ADC inputs, not eight. ADC6 and ADC7 exist only on the TQFP and VQFN packages.
Substitutes: the ATmega328, 168PA and 328PB
The ATmega328 and ATmega168PA drop into the same socket. The ATmega328PB does not: it has no DIP package.
A programmer reads the 328PB as 0x1E 0x95 0x16 (its datasheet, p. 333), so a build set for the 328P will not load onto it unchanged. It needs its own board layout and its own build settings.
Bench check: is the chip alive, and at what clock?
- With power on, measure 5 V on pins 7 and 20 against pin 8, and about 5 V on pin 1. RESET sitting low means a shorted button or a missing pull-up.
- Connect an ISP programmer to D11, D12, D13 and RESET and read the signature. An ATmega328P answers 0x1E 0x95 0x0F; 0x14 in the last byte means an ATmega328. On a new chip, slow the programmer below 250 kHz first.
- Load a blink sketch built for 16 MHz with a one-second delay. If each blink takes 16 seconds, the chip is still on its 1 MHz factory clock: set the fuses.
- For a direct look, the CKOUT fuse puts the system clock out on PB0 (pin 14), where a scope or frequency counter should read 16 MHz.
What we'd do
Buy the ATmega328P-PU, read its signature before it goes into a board, and set the fuses or burn the bootloader first. Build it at 5 V and 16 MHz exactly as Figure 2: 22 pF on the crystal, 10 kΩ on RESET, 100 nF on each supply pin and AVCC wired. On 3.3 V, drop to 8 MHz. Hold every pin to 20 mA and switch anything bigger through a transistor.
Questions people ask
What is the ATmega328P pinout?
On the DIP-28: pin 1 RESET, 2 to 6 PD0 to PD4, 7 VCC, 8 GND, 9 and 10 the crystal (PB6, PB7), 11 to 13 PD5 to PD7, 14 to 19 PB0 to PB5, 20 AVCC, 21 AREF, 22 GND and 23 to 28 PC0 to PC5.
Which Arduino pin is which ATmega328P pin?
By the Arduino Uno convention, D0 to D7 are PD0 to PD7, D8 to D13 are PB0 to PB5, and A0 to A5 are PC0 to PC5. D13, the on-board LED pin, is chip pin 19.
ATmega328 or ATmega328P: what is the difference?
Same pins and memory. The P can switch its brown-out detector off in sleep and has lower maximum currents. Their signatures differ (0x14 against 0x0F), so a programmer set for one rejects the other.
Can an ATmega328P run at 16 MHz on 3.3 V?
Not within its rating. 16 MHz needs 3.78 V, and at 3.3 V the limit is 13.3 MHz. 3.3 V boards use 8 MHz.
How much current can an ATmega328P pin give?
Plan on 20 mA per pin, the most the output voltages are specified at. 40 mA is the absolute maximum. Each group of pins may sink 100 mA and source 150 mA in total, and the VCC pin carries 200 mA at most.
Is the ATmega328PB a drop-in replacement?
No. It comes only in 32-pin TQFP and QFN, adds a second UART, SPI and I²C, and needs code built for it.
Buying the ATmega328P in India
The DIP ATmega328P-PU is stocked by most Indian online component shops, often sold "with Arduino bootloader" for a little more. Read the print: ATmega328P, not ATmega328, and check the signature when it arrives. A chip sold as pre-loaded saves the fuse step only if the bootloader is really there, so test it with a blink sketch before it goes into a board. Our guide to buying electronic components in India compares ten online sellers and covers how to spot fakes.
One email a month from the bench
New circuits, lessons, part guides and calculators, on the first Sunday of each month.
Used in these lessons
Lessons that go deeper
Datasheets this page was checked against
- Microchip, ATmega48A/PA/88A/PA/168A/PA/328/P megaAVR Data Sheet, DS40002061B (Rev. B, 09/2020 (© 2020))
- Microchip, ATmega328PB Datasheet, 40001906A (Rev. A, 04/2017)
Makers revise datasheets. If the copy you download has a newer revision and a number here disagrees with it, the datasheet wins, and we would like to hear about it.