My Account

Wish List (0)

GPIO & Python (4/9) - Push Button

Written by in YouTube Workshop Kit on .

In this project you’ll learn how to make a LED blink!

Things you will need:

Raspberry Pi + SD Card
Keyboard + Mouse
Monitor + HDMI Cable
Power Supply
1x Red LED
1x Blue LED
2x 330Ω Resistor
1x M/M Jumper Wire
4x M/F Jumper Wire
1x Button


Latest version of Rasbian installed on your SD Card
Raspberry Pi setup with a keyboard, mouse and monitor

1. Change the current directory to our gpio_python_code directory:

cd gpio_python_code 

2. Start by creating a file for our button script


3. Edit the script using nano add the following code:


import os
from time import sleep
import RPi.GPIO as GPIO


# setup our input pin
# we use an internal pull up resistor to hold the pin at 3v3, otherwise the inputs value could chatter between high and low

GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    if ( GPIO.input(10) == False ):
        print("Button Pressed")
        os.system('date') # print the systems date and time
        print GPIO.input(10)
        os.system('clear') # clear the screens text
        print ("Waiting for you to press a button")

4. Execute your script

sudo python

5. Now press the button

6. To stop your script, simply press ctrl+c

Last update: Feb 22, 2017


Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.