Relay

The Grove Relay module is a digital normally-open switch. Through it, you can control circuit of high voltage (up to 250V AC or 30V DC and 5A current) with low voltage. There is an indicator LED on the board, which will light up when the controlled terminals get closed. Please visit the official WiKi for the full specification. In the following section, you'll learn how to use the on-board user button as a switch to turn on or off the relay to light up or switch off a LED.

Installation

Please connect the circuit as the figure shown below to complete this example:

Execution

  1. Copy and paste the codes below into the Arduino IDE.

    int val = 0; 
    int controlPin = 10; 
    int buttonPin = 6; 
     
    void pin_change(void) 
    { 
      val = !val; 
    } 
     
    void setup() { 
      Serial.begin(9600); 
      pinMode(controlPin, OUTPUT); 
      attachInterrupt(buttonPin, pin_change, RISING); 
    } 
     
    void loop() { 
      if (val) 
      { 
          digitalWrite(controlPin, HIGH); 
          Serial.println("High"); 
      } 
      else 
      { 
          digitalWrite(controlPin, LOW); 
          Serial.println("Low"); 
      } 
     
      delay(500); 
    }
  2. Click the Upload icon to compile and upload the sketch to the board.

  3. When the upload is done, you can turn on / off the LED through the relay by clicking the user button.

A more generic application is illustrated in the scenario below:

By letting the hot wire of an ordinary power cord or the wire in a wall plug to go through the relay (or the 5V power rail of a USB device), a programmable power switch can thus be created by using a relay.

Last updated