How to Control Relay with Arduino


                              Control Relay with Arduino

12v relay with arduino




 Relay and Arduino   

           A relay is called an electromagnetic switch.Which can be operated by a  low electric current that can convert into much larger electric current. As an input signals the voltage and current applied to the coil for  opens or closed the contacts of electromagnetic switch .

 The definition of Relay is: Using electromagnetic attraction activate the contact, which can be produced by giving an electric current that exceed the specified value flows to the electromagnet. 

When the current passes through the coil it generates electric field . Which makes close and opens (makes or break) the contact with fixed contact.

Relay control with Arduino  

Here we are controlling relay with arduino with simple program and switching the arduino code for blinking the led. For controlling DC motor with Relay Click control-dc-motor-using-relay-arduino

Here we learn the following main features.
  1. Why use Relay with Arduino. 
  2. How check relay when de-energized. 
  3. How check relay when energized. 
  4. Arduino control relay circuit. 
  5. Reason of using transistor with arduino and relay. 
  6. How to calculate resistor value for relay arduino circuit. 
  7. Coding for switching Arduino relay.  

Why use Relay with Arduino

Normally Microcontrollers (Arduino) drains small amount of current. In some devices we need more current or voltages to run for this purpose we used Relays with Arduino. Here we are using 12 volt and 10 ampere relay. Here we are going to done with blink led control by arduino and relay.

How check relay ( Normally open and Normally closed )


relay pins


There are two terminals working you need to check first.

1) Normally closed terminal (NC).
2) Normally open terminal(NO).

Normally closed terminal (NC) when coil is de-energized 

When the relay is not energized . Check resistance across NC and COM terminal with multimeter. The resistance across them is '0 ' (zero). If the resistance across them is zero then the NC terminal is fine. 

Here i am providing detail step by step to test NC terminal.

1) First Put the multimeter settings at ohm meter.
2) Put one of the multimeter probe on NC and the other probe on COM.
3) Read Resistance across them.
4) If the resistance is zero '0'. Your NC terminal working fine.

Normally open terminal (NO) when coil is de-energized

When the relay is not energized . Check resistance across NO and COM terminal with multimeter. The resistance across them is several MΩ ( mega ohms ). If the resistance across them is in MΩ then the NO terminal is fine. 

Here i am providing detail step by step to test NO terminal.

1) First Put the multimeter settings at ohm meter.
2) Put one of the multimeter probe on NO and the other probe on COM.
3) Read Resistance across them.
4) If the resistance is in MΩ. Your NO terminal working fine.

Relay is energize 

Energize the relay by using any external appropriate voltage source for rating of relay coil. Make sure your voltage source is connected with right polarity. When it is connected and relay is energized listen the voice of click.  

Normally closed terminal (NC) when coil is energized 

 when relay is energized. When connect the probes of multimeter with NC and COM. You find opposite condition of de-energized. Here you got infinite resistance or resistance in MΩ. In energized case if resistance is in MΩ then your NC (normally closed ) terminal of relay is working fine.

Normally open terminal (NO) when coil is de-energized 

 when relay is energized. When connect the probes of multimeter with NO and COM. You find opposite condition of de-energized. Here you got zero resistance across this terminal. In energized case if resistance you got is zero then your NO (normally open ) terminal of relay is working fine.

Arduino Relay Control Circuit


relay arduino circuit

Remember 

One of the most important things we should also find is our relay coil resistance. This is for measuring current.

First of all we should find the coil in relay. Mostly it is at pin 2 and 5 as labelled . If not then you have to check resistance at every pin.

Between these two pins you got resistance between 100 to  10 KΩ. Here i found 4200 ohms resistance.

Now calculating current

V = I.R
so I = V/R   = 12/4200

I = 28 mA.

Arduino can drain 20 mA current and need 28mA to switch relay. So we use npn P2N2222A transistor.

 

Reason of using transistor with relay

 
            If you supply 5v directly to the coil of 12volt relay using IO pin of arduino maybe the current is not enough to switch the latch since 5v / 400 ohm = 0.0125 A or ~13mA compare to typical 30mA of 12v relay. So you have to use a transistor as a switch so that you can use 5v source of arduino to switch on 12v source to power the relay. Any 12v source would be fine if it is able to provide current larger than 30mA.

If you use 5v relay and use arduino IO pin to drive the relay directly, the coil resistor is around 70 ohm which needs ~71mA to work. This time 71mA excess the absolute 40mA current limit of arduino IO pin. It will likely damage your arduino. So again, you have to use transistor as a switch to amplify the current apply to the relay coil.

Calculating resistor value connected with transistor.

You have value of hef in datasheet of P2N2222A here http://www.onsemi.com/pub_link/Collateral/P2N2222A-D.PDF  after getting value of hef you you can find Ib value.

 Ib = Ic / hfe

at 10mA and 10 volt DCthe hef is 75

Ib = 0.028/75 =  0.00037 A

now for resistance

R = 5v/Ib = 5/0.00037 = 13513 ohm.

this is not in standard resistor so you use 12k or 12.5kΩ resistor with arduino pin and transistor.


Arduino Relay switching code


int pin = 6;

void setup() {


pinMode(pin,OUTPUT);

}

void loop() {


digitalWrite(pin,HIGH);

delay(1000);

digitalWrite(pin,LOW);

delay(1000);

}

 You have successfully completed one more Arduino "How to" tutorial and you learned how to use Relay with arduino.
I hope you liked this, if you have any query let me know in the comments. 

There will be more of them, so make sure to click Follow button!

Hope you enjoyed the lesson, keep looking at my profile for more arduino lessons soon.

   




Previous
Next Post »
1 2 3 4 5