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.


blog comments powered by Disqus

Featured Products from the MakerShed

Follow

Get every new post delivered to your Inbox.

Join 25,436 other followers