Introduction: Upgrade Your Space Launch With a Physical Staging Button for Kerbal Space Program
I recently picked up the demo version of Kerbal Space Program. Kerbal Space Program is a simulator game that allows you to design and launch rockets and navigate them to distant moons and planets. I'm still trying to successfully land on the moon (or Mun, as it's called in the game). While browsing the official forums, I came across this neat project. It's a physical control panel with dozens of switches and dials that adds a touch of realism to the experience. Someday I think it would be fun to build my own setup, but I don't have all the components as of yet. In the meantime, I put together this simple button that can be used to perform staging controls such as initiating a launch, jettisoning empty fuel tanks, and deploying parachutes. It really adds a fun element to the game, and all it takes to make your own is an Arduino, a pushbutton switch, and a few other small pieces.
Let's get started!
Step 1: How It Works and List of Materials
Here's a basic overview of how my setup works.
A pushbutton switch is wired to one of the pins on an Arduino. The Arduino waits for the button to be pressed and then sends a small message over USB to my computer. On the computer, a lightweight program listens for the signal from the Arduino and sends a simulated spacebar press to Kerbal Space Program (or whatever program is currently active on the computer). It's really quite simple, and the whole project could easily be adapted to any other purpose by changing the desired keypress. You could make a button that brings up a specific tool in a photo editor or maybe one that refreshes the webpage in your browser. The possibilities are pretty broad.
Here are the things you'll need to get your own button up and running:
- Arduino with corresponding USB cable (I used an Arduino Uno)
- Solderless breadboard
- A momentary pushbutton switch (Any pushbutton will do. See the second pic for the one I used)
- A small resistor
- Jumper wires or several lengths of 22 AWG wire to connect the components.
Of course you will also need a copy of Kerbal Space Program. For this project, the demo version works fine so if you don't own the game yet you can still make and test this button. Get the game here: kerbalspaceprogram.com
Step 2: Wire the Circuit
Now let's start constructing the circuit.
First, use a jumper wire to connect the 5v pin of your Arduino to the red column on your breadboard. Do the same with the ground (GND) pin and the blue column. This will allow us to get power from the Arduino at any breadboard pin along the red line and allows us to connect to ground at any pin along the blue line.
Second, insert your pushbutton switch on the breadboard. The exact location doesn't matter very much, just be sure that the in and out pins are in separate rows. Now, run a jumper wire from the red column of the breadboard to one side of the switch. Connect the other side of the switch to the blue column using a resistor. Finally, connect the same side of the switch to which you connected the resistor to one if the pins on the Arduino. I used pin 2.
That's it for the basic circuit!
Step 3: Program the Arduino
The next thing we need to do is upload the code to the Arduino.
I modified the Debounce sample sketch that comes with the Arduino software to send the number 1 over serial connection to the computer every time the button is pressed. All I had to do was add "Serial.begin(9600)" to the setup function and "Serial.println(1)" to the inside of the if statement that checks if buttonState == HIGH. I also removed the code that turns the onboard LED on and off.
You can either do what I did and modify the Debounce sketch or simply download my finished version from this instructable.
Either way, you'll want to plug in your Arduino, open the finished sketch, and upload it to the Arduino board.
Step 4: Test the Arduino
Before we move on, it helps to test out what we've built so far.
With the Arduino still plugged in to the computer, open the serial monitor in the Arduino software. Pres the pushbutton a few times. Each press should produce a "1" in the serial monitor window. If that's the case, you're ready to move on. If not, go back and check that you wired everything correctly and try re-uploading the Arduino sketch. If that still doesn't work, leave a comment below and I'll see if I can help you get it working.
Step 5: Start the Listener Software
Now we have a physical button that sends a message to the computer every time it is pressed. Now we need to set up a listener on the computer to translate the "1"s coming from the Arduino into key presses that Kerbal Space Program will recognize.
I wrote a small program to do just that. Download, unzip, then launch the program. It should look like the picture. Now, set the COM port number to that of your Arduino. If you don't know what COM port your Arduino is using, open the Arduino editor program and check the bottom-right corner.
Next, position your cursor in the textbox and press the spacebar once. The listener will simulate keypresses for whatever is typed in this box. Since the staging button in Kerbal Space Program is the spacebar, we want a single space in this textbox.
Once you've set the COM port number and have a space in the textbox, you're ready to try it out!. Press the "Start Listening" button. Open a text editor such as Notepad or Word and press the pushbutton. A space should appear. If not, double-check that the Arduino is plugged in, the port number is correct, and that the listener program is still running.
Step 6: Liftoff!
You're all done! Fire up Kerbal Space Program, assemble a rocket, and head out to the launch pad. If all goes well, your rocket should launch when you press the pushbutton. If you have built a multi-stage rocket, the button will work for firing the next stages as well.
Thanks for reading! I hope you enjoyed this Instructable. Please let me know in the comments if you have any questions and be sure to post a picture of your finished launch button.