With serial communication you can exchange data with the AVR-microcontroller and your PC. Allmost all AVR-microcontroller have a UART (Universal Asynchronous Reciever/Transmitter) on board of the chip (accept for some ATTiny microcontrollers).


The data transmission between the PC and the microcontroller is serial and asynchronous, serial means that the bits are send one after the other and asynchronous means that there is no clock signal to clock in the data that is send or recieved. One byte is transmitted in 10 bits, 1 start bit, 8 data bits and one stop bit, as you can see in the figure below. 

The serial data transmission has a standard that is called RS232. According to this standard a logical "0" has a voltage level between -15V and -5V and a logical "1" has a level between +5V and +15V. The AVR-microcontrolers use 5V (TTL-level) to transmit signals. So the signals needs to be converted, this can be done with the MAX232 IC, that only needs a 5V power supply to convert the signal from TTL-level to RS232 level and reverse. 
Transmission between two RS232 devices can take place with a maximum distance of 15 meters.


Below you can see the schematic of how the RS232 convertor is connected to the ATTiny2313 microcontroller. The ATTiny2313 board is equiped with the hardware for serial communication with your PC. You can buy the ATTiny2313 board at www.bizztronix.eu.


The software is written on C The program sends a text string to the microcontroller and echos it back to the terminal.
First step of the program is the initialization of the UART, that is setting the baud rate, enable the transmitter and receiver and setting the frame rate.

To test the program you can use the BR@y terminal emulator.The settings for the COM port are: COM1,9600,N,8,1.

// program name: UART send/receive text
// date: 2014.01.25
// author: www.avrprojects.net
// target device: atmega328
// purpose: usart demo - transmit/receive data to the PC terminal
// usart registers:
// usart data register --> UDR
// usart control and status register A --> USCR0A
// usart control and status register B --> USCR0B
// usart control and status register C --> USCR0C
// usart baud rate register --> UBRR0H & UBRR0L
// UDR --> data register

#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define FOSC 16000000 // set clock speed
#define BAUD 9600 // baud rate
#define MYUBRR FOSC/16/BAUD-1 // calculate baud rate

void usart_init(unsigned int ubrr)
//usart init
/*set baud rate*/
UBRR0H = (unsigned char) (ubrr>>8);
UBRR0L = (unsigned char) ubrr;
/*enable receiver & transmitter*/
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
/* set frame rate format: 8 data 2 stop bit*/
UCSR0C = (1<<USBS0) | (3<<UCSZ00);

void usart_transmit(unsigned char data)
// Wait if a byte is being transmitted
while(!(UCSR0A & (1<<UDRE0)));
// Transmit data
UDR0 = data;

void transmit_text(char text[])
int i = 0;
while (i<255)
if( text[i] == '\0' ) break;
usart_transmit (text[i++]);

unsigned char usart_receive(void)
// Wait until a byte has been received
while((UCSR0A&(1<<RXC0)) == 0);
// Return received data
return UDR0;

void receive_text (char text[])
int i = 0;
while (i<64)
text[i++] = usart_receive();
if(text[i-1] == '\n') break;

int main(void)

char string[64];


while (1)
strcpy (string,"");