To control high-voltage or high-power circuits with an Arduino, you have to isolate them from the Arduino with a relay. Here's how!

Circuits that operate at high voltages or at high currents cannot be controlled directly by an Arduino. Instead, you use a low-voltage control signal from the Arduino to control a relay, which is capable of handling and switching high-voltage or high-power circuits. A relay consists of an electromagnet that, when energized, causes a switch to close or open. Relays provide complete electrical isolation between the control circuit and the circuit being controlled. 

A relay typically has five pins:

  1. Coil input pin1. This is generally connected to the positive terminal of your signal source.
  2. Coil input pin2. This is generally connected to the negative terminal of your signal source.
  3. Normally Open pin(NO). This pin is normally not connected to the common pin, it is connected when the relay is activated.
  4. Normally closed pin(NC). This pin is normally connected to common pin and is disconnected when relay is activated.
  5. Common. In most of the cases, this pin is connected to the ground of the source we use to drive the appliance.


Contactor
Contactor

Experiment

In this tutorial, we will drive a 12V DC motor using relays.

 

Hardware Required

  • 1 x 12 VCD power supply
  • 1 x 12V DC motor
  • 1 x relay
  • 1 x Arduino Mega2560
  • 1 x NPN transistor
  • 1 x Diode
  • 1 x jumper wires

 

Wiring Diagram

The circuit shown in the diagram below uses a relay to switch 12 V across a DC motor. To turn on the motor, the program writes a HIGH value to pin 3, which turns on the transistor. When the transistor turns on,  current flows through the relay coil causing the relay to close, which connects 12 V across the motor, causing it to spin.

 

Circuit 1

Code

                    void setup() {
  pinMode(3,OUTPUT);

}

void loop() {
  digitalWrite(3,HIGH);     // motor runs for one sec
  
  delay(1000);
  
  digitalWrite(3,LOW);    //moto stops for one sec
  
  delay(1000);
}
                  

  Download Code  


Video


Comments

4 Comments


  • Diane253 2015-10-18

    Can you supply resistor values and part numbers for diode and the transistor? Also I notice an IC you make no mention of

  • Dan Copeland 2016-06-22

    wow very informative, Im so glad a joined this site.  wtf you have an ic in there? if your gonna writing something then actually put some effort into it d-bag.

  • Ryan Bell 2016-08-29

    Seriously….thats the best you can do???? Soooooo here’s an obvious question a beginner may ask…....if your using the Arduino to control the relay which will control the motor, then why are you using a transistor? You make no mention of that or the reasoning behind it. Useless article with the most BASIC info on relays possible.

    Oh and whats even funnier, it was posted by “Editorial Team”......It took them a WHOLE TEAM to write this article….amazing….. lololol

  • Jose Antonio Nunez 2016-09-09

    The same can be achieved with a combination of power mosfets, buffers, opamps, boost converters, etc…