Tom Lewis
Posts: 22
Joined: Mon Jul 02, 2012 12:14 pm

Baisc GPIO basic switch

Wed Nov 14, 2012 3:07 pm

Hello all, im a noob when it comes to electronics, I have myself a basic starter kit with breadboard and so far have managed to turn on and off some LED's, my next test is inputing via switches, I bought a bunch to play with, one is a "missile launch switch" So either on or off, How would I wire this to the pi's GPIO? Also what kind of signal would this send back to the pi? Would it send an "on" signal once? The idea would be to pickup this signal in PHP and do with whatever...

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
Contact: Website

Re: Baisc GPIO basic switch

Wed Nov 14, 2012 3:21 pm

One of my first projects included using a switch.

http://rpi.tnet.com/project/hardware/project001

The page includes breadboard layout, and photos of the actual construction. I didn't use PHP for the script (Which when sensing the button is pressed, causes the system to do a shutdown), but I could have called the same code from a PHP script.

There are other examples on the Raspberry Pi Wiki as well.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

User avatar
Grumpy Mike
Posts: 916
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Baisc GPIO basic switch

Thu Nov 15, 2012 1:29 pm

How would I wire this to the pi's GPIO?
One wire to the GPIO pin and the other to the ground pin.
When your program initialises this GPIO pin as an input, you should also specify you want the pull up resistor to be enabled. However if you use GPIO 0 & 1 on the old issue 1 boards or GPIO 2 & 3 on the new issue 2 baords then there is already a hardware pull up resistor fitted so there is no need to enable the internal one. It does no harm if you do however.
Also what kind of signal would this send back to the pi?
A logic level signal. When reading the GPIO pin you will see a logic zero when the button is pushed and a logic one when it is not. These are also called true / false levels in Boolean logic.
Would it send an "on" signal once?
As long as the button is held down it will return a logic zero, it will only read back as a logic one when you release the button.

User avatar
Arjan
Posts: 262
Joined: Sat Sep 08, 2012 1:59 pm

Re: Baisc GPIO basic switch

Thu Nov 15, 2012 6:46 pm

Hi,

The picture below shows a commonly used circuit for reading the state of a push-button.

Arjan
Attachments
40106.png
40106.png (2 KiB) Viewed 1934 times
http://www.raspberrypi-dmx.org/
Open Source DMX/RDM/MIDI/OSC/Art-Net/sACN solutions

Return to “Interfacing (DSI, CSI, I2C, etc.)”