Project Five – Relay Control

Introduction

In this project we will demonstrate using the relay . Using the button , button one will turn the relay on, and button two turns it off. As noted earlier, the relay can handle a peak voltage capability of 250V at 10 amps.

Even though you may be capable with low voltages and microelectronics, if you are not qualified for working with mains voltages, consult a licensed electrician to complete the work.

Connect the Twin Button to the D1/D2 input jack.

The Twin Button Grove’s red button uses the D1 connector to send a signal to the Arduino’s D1 digital input, and the green button uses the D2 connector to send a signal to the Arduino’s D2 digital input.

Connect the Relay to the D6/D7 input jack.

The Arduino’s D6 pin sends a signal to the Relay on the D1 connector. The Relay Grove’s red light indicates whether the relay is on or off, and the relay makes a clicking sound when it switches.

Now upload the following Arduino sketch:

// Project Five - Relay Control
//

void setup()
{
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(6, OUTPUT);
}

void loop()
{
  if (digitalRead(1)==HIGH)
  {
    digitalWrite(6, HIGH);
    delay(100);
  }
  if (digitalRead(2)==HIGH)
  {
    digitalWrite(6, LOW);
  }
}

When using this with an XBee Carrier, please be aware that you should set output 16 low to ensure that the mosfet on the XBee carrier provides enough power to reliably pull in the relay

The reason for the delay function after setting the relay high or low is to allow the sketch to pause – in doing so ignoring the buttons for one tenth of a second. This is more commonly known as ‘software de-bouncing”. Although doing so may not seem necessary in this particular example, doing so is a good habit to start with.

Help us make it better

Welcome to the new documentation system of Seeed Studio. We have made a lot of progress comparing to the old wiki system and will continue to improve it to make it more user friendly and helpful. The improvement can't be done without your kindly feedback. If you have any suggestions or findings, you are most welcome to submit the amended version as our contributor via Github or give us suggestions in the survey below, it would be more appreciated if you could leave your email so that we can reply to you. Happy Hacking!