Grove - Switch(P)

Introduction

3.3V 5.0V Digital

This Grove – Switch is a mini SPDT slide, great for “ON/OFF” situations. It is such a reliable switch of great build quality that we adopt it on many of our boards. You should stock some for your Grove prototyping system.

What does “P” mean? “P” is for “panel mount” in this product.

Features

  • Grove Interface
  • Easy to use
  • Basic Grove element

Tip

More details about Grove modules please refer to Grove System

Platforms Supported

Usage

Below is a simple example showing how to use a switch to turn on/off an LED.The working principle and use just the same as the Grove-Button.

  1. Connect the Grove-LED to the Digital 13 of Grove - Basic Shield and connect the Grove -Switch(P) to the Digital 2 of Grove-Base Shield with two Grove cables.
  2. Plug the Grove - Base Shield into Arduino and connect Arduino to PC by using a USB cable.
  3. Copy and paste code below to a new Arduino sketch.
// constants won't change. They're used here to
// set pin numbers:
const int switchPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int switchState = 0;         // variable for reading the pushbutton status

void setup() {
    // initialize the LED pin as an output:
    //pinMode(ledPin, OUTPUT);
    // initialize the switch pin as an input:
    Serial.begin(9600);
    pinMode(switchPin, INPUT);
}
void loop(){
    // read the state of the switch value:
    switchState = digitalRead(switchPin);

    if (switchState == HIGH) {
        // turn LED on:
        // digitalWrite(ledPin, HIGH);
        Serial.println("switch high!");
    }
    else {
        // turn LED off:
        // digitalWrite(ledPin, LOW);
        Serial.println("switch low");
    }
}

After uploading the code, you can see the led will light up when the switch is at high side.

Resources


ArduinoWioBeagleBoneRaspberry PiLinkIt ONE

Caution

The platforms mentioned above as supported is/are an indication of the module's hardware or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Help us make it better

Thank you for choosing Seeed. A couple of months ago we initiated a project to improve our documentation system. What you are looking at now is the first edition of the new documentation system. Comparing to the old one, here is the progresses that we made:

  • Replaced the old documentation system with a new one that was developed from Mkdocs, a more widely used and cooler tool to develop documentation system.
  • Integrated the documentation system with our official website, now you can go to Bazaar and other section like Forum and Community more conveniently.
  • Reviewed and rewrote documents for hundreds of products for the system’s first edition, and will continue migrate documents from old wiki to the new one.

An easy-to-use instruction is as important as the product itself. We are expecting this new system will improve your experience when using Seeed’s products. However since this is the first edition, there are still many things need to improve, if you have any suggestions or findings, you are most welcome to submit the amended version as our contributor or give us suggestions in the survey below, Please don’t forget to leave your email address so that we can reply.

Happy hacking