Running Atmega328 in a standalone mode without Arduino Shield

In this post I will describe how to use a Atmega328P chip without Arduino board.
This kind of electronic circuit is much cheaper than an Arduino board and can be used with the same programming environnement and the same code to do exactly the same stuffs.

Price : less than $10.00

 

 

Needed Hardware

ArduinoUno_r2_front450px

Arduino Uno

The Arduino Uno will be used only as a programmer for the following circuit.

atmega328_MED
A Atmega328P

Price: $5.95 at Adafruit

CFR-25JB-10K
A 10kOhm Resistor

Price: $0.10 at Digikey

ZTT-MT,MX SERIES_sml
A 16Mhz resonator

Price: $0.70 at Digikey

That’s all 🙂

Atmega 328P

First of all you have to be familiar with Atmega328P (be careful it is better to use a Atmega328P instead of a Atmega328).

Here is the Atmega328P datasheet.

Ok, ok, there  is a lot of text to read. So here is the most important thing : the pinout of the atmega to be used as an Arduino:

Capture d’écran 2014-03-06 à 21.52.42

 

Right now, you have to know that Atmega on an Arduino board is already loaded with the Arduino Bootloader. So the first thing to do it to load the arduino bootloader into the Atmega328P.

Load the Arduino Bootloader into the atmega328P

To do so, we need to use an Arduino Board. Here we will use Arduino Uno. And here is the question : “How the first Arduino has been loaded :)”

Load Arduino ISP

First load Arduino ISP into your Arduino Uno — sorry My Arduino IDE is in French — File > Samples > Arduino ISP:

Capture d’écran 2014-03-06 à 21.57.42

 

The project is now open, load it into the Arduino Uno Board.

Then configure Arduino IDE to use the Arduino Uno as ISP Programmeur Tools>Programmer>Arduino as ISP:

Capture d’écran 2014-03-06 à 22.08.07

 

 

 

Load the bootloader onto the Atmega238P

 

Now it’s time to talk about our Atmega328P: To load the bootloader on it, we need to make this circuit:
Untitled

photo 2

 

Done. Now You can burn the Arduino Bootloader to the Atmega: Tools > Burn Boot Sequence

Capture d’écran 2014-03-06 à 22.32.52

 

Done! Your Atmega is ready to be programmed

Mounting the standalone Atmega – circuit

Now you can use the Atmega in a standalone mode. To do so, you first have to program it. On  this step we will also use the Arduino Uno Board. But We will now use it only as a programmer so first of all you have to REMOVE THE ATMEGA FROM THE ARDUINO BOARD. Put it aside for now, your Arduino board is now empty.

photo 3

 

Now let’s do a circuit to program our Atmega328P
program

unnamed

 

 

Run a simple program

Now configure your Arduino IDE to default –  Tools>Programmer>AVR ISP:

Capture d’écran 2014-03-06 à 22.44.20

Just to test I wrote a little simple program

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
 
void loop() {
  // put your main code here, to run repeatedly: 
  Serial.println("It works");
  delay(5000);
}

Run it as you usually run an Arduino program. And it works…

Capture d’écran 2014-03-06 à 22.50.25 Yeah!!

Troubleshooting

While I ordered some Atmega I made a mistake and I bought an Atmega328 instead of a Atmega328P. Ooops!

So when you try to upload the bootloader on this kind of Atmega the IDE says:

arvdude: Expected signature for ATMEGA328P is 1E 95 0F

Actually Atmega328 is not supported buy Arduino even if it works. So How to make it work? It is quite simple, here a little workaround from instructable:

In your Arduino folder, find the subfolder: ..\hardware\tools\avr\etc

  1. Make a backup copy of the file: avrdude.conf
  2. Open the file avrdude.conf in a text editor
  3. Search for: “0x1e 0x95 0x0F” (this is the ATmega328P signature)
  4. Replace it with: “0x1e 0x95 0x14” (this is the ATmega328 signature)
  5. Save the file
  6. Restart the Arduino IDE
  7. Continue with the rest of the steps in the instructable, and once bootloading is complete restore the backup copy you made.

Hope this helps.

21 Comments

  1. Yo, il est faux ton schema “Now let’s do a circuit to program our Atmega328P” le RESET se branche sur le RESET et non sur le Pin 13 😛

    Reply
  2. Your tutorial was very helpful! Thank you! But one thing concerns me: You said to remove the ATmega328P that was on the Arduino board. But when I remove that chip, do I purchase another ATmega chip and replace it back on the board? And How do i program the new ATmega chip to have Arduino codes?

    Also the chip that I removed from the board, do I use that as a standalone for the small project? Or do I use the ATmega chip which I purchased?

    Reply
  3. Hi Vincent
    Very good Tutorial – than you.
    I got an error while burning:
    avrdude: usbdev_open(): did not find any USB device “usb”
    I use arduino uno 1.0.1, selected “Arduino Uno”, ArduinoISP version 04m3 (2008-2011), serial Port: /dev/ttyACM0, which works with the board.
    What`s wrong?
    Many thanks for your help
    ditmar

    Reply
  4. I am getting the following error. Boot loader is done. Sketch not able to download. Please suggest.
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x0e

    Reply
  5. thank you so much for your efforts .
    I had a problem with uploading the final program to the atmega 328p with Tx and Rx , so I replaced it with the avr which was on the chip then I uploaded the code again , it worked well .

    Reply
  6. nice Tutorial.
    However there is no need to remove the Atmega from the Arduino Board when u want to programm the the standalone chip.
    Just upload the Arduino as ISP sketch (examples) on your arduino. Then connect the Arduino Board to the standalone chip(the same way as described above).
    Open your sketch and click “Sketch” -> “Upload Using Programmer”
    This way you will upload your sketch to your standalone chip without the need to remove the Atmega-Chip of your Arduino-Board.
    (Gets annoying fast and you will damage the chip eventually)

    Reply
  7. Hello,
    I follow your tutorial to load my programm to an ATMEGA328P (except that I use the usb2serial board to load the program because I have an Arduino Uno Rev 3 smd)

    I have a problem. When I try to put external power Supply (5V) It doesn’t work. It only works when I connect 5V from the USB.

    My power supply doesn’t have current limit, and I also try with other one, the problem is the same?

    Do you have an idea?

    Thanks

    Reply
  8. Sir Thank you so much i got but if i upload other sketch for example blink led it will not work Why and what is the reason please reply as soon as possible

    Reply
  9. hi.thanks for your help.but i have this error in mine.
    ***failed;
    avrdude: WARNING: invalid value for unused bits in fuse “efuse”, should be set to 1 according to datasheet
    This behaviour is deprecated and will result in an error in future version
    You probably want to use 0xfd instead of 0x05 (double check with your datasheet first).
    what i should to do???

    Reply

Leave a Comment.