Arduino Basics: Relay Module

8 September 2014

Relay Module

WARNING: Mishandling or incorrect or improper use of relays could result in

  • serious personal injury or DEATH
  • possible physical damage of the product
  • faulty operation
  • or create serious/dangerous hazards.

Please make sure that you read and understand how your relay/relay module board works, the voltage and current it is rated for, and the risks involved in your project BEFORE you even attempt to start putting it together. Seek professional and qualified assistance BEFORE you undertake ANY high power projects.

If you choose to follow the instructions in this tutorial, you do so at your own risk. I am not an electrician, and am not a qualified electrical engineer - so please do your research and seek advice BEFORE undertaking a project using a relay. Please check your connections and test them BEFORE turning the power on.

I accept no responsibility for your project, or the risk/damage/fire/shock/injury/death/loss that it causes. You take full responsibility for your actions/project/creation, and do so at YOUR OWN RISK !!!

Please note: It is illegal in some countries to wire up a high power project without an electrician. Please check your country's rules/laws/regulations before you undertake your project. If you have any doubts - don't do it.


What is a relay

A Relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate the switch and provide electrical isolation between two circuits. In this project there is no real need to isolate one circuit from the other, but we will use an Arduino UNO to control the relay. We will develop a simple circuit to demonstrate and distinguish between the NO (Normally open) and NC (Normally closed) terminals of the relay. We will then use the information gained in this tutorial to make a much more exciting circuit. But we have to start somewhere. So let's get on with it.

Parts Required:

Fritzing Sketch



Table of Connections


Arduino Sketch

/* ===============================================================
      Project: 4 Channel 5V Relay Module
       Author: Scott C
      Created: 7th Sept 2014
  Arduino IDE: 1.0.5
  Description: Explore the difference between NC and NO terminals.
================================================================== */

  Connect 5V on Arduino to VCC on Relay Module
  Connect GND on Arduino to GND on Relay Module 
  Connect GND on Arduino to the Common Terminal (middle terminal) on Relay Module. */
 #define CH1 8   // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
 #define CH3 7   // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
 #define LEDgreen 4 //Connect Digital Pin 4 on Arduino to Green LED (+ 330 ohm resistor) and then to "NO" terminal on relay module
 #define LEDyellow 12 //Connect Digital Pin 12 on Arduino to Yellow LED (+ 330 ohm resistor) and then to "NC" terminal on relay module
 void setup(){
   //Setup all the Arduino Pins
   pinMode(CH1, OUTPUT);
   pinMode(CH3, OUTPUT);
   pinMode(LEDgreen, OUTPUT);
   pinMode(LEDyellow, OUTPUT);
   //Provide power to both LEDs
   digitalWrite(LEDgreen, HIGH);
   digitalWrite(LEDyellow, HIGH);
   //Turn OFF any power to the Relay channels
   delay(2000); //Wait 2 seconds before starting sequence
 void loop(){
   digitalWrite(CH1, HIGH);  //Green LED on, Yellow LED off
   digitalWrite(CH1, LOW);   //Yellow LED on, Green LED off
   digitalWrite(CH3, HIGH);  //Relay 3 switches to NO
   digitalWrite(CH3,LOW);    //Relay 3 switches to NC


The Red light on the Relay board turns on when power is applied (via the VCC pin). When power is applied to one of the Channel pins, the respective green light goes on, plus the relevant relay will switch from NC to NO. When power is removed from the channel pin, the relay will switch back to NC from NO. In this sketch we see that power is applied to both LEDs in the setup() method. When there is no power applied to the CH1 pin, the yellow LED will be on, and the Green LED will be off. This is because there is a break in the circuit for the green LED. When power is applied to CH1, the relay switches from NC to NO, thus closing the circuit for the green LED and opening the circuit for the yellow LED. The green LED turns on, and the yellow LED turns off.

I also show what happens when you apply power to a channel (eg. CH3) when there is nothing connected to the relay terminals. The respective onboard LED illuminates. This is useful for troubleshooting the relays, and knowing what state the relay is in (NC or NO). NC stands for Normally closed (or normally connected) NO stands for Normally open (or normally disconnected)

Here is a circuit diagram for two of the relays on the relay module (CH1 and CH2).
This was taken from the iteadstudio site.



The Video



This tutorial will become very useful in the future. I now have an easy way of switching a circuit electronically. Yes, I could do this with a transistor, but sometimes it is nice to hear that mechanical click. I am not sure why I like relays, but I find them to be quite fun !!

If you liked this tutorial - please show your support :




  1. Thanks for an awesome blog! One thing that is killing me is the music in your videos. The crappiest music ever! Keep it rather silent than putting those lame tunes on.

    1. Haha! The music is pretty lame. Unfortunately there is not much to choose from when you are trying to keep it free :). If you know somebody that will allow me to use their music for free. Please let me know.
      While I know you have a volume option within YouTube, I thank you for your honest feedback.

    2. Try taking music from Internet Archive where they have some music which has been put in public domain.

    3. That is where I get all my music from. But there have been some improvements in the quality of music.

  2. hye, i have follow your work, but i dont put any resistor to my LED..and the result is,yeah,LED is not blinking...but my CH is keep blinking and keep changing alternately just like you is because of resistor?and i use Arduino Uno ethernet, so i changed a little pin in the sketch

    1. You need to connect a resistor in series with the LED.
      It is possible that you could have damaged your LED or Arduino Pin (by skipping the resistor).
      Try running the blink sketch, and test each pin with an LED + resistor. Once you know your Arduino and/or your LEDs are fine, then try incorporating the relay module. But you MUST use a resistor as described in the sketch above.

    2. can i know how much the ohm of resistor that i must use?

    3. Nurul... I cannot answer that question. The reason I cannot answer that question is because I do not know what LEDs you are using. I usually use 330 ohm resistors for the LEDs that I have, but that may or may not be suitable for your LEDs. Here is a better explanation.

  3. Hi, your blog is very nice and useful..By the way i have some projects in mind that i want to use your relay module information. If its ok for you? im planning to expand the use of arduino by using some inputs to control the individual actions of the relay. i have this input per relay and every time there an input, delay timer starts for example 12 mins before the relay activate. Hope you have some suggestions in mind.

  4. So, I am missing something. Why do you have a connection to Channel 3 on the relay module? Relay 3 doesn't have anything on it, I only see the NC and NO on Channel 1 being used. It seems that part was un-necessary, unless it's just for future expansion or something. Not criticizing, just asking. Great project BTW

    1. Hi Dax, you are not really missing anything.
      I was mainly trying to emphasize and demonstrate how the relay module LEDs light up when their respective relay is activated. It was mainly for demonstration purposes.

      And you have great insight. The next project I did was this one:
      Arduino Selfie. This project actually used both channel 1 and channel 3. And yes - I know, a relay was overkill for that project... :)

    2. After I re-read your post, I see that my question was not a very good one. You did explain it, I just missed that detail about you saying it demonstrates the little LED and how it's good for troubleshooting. Thanks for the fast reply, and keep up the good work!

    3. No worries Dax. Thank you for the feedback... and keeping me on my toes :)

  5. hi have just used this with ssr instead of normal relays but the relays dont seem to be switching off is their something iam missing to turn them off please help if you can thanks .

    1. Hi Dave,

      I think we will need to take your query to the ArduinoBasics forum.
      Follow this link to get to the forum.
      Post your question, and show your setup and code. Also provide a datasheet for your ssr (if you can find one)...or a link to where you got it maybe??

  6. Hey, I want to ask a question about the relay module. Is an optocoupler relay module better than the on e used here?

    1. I guess it depends on what you plan to do with the relay module.
      There is a good discussion on this topic here.

  7. Hello, can you help me I need full optical isolation and I connected Vcc to Gnd but it doesn't work. I bought module relay here but even on this web site I couldn't find any tips what to do(

    1. Hi Scott,

      Not sure what you mean "it doesn't work". Plus I have no idea what relay module you bought, because the link you provided was too generic.
      Please post queries related to your own projects here:
      Please provide a bit more detail - so that I can understand what it is you have, what you are trying to do, and what you have done so far.


  8. Can 1 arduino uno cater 5 - 4 channel relay modules ?? equivalent to 20 relays???


    1. Possibly. But it is limited by the number of available pins (you could possibly use the 13 digital pins and the 5 analog pins - which only gives 18 relays) but italso depends on whether you need all relays on at the same time or not....If you don't need them all on at the same time, you can get creative with how you utilise the available pins, otherwise if you do need all relays on at the same time, then I would recommend using something like the Arduino MEGA...

  9. hi great tutorial I see you answer your comment section so I need some help I dont know arduino I cant seem to understand the programing logic as its nothing like the relay logic I know. would it be possible for you to design a circut for me im building a pellet gun target that will actuate with a micro switch ( button) when hit will turn on relay for 5 seconds then reset and wait for next shot. if you can help great. thanks for your time

    1. As this is a query about your own project - I think it would be best served in the ArduinoBasics forum. Just copy and paste this into a new topic, and we can discuss further.

  10. Hi,
    Can you also put 230V AC on the relays and control them with the 5V of the Arduino?
    When it is possible it doesn't matter which cable is put on the ground and on the NC/NO, right?

    1. Hi Anonymous,

      First let me say that in some countries, you need to an electrician to hook up high voltage AC circuits. Please research whether this is true for your country.

      Next - let me say that "playing" with these voltages can be fatal... so you should know what you are doing before attempting a project using high voltages.

      Lastly I would recommend that you read the datasheet for the relays on your board, and make sure they can handle the AC circuit you are trying to connect.

      One more lastly - I would test it with a low voltage circuit first. Make sure it works how you expect it to work.

      There are some relay boards that can control high powered circuits from 5V coming from the Arduino. A relay is an electrical switch, and isolates the Arduino from the high powered circuit.
      When 5V is sent to the relay, the switch activates and the current flows through the NO line through to common (or vice versa)... Whether you hook up to the NO or NC will depend on whether you want to turn the device ON or OFF by sending 5V from the Arduino.

      So just to clarify... when you send 5V from the Arduino, it essentially connects the "NO" wire to the "Common" wire. And when you stop sending 5V, this connection between NO and Common is broken.

      If you follow my tutorial, you will get a better understanding of how relays work.

  11. do you know how to use a relay without an arduino ?

  12. Hi,please make me understand how to connect a ac submersible pump to a 4 channel relay
    to control water level of a tank using arduino?

    1. Hi Unknown,

      Well - start with this tutorial, and perhaps my water sensor tutorial may also help. Just put these together.

      It depends on how you plan to monitor the water level. I know some people use these water sensors, but others use the ultrasonic sensors. In which case this tutorial may be useful:

      When you detect water above/below a certain point, you can switch on/off the relay.

      Make sure your relay can cope with the voltage/current you plan to use. Look up the datasheet for your relay to get better insight.
      Playing with AC current can kill you (or others). Perhaps seek advice from an electrician before you move forward with this project.

  13. found page helpful. was messing with arduino wires damn stiff things. finally got relay to start clicking like a trooper.
    now need more wires , trying to play ipad game using arduino , hmmm

    1. Hi Terry - I am glad this tutorial helped you. I am not sure how your relay board is all mapped out. But I would have put the "blue ground wire" from the Arduino to the GND pin on your relay board (next to the VCC pin or yellow wire in your video).

  14. Thanks for this tutorial! I've started experimenting with Arduino and I've run through all the projects that were in my "Learn Arduino Basics" pack. So now I'm adding small items a bit at a time and trying them out. Last week was the Hall Effect sensor and this week the relay. I'm glad your tutorial didn't require kit I don't have.

    1. Excellent Amy - keep it up... you'll be an expert in no time.

  15. Does this work without the relay module?

    1. Sorry - that question is too vague... does what work ?? What are you trying to do ?

  16. Hello sir I am working with AC 220V could it controlled by arduino digital output?

    1. It is always worth asking the seller of the product or looking at the datasheet for the specific product you choose to buy. If you cannot find this information easily, then I would recommend that you look for a site or product where the information IS available, and meets your needs... Any projects you choose to undertake that involves high voltage should be installed by a licensed electrician, and is at your own risk. Incorrect connections could cause serious harm or death. If you do find the correct relay shield, yes technically, it can be controlled by an Arduino Digital output.

  17. How did you get the relay into fritzing? Is that just an image or did you find a 4 channel relay fritzing component somewhere that someone created? I have been looking for one or an 8 channel component.

  18. Hi,
    Great post. Unfortunately, I have a different kind of a relay board. It has 2 pins for input on one side and 3 on the other. Can you please help me out with its connections?
    Here's the link for its image if you want:

    1. I would say that the side with 2 connections is the side that controls the relay, and the side with 3 pins is the relay side (similar to my relay board).

      First try to light up the LEDs on the board. Not sure which is VCC and which is ground, but I am guessing that you cannot really get it wrong... the LEDs and diodes look like they will only allow one particular configuration.
      As for the relay side - you can test the connections using a multimeter. This will help test the normally open and normally closed sides.

  19. In the NC position connects and the yellow LED glows(LOW signal) but when the NO position is supposed to be connected when I provide the HIGH signal the green LED does not glow.Why is it so?

    1. Check the orientation of the green LED. Does the channel LED illuminate when you provide a HIGH signal? Are you using this relay board ? If not, does it support a 5V signal ?
      Do you hear the relay click when you provide a high signal.
      Also make sure that you are providing 5V to VCC and have not accidentally provided 3.3V

    2. This comment has been removed by the author.

    3. Vyushti - glad you manage to work it out. Shame that the other board did not work for you.

  20. hi scott,
    am working on a project where am thinking of using a 1 channel relay between 2 parts of a circuit such that when it is open the output is taken only from the first part of circuit, if closed the output is taken from the second part of the circuit.i need to control where the output is taken using arduino. how should i go about it. thanks

    1. Hi Anonymous,

      I have a couple of ideas - but questions about your own project are best served in the ArduinoBasics Forum (link at the top of this page) - where I will respond to your query. Thank you

  21. hi..
    i had made connection from relay to motor, as NO is connected to vcc 5v, C is connected to motor(water pump) of one side and motor(water pump) of other side is connected to gnd, where no connection for NC,well the problem is when ardiuno switch on the relay for motor(water pump) operation, water pump turn on few sec and gets to off. but i need continuous to turn motor until the power supply is off.

    1. Hi Arjun,

      I am a bit confused, why are you connecting VCC to NO?
      Are you trying to power the motor using the Arduino 5V pin ?

      Don't connect the motor to the common line, connect it to the NO or the NC side of the relay (depending on whether you want it to be "ON" until you switch it off, or "OFF" until you switch it on. You should be powering your motor using an external power supply, unless it is a small hobby servo motor, in which case you can exclude the use a relay altogether.

    2. can i turn off the arduino by coding or relay?

  22. Thanks For this!.
    I like the music :-)

  23. About two years ago I found a schematic that showed how to wire an Arduino 4 channel relay with another 4 channel relay shield to allow the Arduino to control all 8 relays. Does anyone know where I can find it. I have many Seeed 4 relay shields (v1.2) and I need to make a few 8 relay projects. I cannot find that info anywhere now. Any help would be greatly appreciated.

  24. hi scott

    am doing a project which temp and rtc with relay to on and off the motor and fan.but when i program the relay logical operator the relay LOW not running..ASAP

    1. Depends on the relay.
      Some relays need a higher voltage to operate.
      Best seek advice on the Arduino forums so that you can post further info.

  25. What rate can Arduino relays open and close continuously? I would like to use relays to sequence a number of 110V LED floodlights in a chase pattern using an Arduino Mega. Will this work or will the rapid cycling of the relays cause them to fail prematurely?

    1. Hi Tim,
      MOSFETS are probably better suited to the job you are trying to do.
      I am assuming you are dealing with DC voltage for the LED floodlights.

      Otherwise - solid state relays may be an option.

      What rate do you want the LEDs to switch on/off ?
      And how many amps?

      The answer to these questions may push you to one or the other.

  26. How would I do this using a 3.3V microcontroller? Do I have to buy a special relay for that?

    1. There are solid state relays that can be driven by 3.3 V.
      There are also modules like this one which can also be driven by 3.3V:
      "3V High Level Driver Module Optocouple Relay Module For Arduino".

      Alternatively, you could perhaps drive the relay using your source voltage ?? What voltage is powering the 3.3V microcontroller? You may need a voltage regulator and/or an optoisolator/MOSFET to drive the 5V module. Do a simple google search for "Drive a 5V relay module using 3.3V" - you should get thousands of results that will get you in the right direction.
      But if you haven't bought the relay module yet, then just get one that can be driven by 3.3V. That would be the easiest path.

  27. Hi.
    I have an Arduino Uni controlled by a RaspberryPi. The Arduino is powered by a USB cable from the RaspberryPi. The Uno has a couple of temperature sensors connected in addition to a 2 channel relay board ( and is used to switch on and of a heater and cooler on the two channels. Basically its the same as your example. The software on the RaspberryPi is operating the relay based on the temperature. The software and setup seems to work OK as the correct LEDs on the relay module turns on and off when the software wants to heat og cool. But the coils in the relays are not activated. The is no sound and a multimeter confirms that only NO is activated.
    I was worried the RaspberryPi did not give enough power, but taking 5V from the Arduino directly to the relay coil activates it, so I concluded that there sould be enough power.
    I don't have anything connected to the NO/NC, appart from the multimeter. Should the relay switch without anytinh connected?
    The jumper on the JD-VCC is as shown onthe picture.
    Any idea what can be wrong? Is it a faulty relay module?

    1. It is possible to get the relay to switch without anything connected to the NO/NC end.
      Obviously, you need a connection from the Arduino 5V pin to Relay board VCC, Arduino GND to Relay board GND, and then a digital pin from the Arduino to the IN1 or IN2 pins on the Relay board.
      When the digital pin goes HIGH, it should switch the relay.

      Check that you are getting 5V from the digital pin.
      It is possible that the RPi USB port is not supplying enough power for both the Arduino and the relay board. Maybe try with a standard computer or laptop to see if problem persists.

  28. hi i have a project creating automatic switch,here is the scenario, when Ac voltage is on my 12 volt dc battery is off but when my Ac voltage is off then my 12 volt dc battery where on it is possible?

    1. Yes it is possible. You just need to have an AC current sensor. When the AC is off, you can trigger the relay which could switch on your 12V battery.

  29. I was wondering that isn't the relay module active low which means when the signal is LOW the relay will be turned ON? In your case the relay is turned ON when the signal is HIGH. I am a bit confused. Would you elaborate please? Thanks.

    1. I don't know what relay module you have, but the one in this tutorial will activate or switch the relay when 5V (HIGH) is applied to a channel.

  30. hi. iam using arduino board and relay for operating my 240v ac fan and 240v light. there is no problem, if i power on the fan and lights by mobile means it will working. but if i switch on and off the fan and tube light means for continuously for 5 to 6 times. automatically it will power off the fan and lights . for this problem, i have to use any additional electrical items for avoid this. kindly reply to me and solve my poblem..

    1. Sorry - I did not quite understand your problem.

  31. Hello Scott!

    Great tutorial! I have a Arduino Mega 2560 with a Koman LCD shield and a 4 relay module ( I'm trying to find a way to connect this temperature/humidity sensor ( is the HX93AC model. Page 15 has the sensor's specs. the sensor is going to monitor my indoor vegetable garden. And the relay is going to control my devices base on the sensor data. Any help is greatly appreciated!


  32. I want to control relays using anrdoid phone by wifi module ESP8266 which is connected to ardunio mega 2560. so tell me how to start accomplish this task...thanks...!

  33. Sir Is it possible to activate the relay on for 10 minutes and off for 50 minutes by changing the delay time in the source code?

    1. If you don't want the Arduino to do anything else, then I guess you could probably change the delay time. The delay function is a blocking function, which means that you cannot get the Arduino to do anything else while the delay is 'active'. There are better ways of switching the relays using millis() or the Time library - especially if you want to work with 10-50 minute timeframes.

  34. HI sir, how to control devices with high ampere rating using Relay boards?


Feel free to leave a comment about this tutorial below.
Any questions about your particular project should be asked on my Arduino Tutorials Discord Server.

Comments are moderated due to large amount of spam.