hi welcome to an Arduino step-by-step course by Robojax 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 this lecture we are going to learn how to use this
vibration sensor with Arduino this module sends signal when a vibration happens
not motion for example if you move it like this you will not see anything but if the
vibration happens it sends signal to Arduino and using Arduino we can control a buzzer to
make a sound or maybe control a relay to control alarm light fan or trigger and do something
else this is the vibration sensor module we have three pin here the right one is
vcc then we have ground and the last pin on this side is do digital outdoor data out
we have two LEDs one is for power the other is when it is detected
but the operation of this one is the opposite when it does not detect the light is on when it detects
the light will be off and this is a potentiometer that you can adjust the sensitivity of the module
this is an operational amplifier that amplifies the signal and sends high or low depending on the
condition this is the actual sensor so this is actual sensor when the shake happens it creates uh
contact or communication between the pens and here also we have on this side label vcc ground and do
here is the wiring diagram that I have drawn using first thing this module was not available I’ve
inserted using photoshop from the right vcc I’ve been connected using the white wires to 5 volts
the middle pin ground using a grey wire have been connected to the ground and the data out have been
connected using a purple wire to pin two I’ve connected my buzzer to pin it you can connect
anything else you want for example everyday that can turn on or control something else for you
and here is a wiring or actual device from the right vcc have been connected using this white
wire to pin five volts the middle pin I’ve been connected using grey wire to the ground
and the last pin which is d o or the data out or digital out using a
purple wire have been connected to pin two and for the buzzer that I’ve used here
pin eight have been connected to one point and from the ground of this Arduino from this point
I’ve brought it to these two points and the buzzer has two pens the longer pin is positive
this will be connected to the pin that is connected to pin eight
let me now explain the code we are defining pin 2 as a vibration n pin so this is a pin where
the vibration pin will be connected as an input to Arduino and we are defining a pin for relay
in this case I’m going to test with buzzer to just make sound but you can connect a relay as well
pin 8 has been defined for that purpose and on time is the amount of time that
after detecting the uh vibration it stays on so you can play with this
and off time is the time that it waits until it goes for the next iteration of checking
inside the setup we defined the serial monitor as usual with 9600 watt so you can read the data
on the screen and using pin mode vibration in pin we are defining as an input that's pin two this
is as if we type here two as an input and relay pin as an output this is as if we type eight here
and this is just a text for our uh on information all this code inside the setup will run once
inside the loop which runs continuously we read the vibration in pin using digital read
so this will read the result of the pin either high or low compare it to see if
it is high these two equal sign means compare and if that is true if this statement is true
because we have f three lines are action lines that is taken when the vibration is
detected so it's up to you to use it for your own application and in my case I’m turning on a relay
pin high so this is as if I type 8 high and then we wait for this on time that we
define above if this is not true which means if the vibration has not happened we use else and
we take this three line action first we turn the relay low in my case the buzzer will be
turned off or the relay will be turned off and then also we print this text on the screen piece
and we wait for this off time which is 200 millisecond or less or more whatever you
like you can change it and we will wait and the loop will continue taking this action again
and here is the demonstration as you can see here it shows p so it's quiet and the device is running
this light is the opposite unfortunately they designed it such that when there is no vibration
it is on and when vibration happens it goes off but other than that everything works fine as you
can see this shows peace and we don't hear any as soon as it is shaken it turns also shaken and you
can see that the device the alarm goes on but if for example you want to change this to something
uh longer for example this on time every time the shape the shake happens you want to stay
on for a long time changes let's say for two seconds and off
for whatever short period let me update it now if vibration happens it stays on for three seconds
and you can control the time easily to whatever time you want and the time off it will be
quickly ready back but if you keep this off for longer period it also can stay off and ignore
the upcoming next vibration so play with this until it works for your specific application
the sensitivity of this device can be adjusted using this potentiometer
so it has not detected anything and with this one you can set the sensitivity even now it's shaken
I can go to the right
or maybe good to the left
so I just go at the edge where it goes off and it goes on
so this is now the most sensitive and if you want it less sensitive when the light goes on goes go
a little more further to the right this way the sensitivity will be decreased this was how to
use the vibration sensor with Arduino thank you for watching please make sure to subscribe by
clicking at the subscribe button in here thank you thank you for watching if you learned something
and found this useful please thumb up as this will help my video in the search algorithm of YouTube
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