hi welcome to an Arduino step-by-step course by Robojax
hi in this lecture we are going to learn how we can control two channel solid state relay
to control two ac bulb or two ac loads like this I’m connecting only one using two push
buttons independently when you push the light is on and it stays on and push off it will off and
the same way for the other one as you can see this is turned on and off let's get started with this
many times you need to control two ac bulb or ac load like this and using solid state relay this
module is sold on eb and AliExpress I will provide you the link yeah this is very versatile and
easy to use we have two solid states relay by Omron and this is one of the best brand in the
market this is made in Japan and this can handle up to two amperes each can handle two amperes
here we're going to use these two push buttons to control them I’ve seen people have requested this
a lot because when you push the button it will be on and release it will turn off but in this
case I have written this code so when you push it stays on and it says oh for example now channel
one is off when I press it is on and it stays on even my finger is removed both of them are now
on I can independently turn them on and off so this will be very useful for my application
let me now explain the hardware so this is really has three advantages the first one is because it
is solidified and there is no mechanical movement this can last very long with comparing to
mechanical or magnetic relay the second advantage is it can connect and disconnect very fast
sometimes in application you need to connect ac load or ac bulb using Arduino very fast
this can do it and the third one is because it's solid state and there is no mechanical
movement the life expectancy of this one is much longer than the mechanical relay this uh solid
state release for each we have two terminal here that you can connect your load and for this one
we have two other terminals for this that you can connect your load this side we have four terminals
this is dc plus they've written it this is vcc or will be connected to five volts of Arduino
this minus is connected to the ground of Arduino and then we have channel one channel two channel
one will control solid state relay number one and channel two will control solid state number two
these two are connected to Arduino pin this will be connected to pin two and pin three which are
going to show you next these solution release are offered in two types of trigger here it says
high trigger which means at the input we will receive 5 volts or higher voltage higher than
2.5 to turn this on and if you get a low trigger then with the 0 volts or less than 2 volts it
will be turned on in any voltage above 2.5 volts which will be considered as high will turn it off
but this one can be turned on with high voltage or 5 volts and turn off with zero voltage
here we have also a diode that if you connect the polarity incorrectly this protects the
device also we have two LEDs when this is turned on the led will be turned on
indicating which channel is on or which channel is off
the width of the module is 33 millimeter length is 55.2 millimeters the depth is 24.7 millimeters
this is an ac desktop bulb and this is a power plug that I connected to the wall 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 soldered 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 disconnect it to turn it off so I will be connecting these two
to the relay this is the wiring diagram for the two-channel solid state relay
with push button let me start with the push buttons I’ve used a breadboard the red side is
on this side and the blue is up from the blue side acquire is brought to the ground of Arduino
and I’ve inserted two push button the push buttons has two ways one side is one connector the other
side is the other connector if it doesn't work for you rotate it 90 degrees this side is connected to
the ground and the other is also connected to the ground both of these are connected to the ground
and this is push button one this is connected using a white wire to pin two and this is push
button two connected using a gray wire to pin three so this will control solid state relay one
and this one will control the solid state really two which will control the bulb number two
on the module this is the plus dc this will be connected to 5 volts using a red wire
this is a ground or minus dc dc minus this is connected using
a yellow wire to the ground this is channel 1 using blue wire have been connected to pin 8
and channel 2 is connected using a purple wire 2.9 the two bulbs I have shown you how to connect a
bulb the two wire that we said you cut will be connected in here and for the channel one will
be connected at these two terminals there are two types of push buttons I’m using this one because
it has longer leg for breadboard but if you're getting this type of push button just press it
with your plier the legs will be longer and it will be inserted easily in breadboard
here one is inserted if you're using this type also it can be inserted
use a screwdriver to guide the pins
and it has been inserted easily but the other one has a longer leg
and to explain the wiring this side is connected using a gray wire to this blue line
and the other one also the same have connected to that line and this is connected using this
to the ground of Arduino this side of the switch this is connected to pin
two this is push button one and this from this side of this is connected to pin three this is
push button two you can use also this type of push button doesn't matter connect this to the
breadboard and here from the solid state the first wire the red is connected to five volts
the second pin is the negative it's connected to the ground
and this is channel one that's channel two blue is channel one
and both of these are connected to pin eight and nine
blue is eight and the purple is nine for the push button
white which is push button one is connected to pin two
and grave pin three this is the ground ground is connected on the second ground of Arduino
and as I’ve shown you the two wires that you cut for your bulb will be connected to this
terminal that is the channel one the second bulb will be connected to these two terminals
word of warning it will be very dangerous once you connect this to the power to touch this area
and do not put this on a surface that is metallic or a conductive
if you found this tutorial helpful please thumb up and also click on the
subscribe on the right side in the lower corner I really appreciate it
let me now explain the code we have defined a an integer called push button 1 and push button 2
as constant so they cannot be changed during the execution of code I have used pin2 for channel 1
push button 1 and pin 3 for push button 2 push button one will be connected
to pin two push button two will be connected to pin three of Arduino
then we have defined solid state relay one pin solid this is really two pin SSR one SSR two
and I’m using pin eight and nine if you're using dual spin for other purpose you can change them
then the trigger type high this module that I’m using is high if yours is low just type low and
this will take care of uh turning it on and off accordingly this this value is pushed 1 push 2
is used internally within the code do not change it this is just storing the status of a button
and SSR 1 starts as high ssr2 status high please also do not change this
then SSR on SSR off are two variables that are used to control the relay and we are defining
on and off based on the type of trigger which will be used internally inside the setup we are
defining the serial monitor so this can print this text for us with 9600 is bought per second or bot
is the value that is on the right lower corner here this must match otherwise you will not be
able to read this data using pinmode push button one this is the push button that we have defined
we are defining push button one I’ve defined it as an input and also I use underscore pull up
using this you are eliminating using of extra resistor which I have another video the link
will be provided if you want to learn about it and this also for push button 2 and then after that we
define pinssr pin 1 and pin 2 as an output these will be connected to the SSR inputs and
then here we check if the trigger type is high then we define what is the meaning of on mean
high and off mean low if the trigger type is low then it will be the opposite on is low and off is
high then throughout the code I will be using this instead of these and it's automatically on means
regardless of the type it will work for us after that is defined then we go and set the initial
status of the pinssr pinand we set it as off and this is our pin two also we set it as off so the
two relay will be initially off in case for any reason you need this the opposite just change this
with this variable SSR on and when you turn the device on initially it will be on inside the loop
we read the push button using digital read push button 1 and also push button 2 the value which
we read is stored in this variable called val 1 val 2 which means value 1 value 2.
once we read that then we check if val 1 is equal this to equal sign means compare this
to the value of high and SSR status is low if it is low then what we do is we get the value
of pushed remember we have defined here pushed one pushed two this is the status
we change the status how we change this this line is just arithmetic to change the push either if it
is high make it low if it is low make it high how it does is if this is one and we have one
minus one one minus one becomes zero so this will be zero if it is 0 then this is the same variable
this is the same as this variable if this is 0 then 1 minus 0 will be 1 so this will
be changed to 1. and this was for push button one and here we do the same thing for push button two
ssr2 status and we check it so this line the job of this one is to change this when we pushed it
and then we store the value of one at the SSR one state this will memorize that if
the SSR is on or off we just store it here and the forests r2 will be stored in ssr2 status
and that and then we check if pushed is equal high then we print this which will print this on for us
and then digital right SSR one pin SSR on the job of this one is to turn the SSR on if that
is not true then we turn it off that this is for SSR 1 and we do the same thing for ssr2
the relay will be turned on if it is pressed if it is not it will be off
and then we print this to tell us that the loop is done this is printing in here
and we wait hundred millisecond and the loop continuously doing the same thing
and here is a demonstration serial monitor continuously monitors the status of the
push buttons as you can see it shows ssr1 is off and ssr2 is off and now when I press this button
also the light of channel one that is channel one which is connected to this bulb and channel two
is not connected to anything but you will be able to see the led or light on this is push button one
and that is push button to push button one with control channel one and push button
two will control channel two when I press it as you can see this is on and that led is also on
this kind of stay and I can press the push button too and the second sort of stage
release on if the load was here that will be on and independently I can turn off and turn on
this will not affect the other one and also when I press it it shows the two of them are on
one is off it shows continuously
if you don't need this serial monitor helps before you even connect this you can check your work in
here this was how to control two channel of solid state relay with two push buttons to control to ac
bulb or ac load thanks for watching please make sure to subscribe by clicking at the subscribe
button in here thank you if you have comment or question please post it at the comment section
below I try to answer and reply and don't forget subscribe so you get updates on my upcoming videos