I have a PI B and i am having a bit of trouble with my GPIO pins. I am running a simple script to check if a button has been pressed that is hooked up up to pin 7. The problem is as soon as i conntect the jumper cable to the pi (other end is free) the script starts saying that the button is pressed. This is before the pi is even hooked up to the breadboard.

Code is:

import RPi.GPIO as GPIO
import time

buttonPin = 7

if (GPIO.input(buttonPin)):



2 Answers 2


You need a pull up or pull down resistor. right now your pin 7 is 'floating', meaning there is nothing to determine the voltage on that wire, so it picks up all the RF that is around it, everything from TV, Radio, Cell phone, WiFi, anything that uses radio waves. See here for more information.


As an expansion to Butters answer. The raspberry has build in pull-up and pull-down resistors. To activate this, in your case, use

GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.