How to Interface Buzzer with AVR Slicker

Interfacing buzzer with AVR Slicker

Tags: C Program to generate sound in AVR using Buzzer, Interfacing buzzer with AVR, Circuit Diagram to Interface Buzzer with AVR,
Overall rating
AVR Slicker Board

The AVR Slicker board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports In-system programming (ISP) which is done through Parallel/Printer port.

ATMEL’s AVR (Atmega8535), AVR Slicker Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.


Piezoceramic buzzers generate sound through the bending vibrations of a thin metal plate adhered to a piezoceramic disc.

These buzzers feature a low power consumption, a safe, spark-free and non-contact structure, and a small size and light weight for an easy mounting to Printed circuit boards. As a result, an increasing number of piezoceramic buzzers are now used to generate an artificial voice in combination with voice Synthesizing ICs. To produce high-quality piezoceramic buzzers, FDK has capitalized on many years of piezoceramic production and outstanding Ceramic processing technologies and thin film forming techniques. By adding a sophisticated audio know-how to this Manufacturing expertise, FDK offers a large array of electronic tone generating products, such as piezoceramic diaphragms, sounders and buzzers, to meet loud sound outputs, wide frequency ranges, and many other requirements.

Interfacing Buzzer


Fig. 1 shows how to interface The Buzzer to microcontroller. A piezoelectric element may be driven by an oscillating electronic circuit or other audio signal source, driven with a piezoelectric audio amplifier. Sounds commonly used to indicate that a button has been pressed are a click, a ring or a beep. When the input port pin from microcontroller is changed, the sound wave is changed in Buzzer.

Interfacing Buzzer with AVR

A small piezoelectric buzzer on the AVR Slicker Kit, by pulling pin PORTB.1 low, current will flow through the buzzer and a relatively sharp, single-tone frequency will be heard.

The alternative Pressing of Character A or B in HyperTerminal can be used to modulate the buzzer to oscillate around different frequencies. Then the volume of the sound will be changed by alternating the pulse width.

Pin Assignment with AVR







Connect PORTB with J19 (E-MECH) via FRC Cable

Turn ON TXD and RXD Pins of CONFIG-I switch SW24.

Connect Serial cable between USART Section in the  Board and PC and open HyperTerminal

Press RESET Once (If Necessary)

Press A-D to turn ON and  OFF buzzer and relay.




Circuit Diagram to Interface Buzzer with AVR


Source Code

Below is the source code to interface the buzzer with the AVR microcontroller using AVR Slicker board with the help of CodeVision AVR Software.

C Program to generate sound in AVR using Buzzer


Title : Program to generate sound using Buzzer







#define TXIF  UCSRA.5

#define RCIF  UCSRA.7


#define FOSC        16000000L   //Oscillator Frequency 16Mhz 

#define USART_Baud  9600                                                

#define BaudH       ((unsigned int)(((FOSC/16/USART_Baud)-1) >> 8))

#define BaudL       ((unsigned int)(((FOSC/16/USART_Baud)-1) & 0xFF))


#define Buzzer  PORTC.6


void Serial_init(void);

unsigned char Receive(void);


void main()

    unsigned char RecDat=0;

    DDRC = 0xff;

    PORTC= 0x00;





        RecDat = Receive();



          case 'A':Buzzer=1;break;

          case 'B':Buzzer=0;break;


        printf("%c ",RecDat);




void Serial_init()


     UCSRA = 0x00;           //Status Register

     UCSRB = 0x18;           //Transmit Enable,Receive

                             //enable,interrupts disabled   

     UCSRC = 0x86;           //8 databits,no parity,single  


     UBRRH = BaudH;

     UBRRL = BaudL;


     printf("Buzzer:\tPress 'A' to ON\n\r\tPress 'B' to OFF\n\r"); 



void putch(unsigned char Data)



  UDR = Data;



unsigned char Receive()



  return UDR;



To compile the above C code you need the CodeVision AVR software. The software has it’s own IDE and built-in AVR gcc- Compiler. They must be properly installed and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In CodeVision AVR software, you can develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without microcontroller Board.

The AVR Code Blaster software is used to download the hex file into your microcontroller through Parallel port.

Testing the Buzzer with AVR Slicker

Give +12V power supply to AVR Slicker Board; the Buzzer is already connected with Board. Download the hex file to AVR Slicker .After downloading Connect the serial cable between pc and the AVR Slicker and set the configuration switch as per the user manual. When we press the character A in pc the buzzer will creating some sound and Pressing B will off the sound.

If you are not getting any sound from Buzzer, then you just check the configuration switch position & check the Buzzer is working or not. Otherwise you just check it with debugging mode in CodeVision AVR.

General Information

  • For proper working use the components of exact values as shown in Circuit file.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,
       -  User Manual of AVR Slicker Board.
       -  How to create & Debug a Project in CodeVision AVR.

Join the World's Largest Technical Community

we respect your privacy.