1

I'm using a Raspberry pi to log GPS tracks in my car, so it's headless and has no network.

What is the simplest way to add a pushbutton to receive an input that will enable me to:

  1. stop the GPS daemon
  2. initiate a shutdown

I'm from a CS (Computer Science) background, so looking for the simplest circuit and the way to read the switch state via something like a cron job.

Bonus points for adding an LED I can turn off to confirm shutdown :)

2
  • What is CS background?
    – Piotr Kula
    Jun 5, 2013 at 11:58
  • @ppumkin "Computer Science"? might be as well "Counter Strike", but I suspect the former, not the latter.
    – lenik
    Jun 5, 2013 at 23:46

1 Answer 1

3

Here's the simplest circuit:

button schematics

you need to connect to the GPIO pin (choose one you like), +5V or +3V and GROUND. when you push the button, the state of GPIO pin should change. you may read it from the program or command file and do whatever you want to do.

If you want to control the LED, it's even easier. Connect GPIO pin to the 470ohm resistor to the LED to the ground. That's it. When GPIO pin is high, LED will be on, otherwise -- off.

2
  • 1
    Are you sure that using a pullup to 5V, won't damage the gpio pins that only accept 3.3v?
    – Gerben
    Jun 8, 2013 at 20:51
  • The Broadcom chip has build in pull-up resistors. You could use that instead of the resistor above. For safety I personally add a 2k resister between the button and the GPIO. This is in case I screw up and accidentally set the pin to output and high. As that would create a short between the GPIO's 3.3 volt and ground, frying the GPIO pin and maybe even the entire pi.
    – Gerben
    Jun 8, 2013 at 20:51

Your Answer

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

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