navigationGo.pngQuick Navigation
allprojects32.pngAll projects
hardware32.pngHardware
links32.pngLinks

favoriteStar32.pngTop projects
Alan numitron clock
Clapclap 2313/1386
SNES Pi Webserver
USB Volume/USB toys
Smokey amp
Laser cutter
WordClock
ardReveil v3
SNES Arcade cabinet
Game boy projects
cameleon
Home Presence Detector

github32.pngGitHub
AlanFromJapan

navigationMail.pngContact me

alanfjmail.png
3flags.pngWho's Alan?


Akizukidenshi
Elec-lab
Rand Nerd Tut
EEVblog
SpritesMods
AvrFreaks
Gameboy Dev
FLOZz' blog
Switch-science
Sparkfun
Suzusho
Datasheet Lib
Reddit Elec
Ermicro
Carnet du maker (fr)

Atmega328

Last update: Thu Jun 5 22:25:40 2025
kalshagar - atmega328
See also the project Rapide328 : a lightweight alternative to Arduino if you don't need usb

ATmega 328

... or simply using only ATmel µC and let the Arduino what it's made for : a wonderful prototyping tool.

Memo fact sheet

  • Code : 32k Bytes / EEPROM : 1024 Bytes / RAM : 2048 Bytes

ATmega328p is the core of an Arduino. You can build any Arduino compatible board by yourself,
for cheap if you discard the Serial-over-USB IC.
Receipe (bare minimum):
  • Quartz 16 MHz %20 2x 20pF condensator
  • Voltage regulation : LM7805 %20 100uF condensator (wallwart side) %20 10uF condensator (cirtcuit side)
  • ...and the official Arduino duemillanove schematic arduino-duemilanove-schematic.pdf

Afterward, code can be uploaded via a programmer (Pololu AVR Programmer for me) by soldering a nice 6pins connector OR by putting the chip onto an Arduino board. Just remove carefully the original Arduino chip and put it somewhere else. Put the blank chip in the correct place, connect the ISP programmer and upload a bootloader.
#!/bin/bash
avrdude -c avrispv2 -p m328p -D -P /dev/ttyACM0 -U flash:w:ATmegaBOOT_168_atmega328.hex
Then, you can upload code using Arduino IDE, or you could just directly burn the image you created (search the .hex file). You now have a chip that can run code exactly as is doing your Arduino for something like 1/3rd of the price. Note that I'm talking of the minimal version, excluding the Serial-over-USB, and that of course you will spend time soldering. That's a tradeoff, so up to you. But Arduino is not a end in itself, it's a wonderful prototyping tool; unless you want a perpetual USB connection and don't bother with USB power, Arduino is an overkill. Spend 2 hours preparing your Home-made-Arduino, you'll learn a lot.

You can make a "in place" programmer that you put over your cpu. I loooove the design, I have to make one (I always found that soldering that 6pin connector was a waste of time).
Another programmer, breadboard oriented. Not piggiback, not program in place but still quite elegant and useful.


Pins and legs of an ATmega328

pinout328color.pngatmega328.png
On this schema, you can see the chip with its legs (outer figures with no color) and how it is mapped to Arduino's pins. The 3 groups of pins are displayed with colors :
  • 0-7 digital,
  • 8-13 digital and
  • 0-5 analog/digital.

How to get 2 extra pins ?

Simple but you have to think of it : if you don't need precise clock nor speed > 8MHz, just use the internal oscillator and recycle the two crystal pins ! They are PB6 and PB7 and are just waiting for you ! How simple ... (source )

Fuses

Setting up the fuse is necessary (and potentially risky) to tell the uC to use a 16MHz crystal with slow startup (?), which speed, make read-only, ... It's not black magic, just be a little careful. There is a wondeful site for preparing the command line for you : http://www.engbedded.com/fusecalc/

The standard fuses for Arduino "Genuino"

avrdude -c avrispmkII -p m328p -P usb -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m -U efuse:w:0x05:m
PS: I read for the HIGH fuse alternate 0xDA or 0xD6 ... there's a good article on Sparkfun, well worth reading (also explains how to put the official bootloarder on a virgin ATmega).

Power consumption

Veeeeery low, like 1 mA when turned on (? to be confirmed).
Here's a link on how to make the power consumption go ultra low : http://news.jeelabs.org/2009/05/16/power-consumption-more-savings/

USB connection

Misc links:

I2C


Interrupts

Timers


Watchdog


External interrupt and Pin Change interrupt


Power considerations


$h!t I #&$!ed my Atmega's fuses

That happens to EVERYONE ... and to some more than to others.


PWM


Samples project


Interrupts

void setup() {
  D2 is input
  DDRD &= ~(1 << 2);
  pullup on D2
  PORTD |= (1 << 2);
 
  interrupt on falling hedge of INT0
  EICRA |= (1 << ISC01);
  INT0 enabled
  EIMSK |= (1 << INT0);
 
  Go interrupts !!
  sei();  
 
  pinMode(13, OUTPUT);  
}
 
void loop() {
   put your main code here, to run repeatedly: 
 
}
volatile int ledState = LOW;
 
ISR (INT0_vect) {
       if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
 
     set the LED with the ledState of the variable:
    digitalWrite(13, ledState);
}
All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated)
electrogeek.tokyo ~ Formerly known as Kalshagar.wikispaces.com and electrogeek.cc (AlanFromJapan [2009 - 2025])