Interface the Atmega 16/32 with the PC

May 18, 2009 at 20:19 (microcontroller, Uncategorized)

There are many ways to interface your microcontroller to computer , the most easiest way is using serial port and MAX-232.In this tutorial is about how to interface a ATMEGA32 to your computer using serial  port , max232 and programming the atmega32 using CodeVisionAVR.


ATMEGA32 is a 8-bit AVR microcontroller with 32K Bytes In-system Programmable Flash. In Atmega32pins pin no.14 and 15 are RxD and TxD resp. For basics of atmega32 click here


In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time.Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals and various peripherals.

MAX232: As we know for serial port we require TIA/EIA-232-F voltage level i.e. it can accept ±30-V. MAX232 has a capacitive voltage generator to supply TIA/EIA-232-F voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F inputs to 5-V TTL/CMOS levels.

So, to interface the atmega32 to the computer we will be connecting atmega32 (pin no 14 & 15) to serial port via max232. We are using max232 because atmega32 works at TTL voltage level and for serial port we require other voltage level, max232 converts the TTL voltage level to the required voltage level.

Atmega32 will receive the signal from MAX232 and transmit to max232 which will be received by serial port. Do the following connections:

  1. connect pin no 2 (Tx) of serial port to Tx out of the MAX 232 IC (pin no 14)
  1. connect pin no 3 (Rx) of serial port to Rx in of the MAX 232 IC (pin no 13)
  2. connect pin no 14 (RxD) of Atmega to Rx out of MAX 232 IC (pin no 12)
  3. connect pin no 15 (TxD) of Atmega to Tx in of MAX 232 IC (pin no 11)
  4. Do other necessary connections like ground and Vcc.


  1. By selecting UART tab of the CodeWizardAVR , you can specify the UART configuration
  2. Specify the baud rate and communication parameter.
  3. Click on save, generate and exit.
  4. Write the code.
  5. Burn the program.
  6. Open the terminal in CodeVisionAVR TOOL—-à TERMINAL (shift + F5).
  7. Specify the baud rate and communication parameter.(ensure that you specify the same parameter which you have specify in step 2)
  8. In terminal you monitor the whole operation.


NOTE: instead of terminal of CodeVisionAVR you can use other software like DockLight.

It allows us to specify the following communication modes:

  • Asynchronous
  • Synchronous Master, with the UCSRC register’s UCPOL bit set to 0
  • Synchronous Master, with the UCSRC register’s UCPOL bit set to 1
  • Synchronous Slave, with the UCSRC register’s UCPOL bit set to 0
  • Synchronous Slave, with the UCSRC register’s UCPOL bit set to 1

The serial communication is realized using the Standard Input/Output Function getchar , gets , scanf , putchar , puts and printf.


If we want to write program in which, when button ‘a’ on keyboard is pressed then all the LED connected to PORTA should be ON , when button ‘s’ is pressed all LED should be OFF.

#include <mega32.h>

#include <stdio.h> // Standard Input/Output functions

Void main()




// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud Rate: 9600






while (1)


if (getchar() == ‘a’)




if (getchar() == ‘b’)






In this way you can interface your ATMEGA32 to your computer. In similar way you can control the motor (in semi-autonomous BOT).

u can also view this post @

………………….if you found this tutorial helpful or have any suggestions … do leave a comment.



  1. Mahi said,

    while i was doing my first project i didn’t know how to connect atmega with PC this tutorial help me a lot thanks

  2. mohamad said,

    This tutorial help me a lot.
    Best regards.

  3. luka said,

    Can this be used with ATmega8?

    • praveendb said,

      yes u can.
      pin no of Rx n Tx r different……

      • luka said,


  4. erfan said,

    thank you. keep going

  5. Arunabh said,

    Could u please tell me about REVERSE INTERFACING

    i.e. if pin 1 of port A is high, the pc reacts in a certain manner

    suppose that it displays A1 if a text editor is open.

    or suppose a java front , it opens a desired file. . .(say).

  6. Arunabh said,

    Could u please tell me about REVERSE INTERFACING

    i.e. if pin 1 of port A is high, the pc reacts in a certain manner

    suppose that it displays A1 if a text editor is open.

    or suppose a java front , it opens a desired file. . .(say).

    and one more thing if will be really grateful if i could contact u directly by mail or even in any community site

  7. Ichrul said,

    could u tell me how to make USB interfacing with ATmega16?
    please help me..
    thanx a lot…

  8. Matze said,

    A really helpful tutorial

  9. udit said,

    i m doing engg. and i want to know
    how can i control sound files which are in my laptop using microcontroller by usart or parallel port

  10. udit said,

    when i read from usart how can i start or open the sound file
    pls… do reply waiting….. my project is in complete

  11. chandu said,

    good discription

  12. امپراتور said,

    its prefect

  13. amauri said,

    thaaaaaaaaaaaaaaaaanks this is rly helpful

  14. Ozymandias said,

    I owe you a beer, because this is exactly what i was looking for.

    • praveendb said,


  15. Sudheendra said,

    i need to write a code which accepts the characters from keyboard .. if i press character w then dc motor should move in forward direction and on pressing ‘s’ reverse .. similarly ‘a’ for left and ‘d’ for right .. please help me out ..
    thank you

    • praveendb said,

      i have given this in code
      if (getchar() == ‘w’)
      if (getchar() == ‘s’)
      repeat this code segment for a and d………..

  16. dan said,

    thanx very much…

  17. varghese said,

    man tats soooo grt i waz lookin for this since a long time u have helped me a lot…….but can u please send me some pics of this programmer…….

  18. Avjeet said,

    Can you please share the connection diagram for the programming ( i.e Burning code into atmega16). i am confused about that circuit. please reply soon. Thanks in advance.:)

  19. Nael said,

    Hi I have a circuit that reads the temperature, need to send the result of the reading circuit to the PC, anyone can help me please. ATMEGA48 programmed into the basic language use tool AVR BASCOM

  20. mag said,

    HI~ if i want to use VB6 send a word to control PORTA on/off,
    such send “on” to control PORTA on, and send “off” to control PORTA off.

    please help me,thank you~


    Hi sir..thanks for the last information.Now I’m doing a project traffic light which can detect if have faulty.I use ATmega32 to create the traffic light circuit.And i have idea to interface the circuit to connect with computer.The traffic light can be function without connect to PC because the microcontroller already have the programme to control the LED.But the problem is i have to connect this circuit to PC to detect the faulty.Which can display warning if there is faulty such indicator faulty, delay faulty and etc.The circuit i get from “”..with this circuit can i use interface which you told as above.I’m very new and learning all this.I want idea whether this circuit and interface can use or not.If can how to create the coding to detect the faulty like if there is no led blink ‘0’ how to detect it.Thank you.

    • praveendb said,

      mail me the details…

  22. Ritesh said,

    It helped me in understanding the basics.
    Thank you.

  23. Mayank Kachhwaha said,

    everything is perfect….just picture doesn’t show clear….i hope you’ll update it again with clarity ….thanks in advance

    • praveendb said,

      will try
      dunno where i saved those pics…

  24. Sugnan Dani said,

    Hey … thanks a lot 4 the info… it s too basic and very nice to understand… 🙂 I just wanted to know the code for interfacing sensor with ATMEGA 16 in Code Vision AVR…… i’l be very obliged….. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: