Wireless Relay Arduino Shield

From ElectroDragon Wiki

Pin definition and Rating

SHD RL01 4.jpg

Control by Bluetooth Module Software Serial Port

RelayShield.jpg
RelayShield02.jpg
  • Use softserial library create software serial port, communicate with bluetooth module
#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());    
}

Arduino Mega or Hardware serial port

RelayShield-Mega.jpg

If you used Arduino Mage1280/250 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)
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()); 
}

Documents