DIY Arduino : Standalone ATMEGA328 configuration

Bored of using ready-made Arduino UNO, Nano, Micro, Pro Mini boards? Or want to give your project a complete DIY look by replacing those ready-made board with a single ATMEGA328 and few components? This tutorial might be helpful to make your own Arduino or flexible design to your circuit. Design a standalone ATMEGA328 configuration, let’s start !!

Components required : 

  1. ATMEGA328 – DIP28 preferable for testing (1)
  2. 16 MHz crystal (1)
  3. 22pf Ceramic capacitors (2)
  4. 10K Resistor (1)
  5. Breadboard (For testing purpose)
  6. Arduino UNO for burning the Arduino bootloader in controller

Usually, ATMEGA328 are available in market with Arduino bootloader and enables you to program it through Arduino IDE, but you may not get it with bootloader all the time. By using Arduino IDE you can simply upload the sketch into the flash memory of microcontroller. Bootloader is a small piece of code which is executed at every reset of the microcontroller and that looks for a sketch to be uploaded from the serial/USB port using a specific protocol and speed. If no connection is detected, the execution is passed to the code of your sketch. Approx. 512 bytes of code called bootloader is in an area of the memory of the microcontroller – at the end of the address space – that can’t be reprogrammed as a regular sketch and had been designed for such purpose.

Image Source: www.arduino.cc

To program the bootloader and provide to the microcontroller the compatibility with the Arduino Software (IDE) you need to use an In-circuit Serial Programmer (ISP) that is the device that connects to a specific set of pins of the microcontroller to perform the programming of the whole flash memory of the microcontroller, bootloader included. The ISP programming procedure also includes the writing of fuses: a special set of bits that define how the microcontroller works under specific circumstances. So first we will see how to burn bootloader in ATMEGA328 using ISP.

Step-1: Prepare your Arduino UNO as Arduino ISP

The process of loading the bootloader code and burning properly the fuses to make an ATMEGA microcontroller an “Arduino”, is managed by the Arduino Software (IDE): it provides a specific menu item and allows you to use a variety of programming devices. Among the programmers, the “Arduino as ISP” is the cheapest and most practical solution to burn a bootloader on another Arduino board with ATMEGA, 32U4 or ATtiny, and in our case it is standalone ATMEGA328 aka bare-bone Arduino.

The SPI interface – and therefore these pins – is the interface used to program the AVR microcontrollers. Note that MISO, MOSI, and SCK are available in a consistent physical location on the ICSP header; this connector is used also by shields that rely on the SPI interface allowing the design of shields that work on every board.

Before proceeding for activity, make sure nothing is connected on Arduino UNO’s ISP & UART pins. Open ArduinoISP sketch from above default path in Arduino IDE, Plug Arduino UNO & upload the sketch. 

Step-2: Burn Bootloader in your ATMEGA328

After ArduinoISP sketch is uploaded successfully in Arduino UNO, Connect the components as shown in following diagram.

Arduino Standalone Breadboard Configuration

Arduino Standalone Breadboard Configuration

As shown in above diagram, Breadboard has plugged with ATMEGA328 IC, 16 MHz Crystal, 22pF Capacitors & a 10K resistor. Configuration is powered up by Arduino UNO +5V & GND. The main part is ATMEGA328 ISP connection with Arduino UNO, so make sure you connect it as shown in diagram, follow pin map mentioned in below table.

ATMEGA328 Arduino UNO Pin Map

After connecting as above mentioned circuit, select Arduino board type you want burn bootloader as it is necessary to select proper bootloader & fuse bit settings. The programming procedure checks the signature of the microcontroller before any writing action is taken, but many boards share the same microcontroller and each board has its own bootloader. The port remains the one of the ArduinoISP.

Choose “Burn bootloader” under tools and wait for the confirmation message in the lower part of the Arduino Software (IDE) interface.

Step-3: Program your ATMEGA328:

Most easiest way is to upload sketch in ATMEGA328 is serial programming mode. The programming process manages the three SPI lines (MISO, MOSI and SCK) according to the standard SPI programming protocol, the same used to read and write SD memory cards. The only difference with memory cards is the lack of a CS (Chip select) pin. On our AVR microcontrollers we use the RESET pin that halts the execution of any sketch or bootloader and puts the microcontroller in a specific state where it listens to the commands arriving from the SPI interface. The very first command that the protocol requires is the one that enters the microcontroller in the Serial Programming Mode.

Once this specific mode is active, we can write and read all the microcontroller programmable areas: Flash, EEPROM and Fuses. At the end of the Flash memory, we have the bootloader code area, as highlighted in the image at the beginning of this article. The “Burn Bootloader” procedure also sets properly the fuses of the microcontroller according to the design of the board. This is one of the reasons why you have to burn the bootloader selecting your exact board model in the list.

So, you have finished burning bootloader in your ATMEGA328, now in further we will see how to upload sketched in ATMEGA328 using USB to Serial. You can use separate USB-Serial converters like CH340 or CP2102, but here we will use Arduino UNO itself as it has similar configuration on board & for that you need to modify Arduino UNO & ATMEGA328 connections a little bit, also remove ATMEGA328 from Arduino UNO.

Upload sketch in ATMEGA328 using Arduino UNO (On-board controller removed)

As shown in above diagram, disconnect ISP connections and connect Arduino UNO D0 to ATMEGA328 Pin-2 & Arduino UNO D1 to ATMEGA328 Pin-3. Connect Reset pin of Arduino UNO to ATMEGA328 Pin-1.

Now you need to add hardware support in Arduino IDE for standalone configuration. You can download hardware configuration from here. Unzip the file and paste in following path. 

Restart Arduino IDE, now you can see “ATMEGA328 on a breadboard (8 MHz internal clock)” in the Tools > Board menu,, select that and upload any sketch you want in your standalone board. You can upload blink sketch for a quick test. Here you have uploaded a sketch from Arduino IDE software to ATMEGA328 which was without bootloader earlier and you made it !!

Express recap:

  1. Open ArduinoISP example in Arduino IDE, plug Arduino UNO in computer.
  2. Select board & port from ‘Tools’, upload ArduinoISP sketch in your Arduino UNO.
  3. Connect your circuit as shown in ‘Arduino Standalone Breadboard Configuration’ image in this tutorial.
  4. Select board on which you want to burn the bootloader (not the board that you are using as ISP).
  5. Select Arduino as ISP in Programmer.
  6. Go to Tools, click ‘Burn Bootloader’.
  7. After burning bootloader, connect ATMEGA328 & Arduino UNO for serial programming method.
  8. Add ATMEGA328 on a breadboard (8 MHz internal clock) in board list of Arduino IDE.
  9. Upload any sketch you want, Eurekaaaa !!!!

I hope this tutorial will be helpful to give your project a DIY look & will save size, power & cost. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.