Can you connect 16384 Relays to a single Arduino uno ?


Step 1: HOW TO DO THAT? (introduction)

Theoretically it is very easy to do. Can you believe it?

In an Arduino uno there are 14 Digital I/O Pins (of which 6 provide PWM output) and 6 Analog Pins.

That is total 20 pins. We can use this 14 Digital pins for I/O operations. Thus we can make use of this 14 pins to control our Relays.

I know that you are Confused , but don't worry its logic is very simple. Before coming to that lets see how a relay work.


Why I am suggesting optocoupler relay is that , it will isolate our arduino from high reverse flow of current from the relay when we connect to high current /Ac devices .

Multi Chanel 5V optocoupler relays are available in the market ,for example : 2 Channel 5V optocoupler relay ,3 Channel 5V optocoupler relay , 4 Channel 5V optocoupler relay etc..

  • If we are using multi channel optocoupler relay we have Vcc , GND ,IN1,IN2 etc.. also NC(Normally Closed) ,Common , NO(Normally Opened) .
  • It also have JD-Vcc,Vcc, GND pin adjacent to GND ,IN1,IN2 ,Vcc pins which you don't need to worry now .
  • There is a jumper connection from JD-Vcc to Vcc , you don't need to remove it.
  • But you should not connect Vcc to Gnd using jumper , that's the only thing you need to consider .

I'm using 5V relay because it can be controlled by arduino since the output of Arduino is also give 5 V .

How to connect a device to relay?

The default state of the relay when the power is off is Common pin is conncted to be connected to NC (normally closed) pin.

This is the equivalent to setting the Relay boards IN pin to HIGH (has +5v sent to it) .

But we do not use the NC connector in-case you Arduino looses power it will automatically turns off all the devices connected to the relay.

When you have something connected to the relays NO (Normally Open) connector and you set the corresponding IN pin to LOW (0v), power will flow in from the COMM connector and out of the NO connector powering your device.

In other worlds , if we want to turn ON a device , we need to connect Vcc, GND to the corresponding Vcc and GNDpins of Arduino and IN pins to any of the I/O pins , and Common to the power supply that is required to turn on the load.

If the IN pin is at low state the device will automatically turn ON.

Step 3: How to Connect 16384 Relays ?

Before coming to that I will tell you how to connect 4 relay from 2 , I/O pins .





LET the two pins be , PIN 1 and PIN 2 ,

PIN 0 and PIN 1 is first connected to and gate ,



0 0 0

0 1 1

1 0 1

1 1 0

Simple logic isn't it ? But how to implement it ? It is also easy!


Vcc to 5v of Arduino and Vcc of OR Gate

GND to Gnd of Arduino and Gnd/Vss of OR Gate

IN1 to "OR Gate output"

Connect Pin 0 to one of the "OR" gate input Pin 1 to the Second input , the output will be "one" if one of the input is "One" . So if we give PIN 0 and PIN 1 output to logic zero output will be Zero . So If we connect that output to IN1 its value will be zero and Common pin will connected to NO pin and load will be turned ON.

This will work only when both PIN 0 and PIN 1 equal to Logic 0.

i.e output = (PIN0) OR( PIN1)


Vcc to 5v of Arduino and Vcc of OR Gate
GND to Gnd of Arduino and Gnd/Vss of OR Gate

IN2 to "OR Gate output"

You can do that just try!

What we need is output need to be zero (Then only Comm will connect to NO) only when PIN 0 zero and PIN 1 equal to one .

Just see my logic .

Connect PIN 0 to one input of ENOR/XNOR gate PIN 1 to other input. The output will be zero if any of the input is 1. Then connect that output to one input of "OR" Gate and PIN 0 to the other pin of "OR"Gate .The output will be zero only if both the the input is zero.

i.e. ( PIN0 (xnor) PIN1 )or (PIN 0)


Its same as above method . Just a difference is that after XNORing we have to and will PIN1 only not PIN0

i.e. ( PIN0 (xnor) PIN1 )or (PIN 1)

So If we connect that output to IN3 its value will be zero and Common pin will connected to NO pin and load will be turned ON.


You can try that right?

i.e Output will be zero only if both the input is one .

what's the logic ? Its NAND gate .Right?

output = (PIN0) ANAD( PIN1)

So If we connect that output to IN4 its value will be zero and Common pin will connected to NO pin and load will be turned ON.



LET " + " represent OR GATE and " ' " represent NOT GATE.

Inputs be A ,B,C and D . We need to get Output as Zero (Then only Comm pin of relay will connect to NO pin ) only in each of the logic values (input condition ) for A,B,C and D . It is represented in the REPRESENTATION column of the Table (after "___________ " )given below.


0 0 0 0 ___________A+B+C+D

0 0 0 1 ___________A+B+C+D'

0 0 1 0 ___________A+B+C'+D

0 0 1 1 ___________A+B+C'+D'

0 1 0 0 ___________A+B'+C+D

0 1 0 1 ___________A+B'+C+D'

0 1 1 0 ___________A+B'+C'+D

0 1 1 1 ___________A+B'+C'+D'

1 0 0 0 ___________A'+B+C+D

1 0 0 0 ___________A'+B+C+D

1 0 0 1___________A'+B+C+D'

1 0 1 0___________A'+B+C'+D

1 0 1 1___________A'+B+C'+D'

1 1 0 0 ___________A'+B'+C+D

1 1 0 1___________A'+B'+C+D'

1 1 1 0 ___________A'+B'+C'+D

1 1 1 1 ___________A'+B'+C'+D'

1 0 0 0___________A'+B+C+D

In this way we can connect 14 input thus make 16384 combinations.

That is , two input will give 4 output , 3 input will give 8 output

Then 20 input will give 2^14 = 16384 output (we can make use of 14 Digital I/O pins)

Now you know the trick!

If it is complected See another method !

Instead of using logic gates we can use decoders i.e 2 to 4 decoder (eg. 74139 ), 4 to 16 (eg . 74HC/HCT4514) decoder etc. can be used .The output is zero for each of the condition in the first type of demux ,. i.e. 2 to 4 Demux , if we use 74139 .Then we can directly connect its output to input (IN pin) of relay . Only one thing need to remember is that the output is 1 in the case of 4 to 16 decoder if we use 74HC/HCT4514 then we need to add note gate to the output if we need the relay to work. Each of the output can then be connected to each of the relays.

You can do it in your own logic and you can choose your own IC.

******* One thing need to be considered ! If you need to connect a large number of relays using this logic , you need to give a separate power supply to ICs rather than the power form the micro controller(here. Arduino) Other wise any of the relay would not work due to the lack of proper amount of current. *****


  1. You can control more relay from minimum number of pins .You just need to use the conditions.
  2. You can connect Relay and LED from same PIn using conditions in programming Logic Gates in wiring .
  3. You can connect keypad and LCD together in same PIN using conditions in programming Logic Gates in wiring
  4. It can be used in Home automation where a single arduino can be used to control multiple devices.




A sample program is given below.

void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
//type your code here
void loop() {

Step 5: Now Tell Me How This Logic Helped You in Your Project

Tell me your applications and suggestions.!

This has infinite applications try to make use of this logic if you don't have sufficient number of pins on Arduino.

If we make use of 6 Analog pin too then it will be 2^20 = 1048576 different possibilities.


<p>@Michael,</p><p>Thanks for the comment! There are only 14 digital pins which will give 16384 outputs.You are right decoder ICs are available today.I will add that to the instructables. I just started with simple connection . When the connection is complex we can use that type of decoders. My aim was to give another method for expanding the pins of micro-controllers , I haven't seen such methods for this purpose in my life. I also like to mention the fact that we know different methods and technologies , but we are not trying to think in a different way that will bring a great difference by a simple method. I mean the next generation generation will not try to know the base , because of the fact that more advanced technologies are available to them . May be simple base knowledge / technology added to the advanced system that will make more advanced system/technology , like my instructables.</p>
<p>I don't really see this as a practical solution to this problem. Using a line decoder for this would only allow you to energize a single device at a time, leaving your other arbitrary N-1 devices useless. I also don't see how 16 inputs pins will give you 16384 outputs, it should be 65536. I can understand that using discrete logic chips can be useful for describing this, but I think you should make mention that single chips exist for the purpose of line decoders already; to name a couple off the top of my head within the 7400 family would be 74138 and 74154 for 3-to-8 and 4-to-16 decoders in single chips. If I were to do something like this, an arbitrarily large number of IO from an Arduino (or any digital controller for that matter), I would probably use IO extenders. These would allow for large amounts of extended IO with a simple interface in the controller and allow for individual control of each line. An example of this would be a max7317 (https://www.maximintegrated.com/en/products/interface/controllers-expanders/MAX7317.html) (note, I have no affiliation with maxim, this is just the first item up in a google search). With this, you can daisy chain many of these onto a single SPI bus (as shown in the datasheet), and you can modularize your relay boards to have an up stream and down stream SPI interface with a few relays. This way you can control each relay individually in a fashion that can dynamically grow with the scope of your project.</p>
<p>That right, you would need to have to have a flip-flop or so to latch the state at each end point if using the fan-out approach.</p>
<p>That's going to be a *really* big and expensive fan-out board (more likely a great big stack of boards)! Perhaps better to use a cheap micro-controller PCB at each relay or relay cluster with a cheap RS-485 interface (MAX485/487 or so) on it. Add an RS-485 interface to the arduino. Now you can assign as much address space (32-bit for 4 billion if you want that crazy) as you want, while only using 3 lines on the arduino (TX/RX/DIR). Of course, every hundred node or so, you would want to insert an RS-485 signal re-generator (2 x RS-485 driver back-to-back) . The added advantage is that the nodes can be up to several Km apart, as opposed to the PCB idea where everything needs to be in the same area.</p>
<p>I have said in the Introduction that &quot; Theoretically it is very easy to do &quot; . But practically we need to design a PCB if you want to connect 16384 relays together . I only consider relay as an example , there are so many other applications you can do with this logic and this logic can be used for other micro-controllers like PIC , ARM etc. I have included a table , it represent 4 input and 16 output , you can use this logic to connect 16384 relays together.&amp; Thanks for the comment</p>
<p>I wanted to see a picture of 16384 relays connected to one arduino, but it is not there :(</p>
<p>Great work! Its an amazing Idea!</p>

About This Instructable




More by NIKHILP3:Connect Relays Than the Pins Available in Arduino CONNECT  16384  RELAYS TO A SINGLE ARDUINO and Infinite other possibilities ATMOSPHERIC OXYGEN  AND  ITS INFLUENCE (Survive the Future) 
Add instructable to: