we're going to see how we can turn on full channel really either an easy or DC bulb by pressing push
button turn on and push it again turn off or any other channel on death hi welcome to our doing a
tutorial from Robo Jack's you can get the code for this by clicking at the link below the video which
will take you to Robojax.com/learn/arduino let's get started with this
in many application you need to control for switches or full load let's say AC or DC with
a push button this is an example and the code that accomplishes that you can press
each switch separately and independently turn on each channel and the channel will stay on
without an interruption when you press the other button so this will be accomplished
and the module that I'm using is a low trigger module with four relay and have driver without
transistor on everything so the circuitry would be very easy I'm just using four channel for
the end control of this and two more wires full wires for this and two words for the
power ground and VCC and then we need just four wires for the push buttons and here I'm using
four push buttons I'm going to explain the wiring after that I'm going to explain the
code and at the end I'm going to demonstrate it in all my videos I'll have a code jump link so
you can go to different section of the video by clicking at the link which is in the description
let me explain the wiring first for the switches I will remove these four wires for the switches
I have put these four push buttons these push buttons have two pin you can get the foreman two
on one fight will be honored to down the other fight so they're the same I'm just pushing it
one in between so between 1 and the third so my push button in here now this push button
is connected in this line and the other pin is connected in this line same way for this one
this line and this line and for the third one same way this line and this line the middle one
is no pin and also the last one I've corrected the left wire the left pin of this to the left
pin of this switch and the left pin of this is connected with via this wire to the left of
this switch and from here it's connected to the left of this and from here I've connected it to
the ground of Arduino now these four wires on the right side I've connected them here
like that and these are from this side they have been connected to pin 2 3 4 5 relay as
you can see here I put here 8 9 10 and 11 and I've connected it from this side this orange is
connected as you can see 2 & 1 and then in 2 & 3 and n 4 and this side this is VCC v ground I
try to put the red for VCC usually that's the convention and the darkest color black for the
ground so VCC 5 voltage connected here to 5 volts and ground is connected to the ground because
this really is 5 volts and the Arduino is able to handle the current for this through 5 volts
that's fine if you release 12 volts you can still use the 12 volts really but make sure instead of
VCC connected to your 12 volt source this is an AC desktop bulb and this is a power plug that I
connected to the wall and 120 volts which will turn on and off now at this point I've cut one
of these two wires at this point and twisted it and saw that it can be connected to relay job of
relay is to connect this and the AC bulb is on or AC load whatever fan you have and disconnected to
turn it off so I will be connecting these two to the relay from here I've connected my two wires
these three pins are for this really one two three and then these three or four this really
so each really has to depends and I'm using the two left side of this pin these two pins
are used for this really if you want to connect the next load connected between these two points
these are called normally open when the relay is energized the two wires well disconnected and the
light will be on if you connected in these two the middle and on the side initially the light
will be on and when they release energized the light will turn off the same way for all of
these and this also has for light I have separate video explaining this so I will post the link for
you can view it I will not I'm not going to go through the other explanation components
and here is a wiring diagram I will provide you this one with the code and the same page
let me explain now that could because we are using four push buttons we need to have four inputs so
I've defined it from Arduino from two to five two three four five four the push button you can
define different pins if you wish and this array is a constant of type integer that's holding these
values so during the execution of the code it will not be changed because it's constant after that we
are defining four pin digital pin as an output so the relays will be connected in here you can
also change it as long as there is no conflict and between them this is that just for cosmetic
purpose like this channel four or something so these are just a text is used to display that the
text here you can change it as long as you keep the quotation whatever you want put inside and do
not use double quotation in your text it will work and then this do not change it this is the status
of each button initially we set them as zero not pushed and then and then the status of each really
because I'm using load trigger relay initially they should be high which means they will be high
off so this is the initial status under the I'm setting inside the set up we have to define an end
put an output as pins so I'm using the for loop because I have to copy this as you can see here
three and times 4 I have to copy this four times instead of that I'm using this loop that goes from
I equals 0 to I smaller than 4 so it goes 0 1 2 3 so it goes 4 times I changes from 0 1 to
3 and every time comes here we pull up from the push button we went at 0 we pull to when I just
know one we pull 3 so the value of F I type here 2 or 3 and then we use input pull up I do not use
just input I use pull up to avoid using of extra resistor I have another video explaining why we
need to use and put pull up with a push button and then also we use for the relay at output so
the push button was as an input and this is now as an output the same way we picked that those
values with this loop and then also we've set all the relay output as high here the reason for that
one is if you release or high trigger put hairs low so they are turned off initially I set them as
high so the release of our off initially when you turn it on after that we'll go inside the loop in
the loop now we have to check all the push button status and again I use another loop here which
starts from here and ends here so this goes up to 4 from 0 to 3 less than 4 which is 4 times and
then this is digital read push button I when I is 0 it goes and falls the death value and I was one
or two it just changes so we get the pin numbers we put it here f fi type digital right - it goes
to pin 2 and reads it and the value is restored and Val as an integer now this value is the status
of the push button and we check it if it is high equal equal high and then relay status is equal
low then we change the status how we do is we say that good that the status subtract from 1 if they
start is zero zero from one if subtract one that the result would be 1 and well 1 will be stored
here if this is 1 1 from minus 1 1 will be 0 and 0 will be stored so this is just read matic to
change the sets of 0 to 1 and 1 to 0 every time the button is pressed when we give it a hundred
millisecond delay for this to happen after that we store the value of the Val whatever was pushed
we keep it as a status array it keeps the value for F and then we check here if the push now we
kept the value now we have to turn the relay on and we checked if the status if pushed is equal
high then we say trend s name this this text is printing this for us the serial monitor and then
digital right really pin this eye that started that is referring to one of the relay and it
will set it low which means we'll turn on the relay otherwise else we print this the word off
instead of on and then instead of low we just put high and relay will be off but remember if you set
this to higher value every time you press a push button it will not react so put a small button
value like hundred millisecond and this way it will react very quickly but this will print very
fast now as you can see when I press it reacts very quick which is good this is what you want
let me now show you the demonstration as you can see the status of relief as shown very quickly
you can slow it down if you wish I said this at hundred milliseconds as you can see all of them
are off and the leaves are off and if I press this this channel 3 is now on as you can see channel
channel 2 is on now channel 4 is on and channel 1 is off at the same time also it shows here if I
press one channel one will be on that because the light is connected here the others channels will
not affect or entrap or do anything I can press on or off any channel or this one on or off and the
others will keep their status if I restart I've said this that no load will be connected initially
so they will be just waiting as you can see all of them are on thanks for watching this was how to
use this for channel relay with four push buttons turn on and turn off if you like this video and
you learn something from it please thumb up please share it on your Facebook and other social media
if you have comment or question posted a comment section below I try to answer reply also don't
forget to hit the subscribe button so you can get updates of my upcoming videos I appreciate it
you