2 channel Relay Shield For Arduino (With XBee/BTBee interface)

From Wiki

Jump to: navigation, search

Contents

Introduction

The Relay shield is capable of controlling 2 relays. The max switching power could be 10A/250VAC or 10A/30VDC. It could be directly controlled by Arduino/Freaduino through digital IOs with external 9v supply. With buildin xbee/BTBee type socket, it can be wirelessly controlled via Xbee/BTBee(HC-06). Make it an ideal solution for home automation and robotics purpose.
Model: SHD_RL01
SHD RL01 3.jpg

Feature

Application Ideas

Make it an ideal solution for home automation and robotics purpose.
SHD RL01 5.jpg

Cautions

  • If you want to use Bluetooth on, Please make sure the IO is 3.3v on your main board.

Specification

Contact Rating 10A AC 250V / DC 30V
Max Switching Voltage AC 250V / DC 30V
Max Switching Current 10A
Max Switching Power AC 2500VA / DC 300W
Electrical Life (Min) 100,000 Operations
Mechanical Life (Min) 10,000,000 Operations
Safety Standard(relay) UL cUL TUV CQC
Coil Working Voltage 5VDC
Weight 55g
Working temperature -30℃ to +85℃


Pin definition and Rating

SHD RL01 4.jpg

Mechanic Dimensions

Usage

With Arduino/Freaduino

Relay Shield could be directly controlled by Arduino or Freaduino.

Step1. Plug Relay Shield onto Arduino Duemilanove (or compatible) board;
Step2. Supply 9v DC power to Arduino;
Step3. Download the example code and run in Arduino IDE.

Programming

The demo code is test the module RF, BTBee and Relay part. And the code base on the nRF24L01 library, you need change the pin define as below. If you test the Bluetooth Bee interface, you need used other Bluetooth device paired with BTBee. Here we used a Android phone with our APP as client to paired with BTbee(HC-o6), more about paired here.

#include "API.h"

//---------------------------------------------
#define TX_ADR_WIDTH    5   
// 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH  1  
// 20 unsigned chars TX payload
//---------------------------------------------
#define CE       9
// CE_BIT:   Digital Input     Chip Enable Activates RX or TX mode
#define CSN      10
// CSN BIT:  Digital Input     SPI Chip Select
#define SCK      13
// SCK BIT:  Digital Input     SPI Clock
#define MOSI     11
// MOSI BIT: Digital Input     SPI Slave Data Input
#define MISO     12
// MISO BIT: Digital Output    SPI Slave Data Output, with tri-state option
#define IRQ      8
// IRQ BIT:  Digital Output    Maskable interrupt pin
//*********************************************
#endif

Bluetooth Module Guide

First, you need enter AT mode in accordance with the above method. Then, there are three ways use Serial port send command to Bluetooth Shield. Detail option please reference my post Communication between Android and Arduino with Bluetooth(2).

Connect as DOUT to D3 , DIN to D2

Here we used case 3 for the demo code with Freaduino v1.0 with ATMega328 (100% Arduino compatible).


RelayShield.jpg


Usually we used software Serialport library to control and communication with Bluetooth Module. The Preparation steps:

Step One: Hardware connect

Use the Case 3 connection. And we jumper cap to SW side and set switch to H side. Then use Software Serial library to define D2 and D3(Of course others) as a virtual serial port TX and RX. By this way, you can use Arduino’s Serial Monitor to Monitor operation of the code.


Step two: Software control

First of all, you need a software library. There we used NewSoftSerial library. Get it from here

Put the library to : ...\your_ArduinoIDE_Path\arduino-0022\libraries

Copy below demo code and run. This just a sample code for your reference and you can modified and change it whatever you want.


Step Three: AT command

Now, You can send AT commanD from Serial port to control and setting the Bluetooth module. And you can set the module to Master or Slave......

You can play with Master mode to send paired require to others Bluetooth devices or Slave mode to wait others Bluetooth devices discover.

The AT command please reference Bluetooth Bee AT Command(HC-06).


Demo code like :

/*********************************************************************
 **  Description:                                                    **
 **  This file is a sample code for your reference.                  **
 **                                                                  **
 **  Copyright (C) 2011 ElecFreaks Corp.                             **
 **  Created by ElecFreaks Robi.W /29 Sep 2011                      **
 **                                                                  **
 **  http://www.elecfreaks.com                                       **
 *********************************************************************/
#include <NewSoftSerial.h>
#include <TimerOne.h>

#define rxPin 2
#define txPin 3

NewSoftSerial mySerial(rxPin, txPin);
 
void Callback()
{
   Serial.println("------->  Callback Send AT");
   mySerial.print("AT");
}
 
void setup()
{
   // define pin modes for tx, rx, led pins:
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);
   mySerial.begin(9600);
   Serial.begin(9600);
 
   //Timer1.initialize(2000000);             // setting callback is 2s
   //Timer1.attachInterrupt(Callback); 
   Serial.println("-------> Start ");
}
 
void loop()
{
  int i = 0;
  char someChar[32] = {0};
  // when characters arrive over the serial port...
  if(Serial.available()) {
    Serial.println(); 
    Serial.print("------->  ");
    do{
      someChar[i++] = Serial.read();        // Note HC-06 end not '/r/n', direct input "AT" command from Serial port
    }while (Serial.available() > 0);
 
    mySerial.print(someChar);
    Serial.println(someChar);
  }
 
  while(mySerial.available()) 
      Serial.println((char)mySerial.read());    
}


RelayShield02.jpg





RelayShield-Mega.jpg

If you used Arduino Mage1280/250 or Freaduino ADK there are some different.Please note the NewSoftSerial library about Mage2560 explanation in SoftwareSerial.cpp :


// Specifically for the Arduino Mega 2560 (or 1280 on the original Arduino Mega)
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

That's mean the library do not support D0-D7 as receive pins, just could use pins:10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 for receive. So there are two way to resolve it, but all need external jumper wires.

First method: Change the define of rxPin and txPin. Jumper wires connect DOUT-D10, DIN-D11.

#define rxPin 10
#define txPin 11

Second method: Use the others Hardware Serialport because of Mage there are 4 hardware serialport. Jumper wires connect DOUT-RX1(D19) DIN-TX1(D18)

The below demo is second method:

/*********************************************************************
 **  Description:                                                    **
 **  This file is a sample code for your reference.                  **
 **                                                                  **
 **  Copyright (C) 2011 ElecFreaks Corp.                             **
 **  Created by ElecFreaks Robi.W /29 Sep 2011                      **
 **                                                                  **
 **  http://www.elecfreaks.com                                       **
 *********************************************************************/
 
void setup()
{
   Serial.begin(9600);
   Serial1.begin(9600);
 
}
void loop()
{
  int i = 0;
  char someChar[32] = {0};
  // when characters arrive over the serial port...
  if(Serial.available()) {
    Serial.print("------->  ");
    do{
      someChar[i++] = Serial.read();
    }while (Serial.available() > 0);
 
    Serial1.println(someChar);
    Serial.println(someChar);
  }
 
  while(Serial1.available())
      Serial.print((char)Serial1.read()); 
}

Bill of Materials (BOM) /parts list

All the components used to produce the product.

FAQ

Please list your question here:

Support

If you have questions or other better design ideas,

Version Tracker

Revision Descriptions Release
v1.0 Initial public release 09/19/2011

Bug Tracker

Bug Tracker is the place you can publish any bugs you think you might have found during use. Please write down what you have to say, your answers will help us improve our

products.

Additional Idea

The Additional Idea is the place to write your project ideas about this product, or other usages you've found. Or you can write them on Projects page.

Resources

How to buy

Click here to buy:http://www.elecfreaks.com/estore/2-channel-relay-shield-with-xbee-btbee-interface-shd-rl01.html

See Also

Other related products and resources.

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are

licensed under GPL/LGPL, see source code files for details.

External Links

Links to external webpages which provide more application ideas, documents/datasheet or software libraries[[Category:Shield

Personal tools
Namespaces
Variants
Actions
Navigation
Support
Toolbox