The goal of this program is to connect an Arcade button to a Raspberry Pi. The button has a built in LED, so it should be illuminated when it isn’t being pushed. When it is pushed, I want the light to go off for an instant, and then go back on.
- LED Arcade Button
- Raspberry Pi
- Quick Connect Wires
- Male to Male and Male to Female Jumper Cables and Breadboard
Connect the LED Button to Wires
There are 4 leads on the LED button. Two of them are for the LED and two of them are for the switch function of the button.
When you look at the button on the side you can see that two leads go up on the outside of a little grey box. Those are the connections for the LED.
Next, use the quick connect wires on them. Some of these buttons have a (+) and (-) marked. This one did not. Luckily there are only two ways to make the connection. The quick connects slide easily onto the leads.
The switch connection works the same way. The small leads go directly into a small grey box. The white and the blue connections go on the same sides, as you can see in the picture below.
The button is now wired and is ready to be connected to the Raspberry Pi.
Connect the LED Button to the Raspberry Pi
Since I want the button to go on and off, I need to use the GPIO pins. I need one pin for the LED and one pin for the switch. So I will need two different GPIO pins, and a ground. This is a picture of the RPi GPIO pinout. Any of the GREEN pins will work.
These are the connections I used (I am using the Board Pin locations):
- LED Power (White wire) – Pin 16
- Button Switch (White wire) – Pin 15
- Ground (Both Blue wires) – Pin 9
I made these connections using jumper wires and a breadboard.
The (Python) Program
I programmed this in python, because it seems to be my go-to for Raspberry Pi projects.
import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) #Give the pin a physical position GPIO.setup(16, GPIO.OUT, initial = 1) #Turn pin 12 to high GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Make pin 15 a button, set to high try: while True: input_state15 = GPIO.input(15) #set input_state15 to high if input_state15 == False: GPIO.output(16, 0) #light goes off print('White button pressed') sleep(0.2) #wait GPIO.output(16, 1) #light goes on except KeyboardInterrupt: GPIO.output(16, 0) #turn off the lights
There are a lot of ways to program this, but this way made the most sense to me. Once one button is connected, you can connect several others.