Introduction: SEEED Studio / Arduino -- 5V Relay Module (Digital) -- Electronic Brick

Working with the digital relay to control high voltage can be hard to understand.  There are no instructions on how to make this perform with an ARDUINO.  I created this so people will be able to use the relay with a standard 110 volt house outlet in either NO - NORMALLY OPEN  or NC - NORMALLY CLOSED modes.  As always working with high voltage is dangerous so be careful.  If you do not understand how it works seek help from someone who knows how to make it work or DO NOT ATTEMPT THIS INSTRUCTABLE !!!!!!



UNDERSTANDING RELAY STATES:

You can configure your ARDUINO signal to be either "LOW" or "HIGH".  It does make a difference as to how the RELAY controls the outlet in the "NO" or "NC" states.  For this project all PINS on the ARDUINO will start out in the "LOW" state as the default.  You need to determine how you need your "OUTPUT" PIN to be configured for your own projects.  You need to understand this concept so you can configure your projects using this RELAY BRICK to be the most effective with the least amount danger possible.


NO - Normally Open

The RELAY can be NO (Normally Open) state . When outlet is pluged into a high voltage power supply the outlet is HOT (power to it and LED on outlet is on).  The default mode at the ARDUINO is in the "LOW " state (RELAY LED light is off). When ARDUINO send a "HIGH" command to the RELAY (LED on RELAY turns on) all power is cut to the outlet  (LED light on outlet will go out).

POWER LOST DURING USE:
When power goes out or power cord is unpluged there will be no power to the outlet or ARDUINO and all devices connect will not work.

RELAY "LOW" (LED on RELAY is off) and power is lost to the ARDUINO and RELAY outlet will remain HOT.  What ever device is connected to the outlet will continue to run.

RELAY "HIGH"
(LED on RELAY is on) and power is lost to the ARDUINO and RELAY the outlet will revert back to a HOT condition.  What ever device is connected to the outlet will be turned on again.




NC - Normally Closed

The RELAY can be NC (Normally Closed) state . When outlet is pluged into a high voltage power supply the outlet has no power and is OFF (power to it and LED on outlet is off).  The default mode at the ARDUINO is in the "LOW " state (RELAY LED light is off). When ARDUINO send a "HIGH" command to the RELAY (LED on RELAY turns on) power allowed to flow to the outlet  (LED light on outlet will turn on).

POWER LOST DURING USE:
When power goes out or power cord is unpluged there will be no power to the outlet or ARDUINO and all devices connect will not work.

RELAY "LOW" (LED on RELAY is off) and power is lost to the ARDUINO and RELAY outlet will remain OFF (LED light on outlet is off) .What ever device is connected to the outlet it will continue to be off.

RELAY "HIGH"
(LED on RELAY is on) and power is lost to the ARDUINO and RELAY the outlet will revert back to a OFF condition.  What ever device is connected to the outlet will turn off as power to the outlet has been lost.


Know what you can drive with this RELAY:
current * voltage = power 
This RELAY is rated for 10A at 120V
The RELAY can handle up to a 1,000W device.
It is not a good idea to run this RELAY at a full 1,000W demand.  It is a better idea to stop at about 800W to be on the safe side. 



Step 1: COMPONETS OF PROJECT

There are 4 major componets to get this project to work correctly:

1 - Arduino of some type to control the relay.

2 - 5V Relay module (Digital) -  Electronic Brick
      It is much easier to use this small foot print digital relay with all the correct parts in one unit.
      Building one of these little guys can be a lot of work and not perform as well as this unit.

3 - House Outlet the the relay will control

4 - The Sketch to drive the relay using an Arduino.
      (if you don't understand how to use sketches with an Arduino, you will need to learn this skill).

Step 2: PARTS and MATERIALS


BELOW YOU WILL FIND A FULL LISTING OF THE PARTS & MATERIALS USED:


1 --  SEEED Stuido 5V Realy module (digital) Electronic Brick
http://www.seeedstudio.com/depot/electronic-brick-5v-relay-module-digital-p-479.html?cPath=48_53

1 --  Arduino (any type you want to use)

1 --  Duplex Ground Fault Receptacle
http://www.google.com/products/catalog?q=125V+Duplex+Ground+Receptacle&oe=UTF-8&cid=17102349241501817852&ei=XjPmS-b0II64iwTboKHaDg&sa=title&ved=0CCgQ8wIwCDgA#p

1 --  Proto Shield  -- (optional) or bread board to construct button circuit
http://www.makershed.com/ProductDetails.asp?ProductCode=MKAD6

1 -- LED light

1 -- Power Cord grounded

1 -- Button Switch

1 -- 10 ohm resistor

1 -- 12 inches of 20 gauge YELLOW solid core wire

1 -- 12 inches of 20 gauge RED solid core wire

1 -- 12 inches of 20 gauge BLACK solid core wire

1 -- 12 inches of 18 gauge BLACK 600 volt wire
http://www.boatingsolutions.com/Wire-Primary-18-Black-By-Foot-P11018C1609.aspx

1 -- Radio Shack - 
      12 position Mini European Style Terminal Block ( optional if constructed as shown
http://www.radioshack.com/product/index.jsp?productId=2103986

Step 3: Understand Your RELAY BRICK

You need to understand your RELAY brick.

BOBB from the Seeed Stuido Forum did an outstanding job of showing the lay out of the relay.
http://www.seeedstudio.com/forum/viewtopic.php?f=4&t=683

The only thing missing for this overview is the LED light that is located next to the connector 3 terminal block.  This is an important part in the design of this relay.  You use it to see when power goes to the Connector 3 terminal block.  Why is this important -- well once the LED goes on you know you have a signal to the relay and the relay is actually turned on.  VERY IMPORTANT !!!!!!!!!!!!


Step 4: Construct Your OUTLET SETUP

MAKE SURE OUTLET OR POWER CORD HAS NO POWER CONNECTED TO THEM !!!!!!!!

Conection of your outlet to the power cord is very important that you do it right.  If not done right you might start a fire when working with this project.  This project was done outside an outlet box for demonstration purposes only.  Make sure you construct your project in an outlet box that meets all local building codes.

Please notice that we are using a Ground Fault Circuit Interrupter (GFCI) Outlet and not a normal outlet. The GFCI may save your life. It's the type of outlet you'll find near anything that outputs water (kitchen sinks, batchroom tubs, etc). When the outlet detects an abnormal amount of current, it assumes that a large amount of potentially fatal current is flowing through your body, and therefore switches off - saving you and your project.

Note: A two-wire extension cord will not work correctly. Notice this project is using a thick, three-wire circular extension cord. This extra wire is the ground return and allows the GFCI to operate correctly.



POWER CORD CONNECTION TO OUTLET:

WHITE WIRE CONNECTION:
Connect WHITE wire from power cord to silver screw mount on the wide prong side of the outlet.

GREEN WIRE CONNECTION: (ground wire)
Connect GREEN wire from power cord to metal screw mount on the bottom of the outlet.

BLACE WIRE CONNECTION: (hot connection)
Connect BLACK wire from power cord to "COMMON" or Terminal 3 center screw post on the RELAY.

Step 5: PUSH-BUTTON SWITCH CIRCUIT -- Control Input and Output to RELAY

I am using a momentary push-button switch connected to GND to control the input and output to the RELAY for this project . The kind I recommend has 4 legs, however there are only two you need to be concerned with.  Using your multimeter check to see which pairs are redundant (meaning always connected, share the same line).  When you press the button, both pairs get bridged, and GND is shared with pin 1 and the circuit is completed and a signal is sent to PIN 2 on the ARDUINO making it go to either a "HIGH" or "LOW" state.

Step 6: SKETCH - Create Sketch to Drive RELAY

Create the SKETCH that will drive the RELAY for this project.
You can either enter the code yourself or you can copy and paste from here.

// Test Relay signal when button is pressed
// Use PIN 7 to send signal to relay
// Turn on LED when the button is pressed to test Sketch code
// and keep it on after it is released
// including simple de-bouncing
//

 #define LED 13                    // the pin for the LED
 #define BUTTON 2              // the input pin where the pushbutton is connected
 #define RELAY 7                 // PIN for relay signal

 int val=0;                               // val will be used to store the state
                                                // of the input pin
 int old_val=0;                      // this variable stores the previous
                                               // value of "val"
 int state=0;                          //0=LED off and 1 = LED on

void setup(){
 pinMode(LED, OUTPUT);               // tell arduino LED is an output
 pinMode(BUTTON, INPUT);           // and BUTTON is an input
 pinMode(RELAY, OUTPUT);          // tells arduino RELAY is an output
}

void loop(){
 val=digitalRead(BUTTON);         // read input value and store it -- new input

 // check if there was a transition
 if ((val==HIGH) && (old_val==LOW)){
   state = 1 - state;
   delay(10);
 }

 old_val=val;                    // val is now old, let's store it

 if (state == 1){
  digitalWrite(LED,HIGH);           // turn LED ON
  digitalWrite(RELAY,HIGH);      // turn RELAY ON
 }else{
  digitalWrite(LED,LOW);            // turn LED OFF
  digitalWrite(RELAY,LOW);       // turn RELAY OFF
 }




TEST YOUR SKETCH:
Load the Sketch on to the Arduino.

Push Button Switch  --  LED on PIN 13 should light.

If not you need to de-bug your sketch and make it like the one above.

Step 7: RELAY Connection to Arduino

In this step we will be using Terminal 2 located on the RELAY.  This Terminal is made up of 3 post screws.

GND -- COM -- VCC

If you are looking at the terminal and can see into the set screw departments then this is the correct veiw of the terminal block.

BLACK WIRE (GND)   -  connects to GND on the Arduino.

YELLOW WIRE (COM) - connects to PIN 7 on the Arduino.

RED WIRE (VCC) -  connects to 5V on the Arduino


VIEW ADDITIONAL PICTURES FOR A LOOK AT THE CORRECT CONNECTIONS AT BOTH THE RELAY AND THE ARDUINO.

Now test the RELAY for signal being sent to Terminal block 3 to drive outlet


Here is a Youtube of the working RELAY:
http://www.youtube.com/watch?v=4IxNJZU5bsM

Step 8: NO - (Normally Open) Function

MAKE SURE OUTLET AND POWER CORD HAVE NO POWER CONNECTIONS!!!!!!!


NO
- ( Normally Open) Configuration for the RELAY 


CONNECTION 1 ----
Black wire from power cord is connected to the "COMMON" set screw of Terminal Block 3 on  the RELAY.  That would be the center connection when looking directly at the front of the Terminal Block. (see picture NO - (Normally Open) - Configuration if any question about this connection)

CONNECTION 2 ---
Using BLACK 600 Volt wire connect one end at the NO - (Normally Open) Terminal Block 3 NO set screw position.  Run this wire back to and connect to the silver screw on the short prong side of the OUTLET.  This will complete the circuit to the outlet.

PLUG IN THE POWER CORD ---
Your LED light on the OUTLET should turn on .  If not you need to double check all connections, after you un-plug the power cord or turn of power to the OUTLET.

IF EVERYTHING IS WORKING ---
Power cord is pluged in, LED light on OUTLET is on
Have Sketch load into Arduino
Have power to Arduino
Now push the BUTTON --  LED on Arduino and LED on RELAY will turn on --  LED on OUTLET will go out.

Here is a video of the actual event:
http://www.youtube.com/watch?v=LYKPc925el0

Step 9: NC - (Normally Closed) Function

MAKE SURE OUTLET AND POWER CORD HAVE NO POWER CONNECTIONS!!!!!!!


NC
- ( Normally Closed) Configuration for the RELAY 


CONNECTION 1 ----
Black wire from power cord is connected to the "COMMON" set screw of Terminal Block 3 on  the RELAY.  That would be the center connection when looking directly at the front of the Terminal Block. (see picture NC - (Normally Closed) - Configuration if any question about this connection)

CONNECTION 2 ---
Using BLACK 600 Volt wire connect one end at the NC - (Normally Closed) Terminal Block 3 NC set screw position.  Run this wire back to and connect to the silver screw on the short prong side of the OUTLET.  This will complete the circuit to the outlet. (see picture NC-OUTLET configuration)

PLUG IN THE POWER CORD ---
Your LED light on the OUTLET should be off .  If not you need to double check all connections, after you un-plug the power cord or turn of power to the OUTLET.

IF EVERYTHING IS WORKING ---
Power cord is pluged in, LED light is off on the OUTLET
Have Sketch load into Arduino
Have power to Arduino
Now push the BUTTON --  LED on Arduino and LED on RELAY will turn on --  LED on OUTLET will turn on.

Here is a video of the actual event:
http://www.youtube.com/watch?v=BGnLDw6T14o