Circuits and Buttons

Button Up and Down

To create a button or a switch, you just need a circuit that can be easily connected and disconnected. Like an LED circuit, a button circuit can be created by connecting one wire to a data pin and another wire to a ground pin. To "close" the circuit (which is like pressing a button) you connect the two wires, either by touching them to each other or connecting them to a piece of hardware (like a button or switch) that can be used to open and close the circuit. An "open" button is equivalent to the button "up" event, while a "closed" circuit is like the button "down" event.

As with LED circuits, you can create a button circuit on any of pins 0, 2, 3, 6, and 12.

Creating Button Circuits

To create a button circuit you'll need a data pin, two wires, and a ground pin.

  • Connect a wire to your numbered data pin.
  • Connect a different wire to a ground pin.
  • Using code, create a new button object and event handler.
\\ Create a button attached pin 0
var myButton = createButton(0);

\\ Add an event handler to the new button
onBoardEvent(myButton, "down", function() {
    console.log("button pressed");

Pin on the Circuit Playground Express

If you're using the newer Circuit Playground Express, you may have noticed that the pins on the board are labeled with different numbers. Use the table below to identify which number to use for a given pin on the Express.

Express Use Pin #
A0 12
A1 6
A2 9
A3 10
A4 3
A5 2
A6 0
A7 1

Found a bug in the documentation? Let us know at