Saturday, 17 August 2013

Interfacing with the Real World - Working with the Simple Labs Relay Control Board

Simple Labs Relay Control Boards
Simple Labs 3 Relay Board

This is a board with 3 Relays and a ULN2003 Driver IC to drive them. In case you don't have it, you can buy it here -> Simple Labs Relay Control Board

Simple Labs 4 Relay Board - New!
This is the latest relay board. it comes with 4 Relays and a ULN2003 Driver IC to drive them. In case you don't have it, you can buy it here -> Simple Labs Relay Control Board - 4 Relays

The current from the I/O Pins of our Induino R3 is not sufficient to drive a relay. Hence we will be required to use a transistor to control a relay. The ULN2003 is Darlington Transistor Array that consists of 7 Darlington Pairs of transistors. Each pair can drive 1 output requiring higher drive current [in our case relays].


A 5-pin / 6-Pin connector is provided to connect the relay control board to connect it to a microcontroller board. The pin description is as follows.

3 Relay Board

'+': 5V
'RL1': Control pin for relay 1
'RL2': Control pin for relay 2
'RL3': Control pin for relay 3
'-': Ground

4 Relay Board

'+': 5V
'RL1': Control pin for relay 1
'RL2': Control pin for relay 2
'RL3': Control pin for relay 3
'RL4': Control pin for relay 4
'-': Ground


Three 2-pin screw terminals, one for each relay is provided in the normally open mode, which means by default, there is no conductivity between the two pins of the screw terminals. The relay control pins are given as input to ULN2003. The Darlington paired transistors inside the ULN2003 provide enough current amplification to drive the coil in the relay. The coil in the relay when activated will in turn trigger a switch which will internally close the connections between the two terminals of the screw terminals.
Connection Diagram for the 3 Relay Board





Connecting the Relay Control Board to your Arduino / Induino R3 Board
  • Connect the '+' of the Relay control board to the 5V pin on your Arduino / Induino R3
  • Connect the '-' of the Relay control board to the GND pin on your Arduino / Induino R3
  • Connect one of the 2-pin screw terminals (RL1/RL2/RL3/RL4) in series with the load and supply (Remember, the relay is just like a switch)
  • Connect one of the relay control pins (RL1/RL2/RL3/RL4) of the 5-pin / 6-pin connector to any digital output pins of a micro-controller.
  • Turning on the relay control pin will turn on the respective relay hence turning on the load.
Programming it up

For a start, connect the RL1 from the relay control board to Pin 13 of your Induino R3 / Arduino Board and upload the Blink sketch from examples->basics

/*  Induino R3 User Guide - Program 13.0 - Interfacing the Simple Labs Relay Control Board with the Induino R3
    Blinks a LAMP connected to the Relay Control Board
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


Now lets do something more interesting, lets try to switch the lamp on/off using our remote. The hardware setup would remain the same however the program would vary. We shall toggle the state of the lamp connected to the relay every time the button '1' is pressed on the remote control (sony remote - modify code according to your own remotes)



/*  Induino R3 User Guide - Program 13.1 - Interfacing the Simple Labs Relay Control Board with the Induino R3
    A Remote Controlled Lamp
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int lamp = 13;
int state = 0; // Store the current state of the lamp
void setup()  
{ 
  pinMode(lamp,OUTPUT); 
  pinMode(15,INPUT); // TSOP is connected on the 15ht pin  
  Serial.begin(9600);  
}  

void loop()  
{  
  int remote_val = remote();  // Call the remote function to get the value of the key pressed
  if(remote_val>0)  // check if the value is greater than 0. A 0 means that no signal was received by the TSOP
  {  
    Serial.println(remote_val);
    if(remote_val==128) // Button 1 on a Sony Remote / Substitute value accordingly
    {
       state = !state; // toggle the state variable between On and Off
       digitalWrite(lamp,state);
    }
    delay(150); // A remote press will normally generate 3 signal trains. This is to avoid reading duplicates  
  }  
}  


// A Dedicated function that will calculate and return a decimal value for each of the buttons on a remote.
int remote()  
{  
  int value = 0;  // a Variable to store our final calculated value
  int time = pulseIn(15,LOW);  // we need to look for the duration of the LOW pulse as TSOP will invert the incoming HIGH pulse
  if(time>2000) // Checking if the Start Bit has been received. Start Bit Duration is 2.4ms  
  {  
    for(int counter1=0;counter1<12 data-blogger-escaped-12="" data-blogger-escaped-a="" data-blogger-escaped-as="" data-blogger-escaped-be="" data-blogger-escaped-bits="" data-blogger-escaped-counter1="" data-blogger-escaped-if="" data-blogger-escaped-in="" data-blogger-escaped-inverse="" data-blogger-escaped-is="" data-blogger-escaped-loop="" data-blogger-escaped-msb="" data-blogger-escaped-next="" data-blogger-escaped-order="" data-blogger-escaped-pulsein="" data-blogger-escaped-receive="" data-blogger-escaped-receiving="" data-blogger-escaped-the="" data-blogger-escaped-to="" data-blogger-escaped-we="" data-blogger-escaped-will="">1000) // checking the duration of each pulse, if it is a '1' then we use it in our binary to decimal conversion, '0's can be ignored.  
      {  
        value = value + (1<< counter1);// binary to decimail conversion. 1<< i is nothing but 2 raised to the power of i  
      }  
    }  
  }  
  return value;  
} 

Thats It For This Part! Enjoy... and feel free to drop us an email with questions you might have -> info@simplelabs.co.in Visit www.simplelabs.co.in for more interesting products

14 comments:

  1. I power the arduino with 12V and 2A D.C jack. and i use all the three relay using your relay board for a long run (e.g. 12hrs) will the board withstand the current drawn by the relays...

    ReplyDelete
    Replies
    1. Hi aatif, we have a similar live setup in our office controlling 2 lamps and 1 fan and its been running for 6 months now... only we dont use it all the time continuously.. to be on the safer side, you can have a separate 5V supply for the relay board.. any time you work with a load with lots of coils (motors, relays, etc) better to have a separate power supply for them

      Delete
  2. can someone anser Aatif's question plz

    ReplyDelete
  3. How to connect 2 relay boards having 8 relays to the induino r3 noard

    ReplyDelete
    Replies
    1. In the same way as you would connect a single relay... ensure you have a proper 5V power supply..

      Delete
  4. How much wattage can they handle,.. Say if i want to control toaster, or AC,. Will they able to withstand or will they burn away.

    ReplyDelete
    Replies
    1. Not advisable for A/C's... Toasters, depending upon the toaster should be ok... check ratings on the relay and work @ 70% of the given ratings for best results.

      Delete
  5. how do i control the switches on the wall?
    having both the audruino relay board and the switches on the wall work together
    and exactly how much load exactly can the relay board take?
    thanks!

    ReplyDelete
    Replies
    1. Well this requires some tricky wiring and a relay with both NC & NO states. The process is going to be similar to wiring a two-way switch.

      Delete
    2. I got the the four channel relay from simple labs and its has a 3 pin pheonix connector, but this tutorial has a relay with only two pins. Can u plz tell me the difference?
      Thanks

      Delete
  6. I got the the four channel relay from simple labs and its has a 3 pin pheonix connector, but this tutorial has a relay with only two pins. Can u plz tell me the difference?
    Thanks

    ReplyDelete
  7. I am getting lots of errors which are not declared. like - pulsein was not declared in this scope.
    almost every line has an error. it says ; expected before data

    ReplyDelete
  8. Could some tell me how to get the codes of my remote of each key with induino4

    ReplyDelete