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 is the HC-SR501 motion sensors module for Arduino one of the famous one
it can just detect the presence of an emotion in a certain distance
and it can work at it can detect the motion of an object within up to seven meters uh on the
left side we have ground and then this is the output and on the right side this is a power
which can be connected to five volts and here we have two potentiometers that can be adjusted
on this side this is a time adjust delay when the motion is detected for how long
you want the output to be high and this is the sensitivity how sensitive it should be
to the motion in order to activate also here we have a jumper that can be set
removed and these two can be connected if this is connected on this side it will be single trigger
which means once a motion is detected until the output which is set by this delay timer is not
off the next motion will not trigger it and it stays on and it has to wait for the time to expire
if you put it on this side for multiple trigger and if this is said let's say for 10 seconds
once the motion is detected the 10 seconds starts as another motion detected again the 10 seconds
becomes zero I start again from 10 and the countdown goes so this is for repeated and on
this side is for single motion actually this is just for reflection of passive infrared
the actual sensor is this one the actual chip that is used inside the module this chip is
lhi 778 or lhi878 and these are different model pyd1388 these are the actual chip and the module
is hcs r 501 and all of these can work with 2 to 12 volts but we have a regulator here that
it makes it 3.3 volts when you connect it to 5 volts it converts it to 3.3 volts when you're
connected to any voltage even up to 20 volts you will always get 3.3 volts this way it can work
with all voltages there is a diode here to protect this module in case if you connect it in reverse
the anode is on this side and you must connect always a positive here if you
connect it in reverse nothing will happen the device will be protected and it will not operate
this just makes the reflection from different angle to work yes if you forgot the pen connection
from this side also it has been labeled as vcc ground and the middle one is the output
here is the wiring diagram
and the right pen have been connected to five volts of Arduino the left pen the far left has
been connected to the ground the middle pin which is the output signal have been connected
to pin two to control a buzzer or an led pin eight have been connected to anode of led and from the
cathode we have one kilo ohm resistor which is connected to the ground and here is the wiring
on the Arduino the white pen from the right have been connected to five volts the last fan which is
ground have been connected to the ground and the middle pin black have been connected to pin 2.
from pen 8 this red wire is here to this led the long pin on this side is anode
connected to this red wire and then from the cathode one kilo resistor goes to this pin
and blue comes to the ground if you want to use this buzzer the long pin is the positive
this works directly with five volts so you can connect it on your breadboard directly
now let me explain the code this sensor doesn't need any library we are defining PIR pen passive
infrared pen that is coming from the sensor as pin 2 and also we are defining pin 8 for
alarm in case if you want to turn on led relay or something inside the setup we initialize the
serial monitor with 9600 baht and then we use pen mode pin 2 as input and also pen mode alarm pin
this is an 8 that was pin 2 pin as an output this is as if I type 8 and as if I type 2 here
and inside the loop we use digital read PIR pin and we are reading the signal pin and
the result of this which will be either high or low high means one and low means
zero will be stored as a number as an integer into this variable called motion of type integer
then we check this if I if motion is equal equal this is for comparison purpose if
it is high or if it is one then we take this action we do these two thing you can do whatever
else you want or remove this but the action takes place in here and here our action is to print this
text on the screen motion detected and also we use digital right alarm pen we send pen 8 hi this is
a pin that you can turn on a buzzer an alarm or something else this else mean if this is not true
which means it's low then from here to here this action will take place and in this case we
just print this nothing moves and also we send the signal of low to pin 8 using digital write
then we wait 500 millisecond or half a second and the loop continues like this
now as you can see it shows motion detected when I move my hand and this is the sensor
it says nothing moves and when I my hand moves it because of the delay it just turns off very
quickly if I move my hand again the motion is detected now the light is also shown there
this is the delay timer this is the delay timer every time it detects how long it stays is
one two
almost five seconds currently it's set at five seconds if you want to increase it let me just
increase it a little to the right
now let's move
one
if you put it at the lowest minimum fully on two seconds so if I adjust it clockwise
move it a little and on this side this is the sensitivity
and I set this and it become more sensitive or less sensitive for example
maybe a cat could trigger this or maybe if you reduce the sensitivity even unless there is human
large body nothing else will trigger this so you have to play and see in your own application
at what setting it works best I’m currently putting it at the middle now I have connected
the buzzer instead of led and if something moves this is five volts directly connected
this is how to use this PIR
501 motion sensor thanks for your attention please make sure to subscribe by clicking at
the subscribe button in here thank you thank you for watching tutorial from Robojax 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 you