hi welcome to a video tutorial from Robojax in this video we are going to see how we can turn
on and off the AC bulb using a sound control with this sound module so you will clap or shout and
the light will be on and then again it will be off as you can see here the light is off now
this light is off and I'm clapping the light is on and another clap the light will be off
same thing I can shout light off light off you can get the code for this project by clicking
on the link of the description which will take you to Robojax.com/learn/Arduino this project
will have two code one would be for the basic one that you turn on and off the light with a
digital and also will provide another code which is advanced and with the analog so the
analog you can turn on and off with the certain specific audio level so not necessarily it could
be a shout it could be a different sound level that you can set and test and turn on and off a
light so let's get started so world of caution that this has involved AC power once you are
connected to AC light for example we news once you connect it to the AV you are not supposed
to touch this once the relay is connected to the power outlet you're not supposed to touch this
and be careful also because the bottom of the relay is metallic and it has contacts make sure
that you put the relay on on an unselected word plastic paper or something like that
so this is the module the sound module we have here for pants here is the data out or digital
out the second pin is a positive which will be connected to five volts and then we have the
ground this will be connected to the ground and the last one is analog out so we are connecting
it to a zero so that could be read as a zero and then this is an op-amp into an op-amp low voltage
or pump that this module is used for majority of the sensors so the main sensing element is
a condenser microphone here so and then we have a potentiometer a multi-turn potentiometers that
you can change the sensitivity of this so the width of this is fifteen point one millimeter
the length of this is thirty six point eight millimeter the depth of the device is thirteen
point one millimeter so let me explain the relay now the relay is five volts so we do
need another external power so it can be powerful with Arduino so we have three connections here so
this is common so you always connect your one of the wires that you connect to AC or DC whatever
heaters light whatever so you connected the light is connected here one of them and the other one
will be either connected here or here depending on the application so this means normally connected
so without any power to this it's always connected if you connect another wire here the so it will be
connected and your device will have power and this is normally open so when you connect the
metal here and the other one is here it will be normally open when the relay energized or
get signal this will connect these two wire we have two LEDs here this red LED is for when it
gets power and then this will activate it when it gets signal so the three inputs or the three
pin for the relay or VCC so this is V see and this is ground so you will connect this to 5 volt and
this is connected to the ground or negative wire and this is input the input is where the signal
comes this is connected to the pin 10 in this application when the signal comes this light
will be on so let me explain the AC bulb here so this is a table light that is connected to the
wall outlet and then the wire goes and will be turned on but I have disconnected one of these
two wires here so let me show you so I've just cut this wire from here now this can be connected to
that relay the relay job is to just connect it so it will be on and disconnected will be off I've
just twisted them and then put some solder so this can be inserted into a connectors with a screw now
I have connected the AC wires between the common and normally open in O so let me explain the
wiring here for the relay this this wire goes to VCC desk to 5 volts of Arduino that goes to the
ground this goes to pin 10 of Arduino this goes here to pin 10 this module on the left side this
goes for the software digital this has not been used I did not use it for analog and then we have
this Plus this wire goes to 5 volts when it stays plus and then we have ground this goes to ground
so now the light is off and here on the screen as you can see it says light off
so let me clap now the light is on and also the textures not the light is on food so you
can use this for some kind of control or maybe by saying light light light
and so forth so your primitives and change the sensitivity until it works for your application
so let me explain now that could we are setting the number two for the valuable sound which will
be used for the pin 2 of digital and then we are setting relay pin another variable equal to 10
so that refers to pin 10 so everywhere we need to and tell me we will use these two values and these
values are not to be changed because these are used to when the light is on it keeps it on when
the light is off it keeps it off so do not touch or play with them if you want the program to work
then inside the setup from here to the to here we said the serial monitor begin with 9600 baud which
refers to this and 9600 is the number that's at the corner here and then we say the sound which
is pin 2 as an input with a pull-up resistor and also we set the relay pin which is 10 as
an output so this will control the relay then we are coming to the loop which is tossed from
there and hand ends here inside the loop we just say digital read pin 2 which is the sound so read
the value and store it in the variable called Val Val is an integer variable that has been defined
here so now this will hold the value of either 1 or 0 or high or low and here we are comparing it
and saying F Val this is equal high and these two ampersand sign means end and light on is equal low
so light on is a value that is set here so 0 means no one means high so these are can be exchanged
equivalently and then we have this one to sort of status 1 minus heard heard is a variable that is
here and then we are waiting hundred millisecond this is a very critical value so initially do not
change it and but later on you have to change it according to your environment or the occurrence
of sound for example if you make this too short at 20 seconds or 30 seconds and you clap it might
not be able to read the club that will be long and this will not be able to read it because 30
millisecond is too fast or if you shout your or the response of the board might be slow so anyway
this is used and then we say value equal light so from here to here is to keep the light on with on
and keep it off when it's off and then this is the main section of the code that controls the relay
so if her is equal equal high this equal equal means equal so if hurt is equal high didn't do
this what is this meanness right on it will print the right on here that text for us and also we say
10 relieved pin which is 10 equal oh no is used because this relay that I'm using is low-level
tracker so with the low it will be triggered so we say that low so if you want to control a motor he
touch door lock whatever you want with a sound so put your cone here the highlighted area else
means if there is no sound then do this so the same way you can control your device by removing
this code and putting yours or maybe just put something extra here underneath or above this so
somewhere in between this closing and opening or between this opening and closing and then again we
have hundred millisecond this start with hundred millisecond and then if you wanted to manipulate
it if it doesn't work maybe change it otherwise it should be fine so the loop continues like that
so the first part of this application is done so you can get the code and it will work fine but if
you want to go and to use the analog and do more control over the value then continue watching and
it will take a while but you will learn a lot of other stuff that you might use in your projects
okay now we are using the advanced mode in this mode we are not using the digital we're using the
analog out which is the last pin here so to set this first the first thing is that you have to
rotate this until you see this clicking you see after that rotated clockwise the way the clock
rotates until it stops so now the light is off the light is on light on light so the value is
set this is the value from the sensor as you can see this light off at the moment and this
is 5:30 so we are at 528 528 is off so I have to increase my voice to make it five thirty
hello hello or maybe I should clap as soon as it's Club the value increases and then the light is on
and here the light was on and the value was about 525 18 520 when I made a clap
the audio the voice become the value become 5 6 45 and the light was off until again this
is 527 526 and then whenever there are another voice or crap so 530 triggered
it so you can select the value here so do not touch it with this 530 it will be fine
but your environment or the room that has different voice level or noise level that
just change it a little up or down and you will find the right value to trigger this
so now I'm gonna show you the advanced code for this light sensor so we are setting the
pin 10 for the relay pin and then 530 for the sound value this is a value that we are setting
to trigger the that light so as you can see here I've frozen the screen 5:26 the light was on all
these values when it becomes 530 some clamp or high or do you level triggered it to go off and
again it's off and off until again from 530 it becomes 531 and the light is on and again it's
from 26 it jumps to 546 when the light goes off so this is a value and then you do not play or
touch this value these are necessary for program to a function for example keeping the right on
turning the right on and keeping it on and turning the light off and keeping it off so
inside the set up we set 9600 baud for the serial monitor to work and then relay for the output and
this is as if I type 10 as an output and then inside the loop from here to the end and here
we first say analog read which leaves analog 0 value and then stores it into Val and then here
we are comparing and doing the comparison this valve which is ripped from the analog 0 if it's
bigger than sound value sound value is a value that you set here which is 530 the sound value
and light on is equal low so this 2 ampersand sign mean and so this must be true and this must
be true so this can happen so these are done from here to here this is to keep the light on
or keep it off the job of that and here is a important part we say I've heard which audio
is heard is equal hi then print the value of the audio which is this one and also print the text
which is just X and then said really low because just relieves low trigger so that really will go
on so if you want to do something else when the audio is heard you can do a hair controller motor
servo close the door whatever you want you can do with this highlighted area and put whatever
else you wish to do if this is false then we say else do this this is the same as above with the
exception that we say pin real a pin high so this will turn off the relay and then we wait
for hundred millisecond and the loop continues this is very important if you put it too short
the same audio or a sound or clap will turn on the light on and turn it off the same time because it
will read for the next one too quick if you put it too too large which will be too slow
then your audio might not be hurt because at that time the system might have been waiting at that
point because if you put the 500 millisecond half a second a clamp cannot be heard so make
sure that you find the right value here thank you for watching please thumb up the video if
you liked it and also subscribe to get updated my upcoming videos and also share it if you
have any question or comment please type it at a comment box I will try my best to answer and reply
you