The Relay Shield, allows you to control high power devices over the internet. Want to control a lamp, fan or garden sprinklers? Then this is a solution for you!
The schematic for the relay shield is simple and self explanatory. The shield has four relays that are controlled by pins D0, D1, D2 and D3 on the Core. Each relay is triggered via a NPN transistor that takes a control signal from the core and switches the relay coil ON and OFF which in turn makes or breaks the electrical contact on the output. There is also a flyback diode connected across the coil to help protect the transistor from high voltage transients caused during switching.
The relays are SPDT (Single Pole Double Throw) type, which means they have three terminals at the output: COMMON (COMM), Normally Open (NO) and Normally Closed (NC). We can either connect the load in between the COMM and NO or COMM and NC terminals. When connected in between COMM and NO, the output remains open/disconnected when the relay is turned OFF and closes/connects when the relay is turned ON. In the later case, the output remains closed/connected when the relay is OFF and opens/disconnects when the relay is ON.
Specifictions:
- Operating voltage: 7 to 15V DC
- Current consumption: 150mA min to 290mA (at 9V DC)
- Relay Max Voltage: 250V AC
- Relay Max Current: 10Amp at 125V AC
- Relay Part Number: JS1-5V-F (Data Sheet)
- Dimensions: 3.5 x 3.3
- Weight: 100g
Setting up the Relay Shield
Turning ON a relay is as simple as setting the associated pin to HIGH.The picture shows a sample setup where the relay is used as a switch to control a light bulb.
int RELAY1 = D0;
int RELAY2 = D1;
int RELAY3 = D2;
int RELAY4 = D3;
void setup()
{
//Initilize the relay control pins as output
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
// Initialize all relays to an OFF state
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, LOW);
//register the Spark function
Spark.function("relay", relayControl);
}
void loop()
{
// This loops for ever
}
// command format r1,HIGH
int relayControl(String command)
{
int relayState = 0;
// parse the relay number
int relayNumber = command.charAt(1) - '0';
// do a sanity check
if (relayNumber < 1 || relayNumber > 4) return -1;
// find out the state of the relay
if (command.substring(3,7) == "HIGH") relayState = 1;
else if (command.substring(3,6) == "LOW") relayState = 0;
else return -1;
// write to the appropriate relay
digitalWrite(relayNumber-1, relayState);
return 1;
}
POST /v1/devices/{DEVICE_ID}/relay
An example API request to this function would look something like this:
# EXAMPLE REQUEST
curl https://api.spark.io/v1/devices/0123456789abcdef/relay \
-d access_token=123412341234 -d params=r1,HIGH
Particle - Relay Shield
- Brand: Particle
- Product Code:PTCL-Relay-Shield
- Reward Points:40
- Availability:In Stock
- रo 3,985.00
-
रo 2,970.00
- Price in reward points:3985