Using Atmega32 With Arduino IDE





Introduction: Using Atmega32 With Arduino IDE

Over time I have used all kinds of Atmel microcontrollers in various projects.

One of the most suitable was ATmega32. I have a small collection of development boards for Atmega32/16, some bought as-is, some made on stripboard.

Although the original Arduino boards offers a pleasant experience and a rapid development of the projects, when it was necessary to "extract" these projects to give them final shape I hit the well-known problem: arduino board must be "locked" in the project.

It is not only the price. Although a microcontroller in thru-hole package is significantly bigger than SMD version, it is still much smaller than an Arduino board.

And still I want to use the Arduino IDE to benefit from the collection of (very well made) (ready-to-use) libraries.

So I gathered together information useful for this purpose.

Step 1: Things You Will Need:

  1. Atmega32 microcontroller. :)
  2. Programmer (any programmer recognized by Arduino IDE). I use the USBasp programmer.
  3. Minimal setup for power-up Atmega32 microcontroller (breadboard, stribpoard or a classical development board).

We do not need all, photos above are for exemplification only.

Step 2: Software Set-up

  1. Download zip file attached to this instructables.
  2. Locate file boards.txt in arduino folder ...arduino-1.5.2\hardware\arduino\avr\boards.txt
  3. Append information from zip archive boards.txt to original boards.txt
  4. Make a folder named mega32 in ...arduino-1.5.2\hardware\arduino\avr\variants
  5. Copy file pins_arduino.h from the zip into folder created at step 4.
  6. Start Arduino IDE and select board.
  7. Select programmer

Later edit:

I removed link to github projet where I originally found. As long as there source changed and not fit this instructable.

After a message from the author: Eric Conner, I put back link to github project where I originally found this library:

Note: Zip file attached to this article is an older version of above library. This will work as this instructable was written.

Over time, after some feedback I noticed that source from github has changed.

Also, in comments you will see references to some errors, and how to to correct it.

This article and answers from comments is relate to version attached here, not github (newer) version.

Step 3: Done.

It's done.

Now you can try some simple examples that are already in Arduino.

Be very careful about correlation between ARDUINO pin and microcontroller pin.

Here is blink example: Files->Examples->Basics->Blink

Pin13 Arduino == Pin19 (PD5) Atmega32

  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second

After some comments I found two errors in the file pins_arduino.h

So I’ll post here the errors and correct values.

erroneous definition of SCL and SDA

const static uint8_t SDA = 8; //wrong
const static uint8_t SCL = 9; //wrong

must be changed in:

const static uint8_t SDA = 17; //correct
const static uint8_t SCL = 16; //correct

Since I am not the author of the project on github, it is subject to change beyond my control.

So please use code attached to this instructable and make above modifications.


For Serial library to work properly must be made following changes to the file HardwareSerial.cpp
In ...\arduino-1.5.8\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp

will replace:

#if defined(__AVR_ATmega8__)
	config |= 0x80; // select UCSRC register (shared with UBRRH) 


#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega16__)
	config |= 0x80; // select UCSRC register (shared with UBRRH) 

See also:



  • Spotless Contest

    Spotless Contest
  • Science of Cooking

    Science of Cooking
  • Microcontroller Contest

    Microcontroller Contest

We have a be nice policy.
Please be positive and constructive.






ADC is not working on hardware but its works on proteus (software simulation).

i use USB-asp for uploading hex

Hello together,

i've encountered a problem. I've tried to read the ADC via "analogRead(A0)" for example. And the compiler responded with the error "'A4' was not declared in this scope".

also the function #define doesn't accept the argument A0 up to A7; does anybody else have expierenced this problem?

I also tried to read the value by using its digital Pin Number, but there is for example ADC5 = D26, but i need to insert "analogRead(27)" to get the corresponding value for ADC5;

thanks if you could help me with my problem here

analogRead(0); //-> physical pin 40 (ADC0)
analogRead(1); //-> physical pin 39 (ADC1)
analogRead(7); //-> physical pin 33 (ADC7)

Pins A0-A7 are not defined. These definitions make sense for standard Arduino boards, where these pins are labeled on the PCB.

For this approach, I think is more intuitive as shown above.



LiquidCrystal lcd (5, 4, 3, 2, 1, 0);

const int ldrPin = A0;

void setup() {

lcd.begin(16, 2);

pinMode(ldrPin, INPUT);


void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <=300) {

lcd.setCursor (0, 0);

lcd.print ("XX");


else {

lcd.setCursor (0, 1);

lcd.print ("YY");



Hello Silvius,

I uploaded a simple blink sketch using arduino as ISP to blink an LED at PD7 with a delay of 250 ms. But the delay seems too long, about 4000 ms, which is 16x the amount I needed. Is there any problem with timing? How to solve it?

Put some fusebits according with your osc... here are my fuse bits... read from working atmega32 with 16MHz quartz and USBASP. Working in Arduino IDE and AVR Studio:
low fuse :DE
high fuse: D9

hi Silvius

how to boot loader atmega32a with Arduino mega2560 board ?

hi Silvius!!

i m getting error of missing 'upload.tool'
configuration parameter, when uploading the code to Atmega 32 using
usbasp as programmer...plz help me in resolving the problem.

error while burning bootloader: missing 'bootloader.tool' configuration parameter

i am getting these error while i am trying to put bootloader in atmega32 and i am using usbasp as programmer, plz help me whr i am doing mistake

There are no bootloader in this setup. Just use USBASP to upload your code.