Please enter the email address you used on Kickstarter:


MicroView Learning Kit

04 Push Buttons

Introduction

In this circuit, we’ll be looking at one of the most common and simple inputs – a push button. The way a push button works with this MicroView tutorial is that when the button is pushed, the contacts in the button connects to the ground, MicroView reads this and reacts accordingly.

Parts

Component Reference Image
Push Button Push Button Diagram
Black Jumper Black Jumper Diagram
Red Jumper Red Jumper Diagram

Checkout our breadboard guide and MicroView Pinout for more information.

Breadboard Setup

MicroView Arduino Code

What you should see

You should see your MicroView print "ON" if you push the button, and "OFF" if you let go. (See the code to find out why!) If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your MicroView or see the troubleshooting tips below.

Code to Note

The digital pins can be used as inputs as well as outputs. Before you do either, you need to tell the MicroView which direction you're going.

pinMode(buttonPin, INPUT);

To read a digital input, you use the digitalRead() function. It will return HIGH if there's 5V present at the pin, or LOW if there's 0V present at the pin.

buttonState = digitalRead(buttonPin);

Because we've connected the button to GND, it will read LOW when it's being pressed. Here we're using the "equivalence" operator ("==") to see if the button is being pressed.

if (buttonState == LOW)

Troubleshooting

Light Not Turning On

The pushbutton is square, and because of this it is easy to put it in the wrong way. Rotate the button by 90 degrees and see if it starts working.

Underwhelmed

No worries, these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.

Still No Success?

A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: help@geekammo.com

How to use logic like a Vulcan:

One of the things that makes the MicroView so useful is that it can make complex decisions based on the input it's getting. For example, you could make a thermostat that turns on a heater if it gets too cold, a fan if it gets too hot, waters your plants if they get too dry, etc.

In order to make such decisions, the Arduino environment provides a set of logic operations that let you build complex "if" statements. They include:

You can combine these functions to build complex if() statements.

if ((mode == heat) && ((temperature < threshold) || (override == true))) {
    digitalWrite(HEATER, HIGH);
}

...will turn on a heater if you're in heating mode AND the temperature is low, OR if you turn on a manual override. Using these logic operators, you can program your MicroView to make intelligent decisions and take control of the world around it!

Continue on to circuit 05 Photo Resistors