Interface a button to Raspberry Pi

Raspberry PiĀ is an ARM architecture processor based board designed for electronic engineers and hobbyists. The PI is one of most trusted project development platforms out there now. With higher processor speed and 1 GB RAM, the PI can be used for many high profile projects like Image processing andĀ Internet of Things.

interface a button to raspberry pi
Button Interface to Raspberry Pi

For doing any of high profile projects, one need to understand the basic functions of PI. That is why we are here, we will be covering all the basic functionalities of Raspberry Pi in these tutorials. In each tutorial series we will discuss one of functions of PI. By the end of tutorial series you will be able to do high profile projects by yourself. Check these forĀ Getting Started with Raspberry PiĀ andĀ Raspberry Pi Configuration.

Establishing communication between PI and user is very important for designing projects on PI. For the communication, PI must take Inputs from the user. In this second tutorial of PI series, we will Interface a button to Raspberry Pi, to take INPUTS from the user.

Here we will connect a button to one GPIO Pin and an LED to another GPIO pin of Raspberry Pi. We will write a program in PYTHON, to blink the LED continuously, on pressing the button by the user. LED will be blinking by turning the GPIO On and Off.

Before going for the programming, letā€™s talk a bit about the LINUX and PYHTON.

LINUX:

LINUX is an Operating System like Windows. It performs all the basic functions which Windows OS can do. The main difference between them is, Linux is open source software whereĀ  Windows is not. What it basically means is, Linux is free while Windows is not. Linux OS can be downloaded and operated for free, but for downloading genuine Windows OS, you have to pay the money.

And another major difference between them is Linux OS can be ā€˜modifiedā€™ by tweaking into the code, but Windows OS cannot be modified, doing so will lead to legal complications. So anyone can take the Linux OS, and can modify it to his requirement in order to create his own OS. But we cannot do this in Windows, the Windows OS is provided with restrictions to stop you from editing OS.

Here we are talking about Linux because, JESSIE LITE (Raspberry Pi OS) is LINUX based OS, which we have installed in Raspberry Pi Introduction part. The PI OS is generated on the grounds of LINUX, so we have to know a bit about LINUX operating commands. We will discuss about these Linux commands in the following tutorials.

PYTHON:

Unlike LINUX, PYTHON is a programming language like C, C++, and JAVA etc. These languages are used to develop applications. Remember programming languages run on Operating System. You cannot run a programming language without an OS. So OS is independent while programming languages are dependent. You can run PYTHON, C, C++, and JAVA on both Linux and Windows.

Applications developed by these programming languages can be games, browsers, apps etc. We will use programming language PYTHON on our PI, to design projects and to manipulate the GPIOā€™s.

We will discuss a bit about PI GPIO before going any further,

As shown in above figure, there are 40output pins for the PI. But when you look at the second figure, you can see not all 40 pin out can be programmed to our use. These are only 26 GPIO pins which can be programmed. These pins go fromĀ GPIO2 to GPIO27.

TheseĀ 26 GPIO pins can be programmedĀ as per need. Some of these pins also perform some special functions, we will discuss about that later. With special GPIO put aside, we have 17 GPIO remaining (Light green Cirl).

Each of these 17 GPIO pins can deliver a maximum ofĀ 15mA current. And the sum of currents from all GPIO cannot exceed 50mA. So we can draw a maximum of 3mA in average from each of these GPIO pins. So one should not tamper with these things unless you know what you are doing.

Components Required:

Here we are usingĀ Raspberry Pi 2 Model BĀ with Raspbian Jessie OS. All the basic Hardware and Software requirements are previously discussed, you can look it up in theĀ Raspberry Pi Introduction, other than that we need:

  • Connecting pins
  • 220ā„¦ or 1Kā„¦resistor
  • LED
  • Button
  • Bread Board

Circuit Explanation:schematic interface a button to raspberry pi

For more detail: Interface a button to Raspberry Pi

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top