07- AVR ATmega 16 Tutorials- Interfacing a Push Button || Digital Input Sensing

Hello everyone, Welcome back to the Blog.

In this post, I would like to go back to the first circuit we created for interfacing an LED and modify it to include a Push Button. I am going to try to control the rate of blinking of the LED with the help of the button. So in short what I am aiming for is if the Push Button is pressed the LED should toggle at a rate of 100  milliseconds, else it should toggle itself at a rate of 1000 milliseconds.

Before I do that let’s get a better understanding of switches and buttons. A switch is a device which is designed to interrupt the current flow in a circuit, in other words, it can make or break an electrical circuit. Every electrical and electronics application uses at least one switch to perform ON and OFF operation for the device. So the switches are part of a control system and without it, the control operation cannot be achieved. A switch can perform two functions, namely fully ON (by closing its contacts) or fully OFF (by opening its contacts). When the contacts of a switch are closed, the switch creates the closed path for current flow and hence load consumes the power from the source. When the contacts of a switch are open, no power will be consumed by the load.

Switches can be generally classified into two types: Mechanical and Electronic.

  • Mechanical switches must be activated physically, by moving, pressing, releasing, or touching its contacts.
  • Electronic switches do not require any physical contact in order to control a circuit. These are activated by semiconductor action.

Here are a few examples of switches:

Different Switch Types
Push Button

For our purposes, I have used a Push Button which looks like the picture to the left. It is a momentary switch which closes the circuit only when the button is pressed. At all other times, the circuit remains open. This type of switch is ideal for giving impulse inputs for a short amount of time and also is quite inexpensive.

Now, I would like you all to go through the video below where I explain everything in details as well as build the circuit along with explaining the working of the code. I have given the detailed circuit diagram along with the code for your convenience below the video so do check that out too after watching the video.


Now, you should be having a clear idea of what we are doing in the circuit and in the code. I have also given the circuit diagram along with the code below for your convenience. Feel free to modify it as you see fit. Download the Makefile needed for compilation and copy it into the folder where you have saved the source file.

In the Circuit below I have just added the Push Button to PIN1 of PORTA of the microcontroller.

 Circuit Diagram:


Shop Smart with us for Best Prices:

If you want to continue on with this series I would ask you to visit our YouTube channel and subscribe to receive continuous notifications. You can also subscribe to our Newsletter below to get email notification of each post as and when they are posted.

You can also follow us on social media platforms such as  Facebook and Twitter.

Thanks a lot for reading through this post. Feel free to follow through this series and comment your queries in the comment box below. Also feel free to contact us regarding any out of stock product and we will try to get back to you as soon as possible.