Getting Started with Grove
Experiment: Momentary button
In this article, I'll show you how to use a Grove button module. As you'll see, wiring will be a breeze, with precisely zero margin for error.
If you prefer to watch the video version of this article, go ahead.
Purchase a Grove Button module
This module contains a momentary button with its pull-down resistor. Plug it into a Grove connector and it's ready to use.
This is a Seeed product. Click on the red button, to complete your purchase on the Seeed website.
About this experiment
I'll show you how to use this button module in the simplest way possible. I am not going to do anything fancy, because I believe that simplicity is the key for good learning.
For more elaborate experiments and examples, have a look at the 5 projects in Grove For Busy People.
In this article, you will learn how to connect a Grove button to your Arduino via the Grove Base Shield, and take readings from it.
About the Grove button
The button, as you probably already know, is a digital device. Since the button can be either pressed or not pressed, it has only two possible states. These states are translated to voltage (high or low), and the Arduino with your sketch will then translate this voltage into a logical value.
Because the Grove button module has an on-board pull-down resistor, when the button is not pressed, the signal voltage of the button is GND. When the button is pressed, then the signal voltage will be 5V (if you are working with a regular Arduino Uno). If you are working with a Seeeduino and have set its power switch to 3.3V, then the pressed button signal level will be 3.3V.
Still considering the Grove button module, when the button is not pressed, your sketch will perceive its value as a logical "LOW" or "0". When the button is pressed, your sketch will perceive the same as a "HIGH" or "1".
Connect the Grove button
Let's connect the Grove button module to one of the Grove connectors on the Base Shield.
Take a Grove cable.
Plug one end in socket D4 on the Grove Base Shield.
Plug the other end in the Grove socket of the button module.
There is no way to make a mistake here 🙂
Your circuit should look like the example in this photo:
The arrows in the photo above show the pins involved. On the button module, the pin marked "SIG" is the one that conveys the state of the button to the Arduino. It is the first pin from the left.
Follow the yellow wire of the Grove cable to see where it ends up in the Base Shield. The left-most red arrow points to D4. This is the Arduino digital pin 4. This pin happens to be broken out in the Grove connector D4 (noted in large text on the Base Shield).
Be careful: There are two "D4" on the Base Shield. But, one refers to the Arduino pin, while the other refers to the Grove connector.
Now that we know which Arduino pin the button is connected to, we can move on to the sketch.
The Arduino sketch
The sketch we'll use to read the state of the button is very simple.
There is nothing fancy in this sketch; it should be familiar to you if you have done any work with the Arduino.
In line 49, I set the button pin.
It is set to pin 4, which is the Arduino digital pin D4.
In line 50, I also set the pin for the build-in LED: 13.
Reading the state of the LED works with the regular "digitalRead" function, and changing the state of the LED works with "digitalWrite".
Execute the sketch
Upload the sketch to your Arduino, and press the button on the Grove module.
The build-in LED will turn on, as expected.
In the photograph below, I use a Seeeduino. When I press the momentary button module, the blue LED connected to digital pin 13 turns on.
How easy was that? Wiring literally takes 10 seconds or less, with zero risk of error, and no need to use a pull-down resistor.
Ready for another experiment? Let's try out an analog module in the next article.
"Getting Started with Grove" series
Ready for some serious learning?
Grove For Busy People
In this course, I’m going to show you how to use the Grove system for the Arduino.
It is a course for people who are already familiar with the Arduino. Ideally, you a graduate of Arduino Step by Step Getting Started, and you are comfortable programming the Arduino with the Arduino IDE.
Just click on the big red button to learn more.