Switch with AVR Atmega32A Microcontroller

This tutorial is about how to use button switch with AVR Atmega32A Microcontroller. In previous tutorial we have seen, how to drive LED connected to Pin “PB0” and in this tutorial lets have a look at, how to connect button to PB1 pin of microcontroller so that will control LEDs blinking by pressing button switch (tactile switch). To keep simplicity in example we’ll blink LED by 10 ms when button pressed and blink LED by 100 ms when button switch is released.

Button Switch With ATmega32A

In general to control hardware we often need to provide some sort of input to system through human interaction. As an example, if we take our personal computer we use mouse and keyboard to provide input to a system and then system react accordingly. If you look at keyboard, which is nothing but the bunch of buttons. I believe this tutorial will help you to understand concept. Let’s have a look at circuit connection for this experiment.

Button-Input- ATmega32A
Button Switch with ATmega32A

Short Explanation:

In code snippet you can see in main loop first two lines DDRB |= 1 << PBo assign PB0 pin as output for LED and DDRB &= ~(1<< PB1) assign pin PB1 as input for button switch to read input though button.

In while loop “bit_is_clear” function takes two argument (PINB,1) which used to continuously monitor state of button either pressed or un-pressed and if its un-pressed then turn LED off. This way one can give input from button switch with ATmega32A at very basic level. I hope you will find this tutorial educational and entertaining if you have question then post comment below.

About Umesh Lokhande

Umesh Lokhande holds a Master degree in Scientific Instrumentation from University of Applied Sciences Jena, Germany. and has previously worked at Orbotech, Alere Technologies etc. Umesh is also a founder and first author of BINARYUPDATES.COM


  1. are u also help to how to programme 89v51rd2 microcontroller

  2. Hello Shailesh,

    You can program 89v51rd2 using flash magic tool its very simple. I have made video for flash magic on YouTube Channel of BINARYUPDATES.

    Here are some quick links you may find useful:




    Good Luck and write me if in case you still not able to solve

    Good Day

Leave a Reply

Your email address will not be published. Required fields are marked *


Register | Lost your password?