The Easy Photo Button

Saturday, June 01, 2013
By Kevin

The Spark

I was asked the question, "How do I make a keyboard that's just a spacebar?" I was a little surprised by the question and asked what was the use case? As it turns out, the spacebar is what is needed to trigger a piece of software to take a picture for this photo booth that my friend was building.

I thought about it for a bit and figured this wasn't the first time someone had wanted this type of device so I turned to google. The first post that stood out was from MAKE Magazine with an overly simplified explanation of how to make The Awesome Button. Between this post and a few other hits I decided it wouldn't be too difficult to make a button that sent a keypress event over USB.

The Materials

Here's the list of materials. Most were purchased from RadioShack, but I'm sure they can be found online for much less. I needed them the next day so I paid the convenience fee.

  • Size M, Coaxial DC Power Jack (RadioShack) $3.50
  • Size M, Coaxial DC Power Plug (RadioShack) $3.50 for 2
  • SPST Momentary Pushbutton Switch (RadioShack) $3.99
  • 18 Gauge solid wire (should have used 22 gauge)
  • 3" x 2" x 1" Project Enclosure (RadioShack) $3.50

At the heart of this little black box is the Teensy USB development board.

tease:

To round things out, here's the list of tools and other supplies that I used.

  • Soldering iron
  • Solder 60/40
  • Electrical tape
  • Utility knife
  • Phillips screwdriver

The Teensy

I love this little thing. Its a USB-powered device that can take input or drive output through your computers USB port. I won't be able to do justice to what this thing can do so I would recommend checking out PJRC. They have lots of documentation, guides, and sample projects.

Size comparison between Teensy board and a US quarter

There is some software to download and install: Arduino software and Teensyduino. They support Windows, Mac, and Linux.

Once the software is installed and setup, you can plug the little guy into a USB port on your computer to give it life. It comes pre-loaded with a simple program that will flash the LCD one and off every second.

Teensy board powered up with LED light

Doing The Work

Soldering

For this simple project, I only needed to solder two wires to the Teensy. One of the wires goes to ground (blue, top right corner), and the other I wired to pin 4 (orange, top middle). The pin you select is is arbitrary since all pins can act as digital input pins. Take note of the pin you use for the program we load later.

Soldering work on input pins

You can connect these two wires to almost anything. I used a momentary push button from RadioShack, but if you can find a cooler, bigger button then go for it.

Interlude

At this point in my story I'd like to take a break and explain why I didn't use the Staples Easy Button. I thought about using it -- in fact, I tried it first -- but to use the button for this project requires exposing one of the copper traces on the circuit board that comes with the button. I was able to do that successfully, but I messed up soldering a wire to the copper trace. I decided it was beyond my soldering skills and elected to use a traditional button.

Easy Button soldering failure

This pic shows how it should look, but after taking this picture I realized that I burned away the copper trace under the blue wire. If you want to go this route, here are the instructions from instructables.com.

The Button

The next piece of soldering I did was to connect the two wires from my Teensy to a push button. I opted to make this a bit more complicated and add a plug to the connection. This allowed me to put the Teensy in one of those project boxes to protect it and give it a nice finished look, and it also allowed me to extend the length of the push button with a minimal amount of re-soldering.

Connecting the push button

I used a drill and a Dremel tool to create the openings for the USB cable and the DC power jack. I didn't want to cut my USB cable so I made that opening start from the edge of the case.

First view inside case showing opening for USB cable Second view inside case showing plug for push button

Soldering the button to the DC power plug was simple. I used 18 gauge wire, but I think that was overkill. I think 22 gauge wire would have been sufficient.

Close up of the push button

Final Assembly

Here's a picture of the final assembly. I'm pleased with how it turned out. It feels stable and usable. The button is a bit hard to push, but I think that will ease up with use.

Final assembly

Software

Now for the software. This is what I do best, and was honestly the most enjoyable part of the project. Here's a simplified version of the source code I used.

const int ledPin = 13;
const int inputPin = 4;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(inputPin, INPUT_PULLUP);
  Keyboard.begin();
}

void loop()
{
  if (digitalRead(inputPin) == LOW) // is pressed
  {
    Keyboard.set_key1(KEY_SPACE);
    Keyboard.send_now();
    delay(100);
    Keyboard.set_key1(0);
    Keyboard.send_now();
    delay(1400);
  }
}

The software basically sends a space key event, pauses for a short time, clears the space key event, and pauses for a longer amount of time. The pausing is to prevent multiple space key events from registering in succession. The delay values might need to be tweaked once I see it used with the photo booth software.

The full source code can be found here.