Motion Detection with Arduino!

LeMaster Tech
182 followers
1 Video View·Apr 20, 2025
Motion Detection is a super cool and useful tool to be able to do wit arduino, raspberry pi or any other microcontroller and using the PIR Infrared HC-SR501 Infrared Sensor it is super easy to do as well!
Check out PCBWay here: https://pcbway.com/g/2Zlh7L
Link to Motion Detection Sensors used: https://amzn.to/4b4LLmN
GitHub link to simple code and Sting code: https://github.com/plemaster01/ArduinoMotionDetect
Don't forget to leave a like on the video, subscribe to the channel and comment what you want to see more of next!
If you love the channel consider becoming a supporter on Patreon!
https://www.patreon.com/LeMasterTech
welcome back to the MasterTech and in
today's video I'm going to show you how
to do motion detection with Arduino or
Raspberry Pi or any other
microcontroller I'll start with some
basic wiring and code examples to show
how to use motion detection and then at
the end I'll show you how I built this
cool motion detecting glowing blue sting
sword replica from Lord of the
[Music]
Rings so motion detection is obviously a
super fun technology with a very wide
range of applications that hobbyists and
makers might want to incorporate in
their builds and then on the
professional side of things
incorporating motion detection into
things like automatic lights and other
Smart Systems around the house is
becoming more and more common and one of
the core pieces at the center of builds
like this is the infrared motion
detection sensor often called a p sensor
and this specific chip and module is
called the hcsr
r501 motion detection sensor don't worry
about memorizing the numbers I'll leave
a link to the one that I'm using here in
the description of this video and
they're just a few dollars for pretty
high quality pretty well functioning
sensors and the way the sensor works at
a very broad level is it casts an
infrared cone to detect Motion in front
of it going outward from this kind of
ball that's on the end of it and then
there's actually a fair bit of
functionality baked into the chip where
the entire connection between your
infrared sensor and your Arduino or
microcontroller is just three wires a
5volt signal a ground signal and then a
digital output that just reads high or 5
volts energized when motion has been
detected and then low zero no volts not
energized when motion goes away and the
settings that you get to play with on
the sensor are actually just as
important as knowing how to incorporate
this into the microcontroller so I'm
going to talk briefly to you about those
starting with these two dials that come
on the sensor they can be adjusted with
a terminal screwdriver or another small
tool and one knob is for the sensitivity
or essentially how far out that cone of
infrared sensing is going to be
projecting from the tip of the sensor
and then the other knob is the time
delay knob which is your setting to
determine how long after detecting
motion you want the signal to stay
energized so on the very short end this
can go away after just basically 1
second and on the long end it can be
several minutes sensor to sensor these
ranges do change a little bit and then
the other super important thing to talk
about on the sensor itself is the
triggering mode and that's these three
metal pins that usually come with a
two-prong trigger already on two of the
pins and if it's on the top two pins as
you're looking down at the dials and
you're in single trigger mode and in
single trigger mode it doesn't matter if
the sensor keeps detecting motion once
it's already detected motion it's going
to wait out until the time delay knob
tells it it's done and then there's
going to be a couple of seconds of
buffer time before it can detect motion
again and turn the output on again so if
you were using this to turn the lights
on in a room and then stay on for 5
minutes it doesn't matter if motion was
detected again during that 5 minutes at
the end of the 5 minutes the lights are
going to turn off and then you'll have
to wait a second before they come back
on which is obviously not ideal for
every project so that's why the bottom
two pins if you move the jumper down
there put it into multi-trigger mode or
repeat trigger mode and in repeat
trigger mode it's basically the opposite
of single trigger mode which is you can
repeatedly send Motion in that infrared
cone and as long as it sees motion
before the timer lets out it could stay
on forever so this is obviously more
ideal for things like motion detector
lights but again not perfect for every
scenario and these settings are easy to
change locally on the sensor and they'll
be different for every project that you
want to build so feel free to play
around with those settings a little bit
because the code and the wiring into
your microcontroller couldn't be much
simpler so as I said before 5 volts and
ground are two of the three pins and I
don't even actually need an Arduino at
this point I'm just using it because
it's a good example of a 5volt power
supply but I have the output wire for
this first example going straight to the
positive leg of an LED which is then
grounded back to the Arduino but what
you can see is I can just trigger motion
on the infrared sensor and I can get the
LED to turn on without any code written
so far and this is actually a great
point for you to pause with your project
to understand the two dials and the
trigger mode pins a little bit better
before diving into any code or anything
that makes it more complicated but
obviously not everything that you would
want to do with motion detection can be
boiled down to just using the output pin
to turn an LED on and off so when you do
want to pull it into the Arduino you
don't even need a special Library it's
just a digital input that is going to
read 5 volts when it's been triggered
and Zer volts when it hasn't so the most
basic version of a code that basically
does exactly what our hardwired example
does would be this and this is code that
reads an input from the motion sensor
just like we just had and then writes an
output to the LED just like we just had
but now we've used an Arduino to be the
basic interface between the two again
this isn't that exciting yet but it does
show basics of how to use motion
detection with a microcontroller and
then the only limit to how creative you
can get from that point onward is your
ability to write some decent code and
build an interesting physical project
and this is a great time to talk to you
about the sponsor of today's video PCB
way PCB way is one of the top
manufacturers of printed circuit boards
and PCB assemblies for hobbyists and
makers in addition they have great 3D
printing and metal prototyping Services
a super friendly and responsive support
team great turnaround time and super
high quality builds so be sure to check
them out at the link in the description
of the video thank you to PCB way for
sponsoring the video and one of the
things that I love so much about the
online maker Community is how many
incredible highquality 3D printable
files there already are for free out
there like this awesome sting replica
sword that I was able to find from The
Lord of the Rings and Hobbit movies and
so all I had to do was do a little bit
of 3D modeling and design in the
background to build a bracket that could
hold my sword for display and have some
embedded neopixel RGB lights in the
background and a motion detection sensor
on the bottom so that anyone who comes
near would make the blade glow blue just
like it would when goblins were near in
the movies so is that a nerdy example
maybe but you clicked on how to use
motion detection with an Arduino so I
figure you'll appreciate it okay and
that is going to do it for today's
tutorial I hope you found it useful if
you have any questions or comments or
want to let me know what you want to see
more of on the channel be sure to like
let me know in the comments below thank
you so much to my patreon supporters as
well as everyone who leaves likes on the
videos and subscribes to L Tech good
luck with all of your projects and
thanks for watching we'll see you next
time thanks bye
