Introduction: CONNECT 16384 RELAYS TO a SINGLE ARDUINO and Infinite Other Possibilities

Can you connect 16384 Relays to a single Arduino uno ?

IMPOSSIBLE? POSSIBLE?

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.

Step 2: WORKING OF 5V RELAY WITH OPTOCOUPLER

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 .

IT IS VERY SIMPLE!!

HOW?

U KNOW IT !

USE AND GATE AND OR GATES !

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

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

TRUTH TABLE FOR OR GATE

PIN 0 PIN 1 OUTPUT

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!

RELAY 1

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)

RELAY 2


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)


RELAY 3

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.

RELAY 4

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.

LOGIC TABLE

FOR 4 INPUT 16 OUTPUTS CAN BE MADE.

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.

A B C D_________REPRESENTATION

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. *****

Step 4: INFINATE APPLICATIONS

  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.

etc.

etc.

etc.

A sample program is given below.

void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
//type your code here
void loop() {
/*if(condition)
{digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
elseif(condition)
{
digitalWrite(0,LOW);
digitalWrite(1,HIGH); 
}
elseif(condition)
{
digitalWrite(0,HIGH); 
digitalWrite(1,LOW); 
}
elseif(condition)
{digitalWrite(0,HIGH); 
digitalWrite(1,HIGH); 
}
*/

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.

Thanks!