Skip to main content

Grove-LED Button

The Grove - LED Button is composed of Grove - Yellow Button, Grove - Blue LED Button and Grove - Red LED Button. This button is stable and reliable with a 100 000 times long life. With the build-in LED, you can apply it to many interesting projects, it is really useful to use the LED to show the status of the button. We use a high-quality N-Channel MOSFET to control the LED to ensure the high swithching speed and a low consumption.All in all, you want some relly awesome button? Here you go ...


Product VersionChangesReleased Date
Grove-LED ButtonInitialJun 2018


Product VersionChangesReleased Date
Grove-LED ButtonInitialJun 2018


Product VersionChangesReleased Date
Grove-LED ButtonInitialJun 2018


  • Long operating life
  • Easy to use
  • Grove Digital interface


Working voltage3.3V/5V
Operating Life without Load100 000 times
LED rated current50mA
Press Resistance^1^<100mΩ
Release Resistance^2^>100MΩ
SizeL: 40mm W: 20mm H: 13mm
Package sizeL: 140mm W: 90mm H: 10mm
Gross Weight11g

1,2- If you want to measure the resistance, please take the key cap off the board. Otherwise you will get the value of the equivalent resistance of the board instead of the true resistance of the key cap.

Hardware Overview

Pin Map


SIG1 is the the LED control signal, the default value is low, so the N-Channel MOSFET is off , the LED is off too. When SIG1 becomes high, the N-Channel MOSFET trun on, and the LED light on.

SIG2 connect to the button pin. With a pull-up resistance, the default value of SIG2 is high. When you press the button, the voltage is pulled low, the SIG2 becomes to low.

Platforms Supported

ArduinoRaspberry Pi

Getting Started


In this part, we use the Grove - Red LED Button as an example. The following parts also apply to Yellow and Blue.

Play With Arduino


Materials required

Seeeduino V4.2Base ShieldGrove- Red LED Button
enter image description hereenter image description hereenter image description here
Get One NowGet One NowGet One Now
  • Step 1. Grove- Red LED Button to port D3 of Grove-Base Shield.

  • Step 2. Plug Grove - Base Shield into Seeeduino.

  • Step 3. Connect Seeeduino to PC via a USB cable.


If we don't have Grove Base Shield, We also can directly connect this module to Seeeduino as below.

SeeeduinoGrove- Red LED Button



If this is the first time you work with Arduino, we strongly recommend you to see Getting Started with Arduino before the start.

  • Step 1. Open the Arduino IDE and create a new file, then copy the following code into the new file.
#include "Arduino.h"

//1: toggle mode, 2: follow mode
#define LED_MODE 1

const int ledPin = 3; // the number of the LED pin, D3
const int buttonPin = 4; // the number of the pushbutton pin, D4
const boolean breathMode = true; // if or not the led lights as breath mode when it's on

// Variables will change:
int ledState = LOW; // the current state of the output pin
int ledFadeValue = 0;
int ledFadeStep = 5;
int ledFadeInterval = 20; //milliseconds
int buttonState; // the current reading from the input pin
int lastButtonState = HIGH; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
unsigned long lastLedFadeTime = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);

void loop() {
int reading = digitalRead(buttonPin);

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;

#if LED_MODE == 1
if (buttonState == LOW) { //button is pressed
ledState = !ledState;
ledFadeValue = 0;
lastLedFadeTime = millis();
if (buttonState == LOW) { //button is pressed
ledState = HIGH;
ledFadeValue = 0;
lastLedFadeTime = millis();
} else { //button is released
ledState = LOW;

// set the LED:
if (breathMode && ledState != LOW) {
if (millis() - lastLedFadeTime > ledFadeInterval) {
lastLedFadeTime = millis();
analogWrite(ledPin, ledFadeValue);
ledFadeValue += ledFadeStep;
if (ledFadeValue > 255){
ledFadeValue = 255 - ledFadeStep;
ledFadeStep = -ledFadeStep;
} else if (ledFadeValue < 0) {
ledFadeValue = 0;
ledFadeStep = -ledFadeStep;
} else {
digitalWrite(ledPin, ledState);

lastButtonState = reading;


In this demo, we choose mode 1 which is the toggle mode, you can change the line 4 #define LED_MODE 1 into #define LED_MODE 2 to use the follow mode.

  • Step 2. Upload the demo. If you do not know how to upload the code, please check How to upload code.

  • Step 3. Now, try to press you button, you will see the LED light on with a fade on/fade off effect.

It should be like:

Play With Raspberry Pi


  • Step 1. Things used in this project:
Raspberry piGrove Base Hat for RasPiGrove - Red LED Button
enter image description hereenter image description hereenter image description here
Get ONE NowGet ONE NowGet ONE Now
  • Step 2. Plug the Grove Base Hat into Raspberry.
  • Step 3. Connect the red LED button to D5 port of the Base Hat.
  • Step 4. Connect the Raspberry Pi to PC through USB cable.


For step 3 you are able to connect the LED button to any GPIO Port but make sure you change the command with the corresponding port number.



If you are using Raspberry Pi with Raspberrypi OS >= Bullseye, you have to use this command line only with Python3.

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Download the source file by cloning the library.
sudo pip3 install
cd ~
git clone

  • Step 3. Excute below commands to run the code.
sudo python3 5

Following is the code.

import time
from grove.button import Button
from grove.factory import Factory

class GroveLedButton(object):
def __init__(self, pin):
# High = light on
self.__led = Factory.getOneLed("GPIO-HIGH", pin)
# Low = pressed
self.__btn = Factory.getButton("GPIO-LOW", pin + 1)
self.__on_event = None
self.__btn.on_event(self, GroveLedButton.__handle_event)

def on_event(self):
return self.__on_event

def on_event(self, callback):
if not callable(callback):
self.__on_event = callback

def __handle_event(self, evt):
# print("event index:{} event:{} pressed:{}".format(evt['index'], evt['code'], evt['presesed']))
if callable(self.__on_event):
self.__on_event(evt['index'], evt['code'], evt['time'])

self.__led.brightness = self.__led.MAX_BRIGHT
event = evt['code']
if event & Button.EV_SINGLE_CLICK:
print("turn on LED")
elif event & Button.EV_DOUBLE_CLICK:
print("blink LED")
elif event & Button.EV_LONG_PRESS:
print("turn off LED")

Grove = GroveLedButton

def main():
from grove.helper import SlotHelper
sh = SlotHelper(SlotHelper.GPIO)
pin = sh.argv2pin()

ledbtn = GroveLedButton(pin)

# remove ''' pairs below to begin your experiment
# define a customized event handle your self
def cust_on_event(index, event, tm):
print("event with code {}, time {}".format(event, tm))

ledbtn.on_event = cust_on_event
while True:

if __name__ == '__main__':


If everything goes well, you will be able to see the LED turns on if you press it and turns off if you long press it. If you double click the LED button, the LED will blink.

pi@raspberrypi:~/ $ python3 5
Hat Name = 'Grove Base Hat RPi'
turn on LED
turn on LED
blink LED
turn on LED
turn off LED
^CTraceback (most recent call last):
File "", line 101, in <module>
File "", line 97, in main

You can quit this program by simply press ++ctrl+c++.

Schematic Online Viewer


Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.
Loading Comments...