Arduino 2 Channel Relay




About: I have been working in IT since the mid 1980's. Most of that has been database and application development. I've been working on Internet application development since the late 1980's. I've just moved back ...

This instructable is for connecting your Arduino to a 2 Channel relay module and using your sketch to control the switches.

I bought the 2 Relay Module on eBay (for $9.50) to drive a couple of 240V parts (a vacuum cleaner and a rotary engraving tool) that I'm using with my CNC Etching mill (still under construction). The idea was that the controller of the CNC etching mill would turn both of these devices on when the machine was etching, one to do the etch, while the other sucked up all of the detritus from the etch.

In this instructable, I'm using:

  • Arduino UNO
  • 2 Relay Module
  • 2 LED
  • 2 220 ohm resistors
  • some jumper wires (7 actually)
    • 4 of the jumpers are Male to Female
    • 3 of the jumpers are Male to Male

This instructable does not connect anything to the relays, it just runs them.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Wire the Circuit Up

I'm connecting the relay to Analog pins on the Arduino because in my circuit, I'm running low on Digital pins. Analog pins on the Arduino can be used as Digital simply by setting the pinMode appropriately and using digitalWrite to ... digitally write to the pin :p
  • Relay GND > Arduino GND
  • Relay IN1 > Arduino A0
  • Relay IN2 > Arduini A1
  • Relay Vcc > Arduino 5V

I've connected some LED to the circuit to use as indicators, which is a little redundant as the Relay Module also has indicator LED on the board. You can leave these out of the circuit if you want ... although I plan to mount the LED on the project box and I'm not going to use light pipes on the SMD LED.

The LED are connecting to digital 12 and 13. These are connected to ground via 220 ohm resistors.

And there you have it, the Relay module is connected to the Arduino and you are good to go.

Step 2: Sketch It Up

The sketch is downloadable on this page.

The two relays are dimensioned in the top of the sketch:

int RELAY1 = A0;
int RELAY2 = A1;

Note that I am passing A0, A1 as integers ... neat, huh?

In setup() the relays are prepared using pinMode:

pinMode(RELAY1, OUTPUT);

and then set to HIGH using digitalWrite:

digitalWrite(LED1, HIGH);

Depending on how you are connecting your load to the relay NO = Normally Open or NC = Normally Closed, it's a pretty safe idea to ensure that the relay is initially OFF (in my case, that's HIGH).

Test your relay and don't just believe that it's either ON or OFF ... prove it to yourself.

In the loop() we are just switching the state from HIGH to LOW for both of the relays. The relays can be operated independently, so you can use the 2 Relay Module to control two devices independently, maybe in response to 2 different sensors?

In this configuration, the relays are not supplying a load, but they are working. When the relay toggles OPEN and CLOSED, there will be an audible *CLICK* for each transition.

When you have connected the module to the Arduino, uploaded the sketch and powered it up, you'll get a click a second ... unless you change the value of "delayValue" of course.

As mentioned earlier, this is a very simple instructable without many parts and with a fairly terse description.

I'm going to make a garden watering system for my vegetable patch using this circuit with a 120L/hour pump and a simple hygrometer ... I'll show the relay in action in that later instructable.

Good luck and happy/safe play!

Step 3: Relay With Load

After a little bit of effort, I cut up an old 5V DC wall wart to make a simple power supply on the relay side of the circuit. To do that, I simply cut the connection from the end of the wall wart, soldered an extension onto the negative lead (to make it longer and with a heat shrink shield). Then I tinned the positive lead and put it into the normally open (NO) screw terminal on the relay (channel 1).

I cut another piece of wire and tinned both ends and put it into the common (C) screw terminal on the relay (channel 1).

The Common lead and the Negative lead were then connected to an 8V lamp (something that I use for circuit testing as it is a good indication of load). Finally, I provided power to the Arduino and, yay, an 8V lamp blinky was born ... "Hello World!"

You may (or may not) notice that I disconnected the redundant LED from the circuit. This circuit has so many applications in home automation and for internet of things jiggery-pokery. Because the relay can handle up to 250V it will be able to control power to any 240V device in the house from lights to audio equipment.

On the other side of the circuit, the Arduino is a 5V device and can interact with 5V (and 3.3V) sensors and digital equipment.

This combination gives rise to a many possibilities from turning the kettle on when the front door opens (who doesn't want a cup of tea or coffee when they get home), sending an email message (with an attached photograph) to you when someone goes into your workshop, watering your precious vegetable patch when the soil moisture level gets too low, how about an automatic alert to a carer when your blood sugar gets too low? You are only limited by your imagination, budget and (to some degree) the availability of sensors.

All Hail The Rise of the Mad Home Scientist!

Be the First to Share


    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    26 Discussions


    Reply 5 weeks ago

    put a pull up resistor to IN1 and IN2, this way the shutdown state of relay is guaranteed.


    10 months ago

    I am using this relay and for some reason when the arduino output is set to HIGH, the relay is sometimes erratically and rapidly switching on and off. Even touching the relay affects it.
    I have checked my wiring. The arduino is outputting a steady 4.7V on HIGH.


    1 year ago

    hi here is the code i made, feel free to copy.

    relay 1.jpg

    Question 1 year ago

    Is it possible to read the state of a relay? I am working on a system to turn my room fan on if the temp reaches above a certain point. I figured out how to turn the relay on or off depending on temp, but it tries to turn the relay state on or off on every loop cycle. Is there a way to determine if the relay is currently in NO or NC position so I can have the loop cycle only change state if it is not in the correct position? (i.e. if the temp gets to the setpoint, turn the relay on ONLY if it is not already on and vice versa) Thank you.

    2 answers

    Answer 1 year ago

    rather than trying to read the state of the relay, you would probably be better off reading a variable with the state of the relay. So, when the relay is switched "on" then the variable is set to 1 ... when switched "off" it's set to 0 (or use booleans). The temperature then becomes a sub-criteria for the evaluation. If relaystate then if temperature ... Of course, that would mean that the micro would need to be always on to maintain state.


    Answer 1 year ago

    I think this might be a better option for what I am doing:

    That way I can use the 2nd pole to pass a 5vdc signal back to an Arduino input to verify the relay state. The problem I had when testing was that the Serial Monitor would tell me that the relay 1//2 was on or off even when the board wasn't hooked up. I want to actually verify that the relay did indeed close the NO contact or not.


    2 years ago

    Hi there,

    I have a question: If you used only one relay, Why did you use a module with 2 relay? Would I use a only one relay module?

    as well I want to know how many lamps Can I turn on/off with one relay module?

    Thank you so much!


    2 years ago

    Thanks for the instructable! Just what I was looking for. I plan on controlling my garden drip irrigation system with an arduino using 2 sensors, a soil moisture sensor and a rain detection sensor, along with a real-time clock module (I don't want it watering between certain hours, regardless of the other sensors). I want to use the relays to turn the sensors on and off, since I do not need them powered all the time, just when I need the data. All the program has to do is check the sensors, then activate a 12 volt water valve. This will be my very first home project, so I was looking for code to independently run the relays. Think this will help a great deal. Just have to find a way to manipulate the data the way it needs to be. Thanks again!

    1 reply

    Reply 2 years ago

    Thanks Pinnaclelarry, I'm only too pleased that you find the instructable useful for your project.

    Let me know how you get on!

    Cheers Baelzabubba


    2 years ago

    I have a query. The output of the relay is not connected to LED's . The output lines NO and COM should be connected to LED's on breadboard right?. Please clarify.

    5 replies

    Reply 2 years ago

    for anyone searching for answer check link in instructables


    Reply 2 years ago

    Do you want a follow?





    Reply 2 years ago

    The LED are connected to the Arduino and are merely indicators, they are not connected to the relay at all. The sketch turns the RELAY1 on and off at the same time that it turns the LED on and off.

    I hope this helps!

    Kind Regards



    Reply 2 years ago

    well ... that's a good question, why doesn't it?


    3 years ago


    nice guide, but maybe you want to add that the jumper must be set to JD-VCC to VCC, or nothing will happen with the relay.

    1 reply

    Reply 2 years ago

    (no offense)

    why are you called 123d4?