Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!

Make: Projects

Using the MakerShield – Button

Learn how to make the button on the MakerShield work with the "button" example sketch in the Arduino IDE.

Using the MakerShield – Button

The MakerShield is a great prototyping shield but the button can be a little confusing to use. Since it connects to ground when pressed, it takes a little extra wiring and one change in the code to get to work with with the Arduino example sketch. Follow along!

Steps

Step #1:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • First, let's lay out our parts. You'll need a MakerShield (assembled), a mini breadboard, an Arduino, 3 male jumper wires, and a 10K Ohm (Brown, Black, Orange) resistor.
  • Next, take your MakerShield (with mini breadboard attached) and place it on top of the shield headers. Make sure the pins are lined up and press it into place.
  • Great Job! Let's continue.

Step #2:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • Now for the parts. Take your 10K Ohm resistor (Brown, Black, Orange) and insert one leg into the 5V pin on the MakerShield. Connect the other leg to an adjacent hole on the breadboard.
  • The reason we're doing this is to give the digital input pin something to sense. This will supply the voltage we need to let the input pin know that something is going on.
  • Next, take a jumper wire and insert one end into the breadboard right above the resistor (just like in the picture). Connect the other end of the wire to the BTN1 (button 1) pin on the MakerShield.

Step #3:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • Now, grab another jumper wire and stick one end into the breadboard above the other jumper wire. The other end of this jumper wire will go to the D2 (digital 2) pin on the MakerShield.
  • This wire is so that the Arduino will be able to detect when the button is pressed.

Step #4:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • Now we are going to connect the LED on the MakerShield to the LED output pin.
  • Take another jumper wire and connect one end to the LED1 pin on the Maker Shield. Connect the other end of the jumper wire to pin D13 (digital 13) on the MakerShield.
  • Now the LED is connected so we'll be able to see when the button is pressed.

Step #5:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • Go ahead and plug your Arduino into your computer using the USB port and fire up the Arduino software.
  • Open the Button example sketch by going to File > Examples > Digital > Button.
  • Got it? Good! This sketch is written for a button that is connected to voltage on one end and a digital pin on the other. The button on the Maker Shield is different; the button connects to ground when pressed. Because of this we need to make one little change to the code.
  • Scroll down to where it says if (buttonState == HIGH) { (highlighted in the picture) and change HIGH to LOW.
  • The line should now read if (buttonState == LOW) {
  • What we just told the code that when the button is pressed on the Maker Shield (when the digital pin gets connected to ground) to light the LED up.

Step #6:

PrevNext
Using the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – ButtonUsing the MakerShield – Button
  • Now upload the code to your Arduino and hit the button on the MakerShield. The LED should light up!
  • Congratulations! Your button now works!
  • You can easily swap which LED lights up by switching your LED jumper wire from LED1 to LED2.
  • Play around and have fun!

Conclusion

Easy, huh?

Michael Castor

I am the Evangelist for the Maker Shed. It seems that there is no limit to my making interests. I'm a tinkerer at heart and have a passion for solving problems and figuring out how things work. When not working for Make I can be found falling off my unicycle, running in adverse weather conditions, skiing down the nearest hill, restoring vintage motorcycles, or working on my car.


Comments

  1. Charles says:

    Thank you so much…I’m new to arduino and just soldered the makershield together with my son…we were lost on how to verify that we set everything up correctly. This was exactly what we needed and will make our experience with the protoshield even better!

    1. Jason says:

      Me too! Success! It worked. Both LED’s light up (after moving the jumper wire.)

  2. Tonto123 says:

    mine didn’t come with the bread board to put on top. :(

  3. Martin Holguin says:

    hi i just put together the makershield and I wanted to say that it is very easy to solder, although
    I have not experience and after testing it (thanks to this step by step guide) I realized that it works fantastically!!!

  4. Ari says:

    I can not find the 10K Ohm resistor nor the pushbutton, could you please give me the links?

    1. Michael Castor says:

      Hello,

      The button is included in the MakerShield Kit – http://www.makershed.com/MakerShield_Kit_p/msms01.htm

      We include the 10K resistor in our Getting Started with Arduino Kit, Ultimate Arduino Microcontroller Pack, and Mintronics: Survival Pack. You can also pick one up from your local RadioShack.

      Hope that helps!

In the Maker Shed