Hi, welcome to another video tutorial from Robojax.In this video we are going to
see how we can control each individual relay on the 16 channel relay module
using Arduino Uno/ you can get the code for this project by clicking at the link
at the description which is below the video which will take you to
robojax.com/learn/arduino let's get started with this
My Name is Ahmad Shamshiri and I am presenting this tutorial from Canada.
this is a 16 channel relay module that you can control independently 16 AC or
DC load and depending on your region if you are connecting or
controlling AC load it could be 2.2 kilowatt or 1.1 kilowatt using each relay.
This is optically isolated so your input from Arduino will
be completely isolated it has it has separate input and this can be used to
control different devices such as fan heater or whatever application that you have and I've
written a code for this so controlling of this will be very easy
Hardware Explained
let me now explain the module. This is LOW triggered relay, it means that all these
relays will be controlled if it receives LOW signal or zero volts at these pin
the pins here labeled on this side these two pins are five volts which are
coming from this voltage regulator these pins from one to sixteen or accordingly
one two three four and so so these are all odd and these are even numbers and
then we have two grounded this ground pin must be connected to Arduino. and you
will provide external power supply the ground is on this side the positive is
on this side because each relay at 5 volts will draw about 80 milliampere (80mA or 0.08A) so
this will be a lot of current make sure that when you connect external power
supply it can handle at least 1.5A for this system. the device has
this LM2596 3 ampere (step down) converters this is a module pin 2 is an output, pin one
is the input this is the regulator
8 of relays will be driven by this chip and the other eight will be driven by
this chip and the chip is ULN2803 the this is a Darlington transistor arrayed
which can work up to 50 volts 500 milliampere each of those and as you
can see here we have input and output eight input and 8 outputs they all have
diodes to protect it against kickback voltage from the relay and this is the
chip 1 2 3 4 all of this as input and that's the output and this is a ground
this is a common as shown here and all the inputs of this 8 input have been
isolated from the input by these optocoupler
chips here. Optocouplers use here is PC817C, the C version.
and here is the chip and here here are the pin connections so one and
two, 1 and 2 , this is the input and this side is the ground
and this is the output as you can see the four and three
these are isolating it in case if the voltage that you are supplying for this
has some interference or something so isolation removes noise and also in
terms of safety so that's a better practice and also the eight optocoupler
are here for this chip so the relays have been labeled as contact 1 or k1
K2, K3, K4 up to K8 and then we have 9 here up to 16 and each has
its own LED to show their status if it's ON or OFF. and the contact of relay
or 3 so this really has three contacts here and these 2 are normally closed (NC) and
if you want the relate to turn on and disconnect a load so you will connect it
to normally closed but usually you will have a normally open (NO) so you will connect
two wires in here and here when this really is energized the contact will
establish and switch your load and this light will also turn on. the length of
module is 177mm by 80mm the
height is 19 mm but this capacitor at the end is very long and
the height is 22.4 millimeters because of this capacitor.
weight of the module is 216 grams
How much load to connect?
when you're connecting a load into this relay pay attention to the current if
you are connecting a DC load 28 or 30 volts the maximum current is 10 ampere so the amount of
power just multiplied 10. 10 x 30 and it will be 300 watt. if you're connecting at
30 volts and 208 watts t if you're connecting it to a 28 volts. but in the
region in North America 125 volts times 10 if 1250 or 1.25 kilowatt load can be
controlled with one day really but if you're living in a region with a 220
volts like Europe and Asia then you will have 220 volts or 240 x 10 so it's 220
volts it will be 2200 watts or 2.2 kilowatt for per relay. and if you
overload this the contacts will melt and there is a hazard of fire so be careful
not to overload this.
Relay voltage explained
now let me show you a problem with this module with a voltage there is a voltage
regulator and I have connected this module to external power supply and let's say the
input voltage as you can see has 5 volts so I'm reading the input voltage 5 volts
on my multimeter and voltage on the relay is of course the same now let me
increase the voltage now it's around 8.72 volts. The related
voltage is 5 volts as you can see so the current is on this side the voltage from
voltage regulator comes to this and each layers driven by their so eight of
them by this and eight of if it really will be driven by this now if I check
this this chip is receiving 8.7 volts so exact same voltage is
coming here and then this will supply the voltage to the relay if I check the
voltage across the two pin of the relay you will see that we are reading 7.75V
volts the other relay is off and we are not reading any
voltage only this one is ON when that light is on and also here
that's a voltage including the resistor and it is 7.78 volts
and that is concerning this is a very very bad design that allows the whole
voltage to come here this should have been regulated voltage of 5 volts. I have
a separate video fixing the issue (the link is below this video) on this module so these relays will
receive exactly 5 volts regardless of the input so you can connect even up to
40 volts at the input and you get 5 volts regulated because the video will
be very long I will create separate video to resolve that issue the link
is be provided under this video in the description below
Code explained
let me explain the code now. This code works and this module can be used with
Arduino UNO and Arduino Mega or the the Nano and Mini will not have
enough pin so that this will not work. (I have new video where it will work with 4 pins) but even with all the we know you know
we can use the trick that analog pins can be used undefined us and digital
output so that's why I've defined it from pin 2 to 12 and then I have left 13
and then from A0 to A4 and I call them a controlPin with 16 element array
this is an array that I define all depends if you want to change it you're
welcome but you have to have 16 elements here otherwise you will get an error if
you have lower number of elays just if you have it you can use the same code I
just defined it here but you have to change some other values this is a type
of relate trigger if your relay's trigger is LOW is low like mine just type here
LOW otherwise type HIGH and everything will be taken care of and this is the
loop delay that when I was testing the module with the loop and the state this
is used internally do not changes to change this , this any of this
code will work. inside the setup() we run a for-loop 16 times from 0 to
15 and here we define all the pins as an output and also we check we take care of
that trigger as well just work and keep the relay off in both case initially
then this is initializing the serial monitor in 9600 baud and that is the
value that will be displayed here this number must match 9600 baud inside the
loop() this is just a loop for to test that relay and I'm running for() loop
from 0 to 16 this is just going and checking this "i", "i" become 0 to see
since 0 1 2 3 up to 16 so we say channel while that the channel and that's the
temporary so that initially it's off and then for 500 millisecond and then the
delay after that I want also to wait for this many times beside this and here we
check if the status is ON make it OFF, if it's off make it ON. this
is just for the loop I'm sure you will not need this and this is just for test
of the module but the main code is here we print this once when loop runs and
here if you want to control channel 6 and turn it on for 2 seconds this is how
you do this 6 mean channel 6 and the 6 min channel 7 really seven and one mean
on and then 2 seconds and if you want to do channel 7 turn it off for 3 seconds
do it this way and the loop continues like that so this function that I have
written the channelControl is here below this and when you pass this 6, 0 and
and 3000, the first parameter second and third so those arguments that you
pass for the first one becomes relayChannel, the second one is the action
that last one is a time or T and here we are taking care of all these values and
we say if the trigger is LOW do this and if the trigger is high so this does
self-explanatory because you will not need to change this in order to for the
relay to function whatever you want to do you you will do it here
Wiring Explained
let me explain now the wiring. I have connected these two pins to external five
volts the positive is on this side VCC and a ground is there on these pins
the last one is ground as ground is connected with separate wire that you
can see here I've connected it to the ground and the rest are from the VCC is
left I do not touch it and I do need to touch that but if you want to power up
your Arduino from this power that is a very good practice from five just
take a wire and connect it to this VIN to of Arduino and your Arduino will power up
pin one and two three four up to sixteen I brought them accordingly
here so the pin one this module the channel 0 or channel 1 channel 1 is
connected to 2 and accordingly up to pin twelve after pen 12. After pin 12 I have come here to
this side so after 12 this is A0, A1, A2, A3 and A4
Demonstration
Now let's see the demonstration of this that each channel will run and also we
will see on the serial monitor that it prints the values. currently the program
is running but I've not connected it the power so I'm connecting the power as you
can see it goes on and then as it goes off also prints it. Now the time that
they're set is hundred millisecond if I change it to 1000 milliseconds
you'll see that it goes one by one I've channel 10 is on 11, 12 it goes to 15
because I've thought from 0 now to control it further because this is the
loop for testing all the release so the for loop that I've written inside the
main loop just comment this section(put // before each line) and here you just use this one if you. for
example if you want to control channel 6 turn it on for 2,000 millisecond just
type it like that. and after that then we say turn it off for three seconds to
keep it off for 3 second and run it for that amount of time now it shows that
channel ON and that time off for that time and the loop continues. so this line
shows the status of a channel and also it shows the time. at the time and just
leave it forever on just set this to zero and also if let's say you want to
control a channel based on some action temperature pressure some other value so
you can set it like if( and let's say you have that temperature T Celsius it's
greater than it is 87 degrees and you want they say the temperature increase and
you won't turn on a heater to turn on channel 4 turn it on forever until you
do some action. thanks for watching before how to use this 16 channel relay
with Arduino Uno an Arduino mega if you like this video please thumb up 👍 and also
subscribe so you can get updates of my upcoming videos
I have created video fixing the voltage issue. The link is now on the screen on the left top icon.