on today's makers mashup we're doing motion tracking with an esp32 cam
welcome back makers i wanted to do an animatronic project for halloween where i was tracking motion
left and right as someone walked across in front of my yard now the difficulty i had was using
these pir sensors or maybe these ultrasonic motion sensors these devices really don't have a very
good range when you look at something as large as your yard and i ran some initial tests indoors
and these worked really great but my experience outdoors was less than consistent
now i've used these esp32 cams before it's a great little microcontroller if you've never used one
that has an onboard camera it's got wi-fi it's got bluetooth 240 megahertz processor it's even got
an sd card slot on it and while the camera itself is really nothing spectacular it does work really
well for low cost maker projects and they'll only run you about ten dollars i've used them
for network based webcams before for octoprint and i've got a card at the top that will get you
to that video if you want to see another project that uses these esp32 cams now with the es32 cam
we've had motion detection on it for some time and what i wanted to do was more than just simple
detection i wanted to be able to track motion across the field of view and then i wanted to turn
an animatronic character left or right where the person or object that was detected in the field
of view was so today we're going to be working on using this esp32 cam some inexpensive toy stepper
motors to track a person across that field of view and this project is simple to assemble and
as always it's open source so you can modify the models or the source code to fit your projects
so with all that said let's get to work eloquent arduino gave me the groundwork for this project
modifying their code i was able to take a camera frame and squish the data down
to an array of detection points so anything that was on the vertical axis became a value
in the horizontal array from there i broke down the values into 10 degree segments
which are assigned a value based on the amount of movement from one frame to the next this
indicates where the most activity or motion exists in the field of view
then we move the stepper to that location this sounds really complex but the source code is small
given the number of operations taking place i want to also give a shout out to reader
alan our discord who helped me noodle out some of the math to make all this happen
if you're not a member of our channel discord you can find links for that in the description
it's absolutely free and a great resource for any maker project you're working on so now that i had
a working sensor i had to build an enclosure for the esp32 cam and hook up some steppers
installing the esp32 is a piece of cake all we have to do is press it into the 3d print
now we'll need to install the electronics into the stepper enclosure
we've got one stepper driver the usb power connection
dupont terminal block this allows us to easily connect everything without soldering
now we're going to install the stepper driver all that's necessary is running
two leads from the positive and negative on the driver to the terminal block positive and negative
now we're going to run our input power from the usb to the terminal block
now we'll install our wiring that goes to the esp32 we'll need to hook up the positive
and negative to the terminal block and then the four other wires to the stepper driver
which will connect back to our esp32 be sure to remember the order that you have these wired in
they'll have to go in the same order on the esp32 with the exception of swapping the last two around
and that's due to the pin outs on the esp32 itself
now we're going to feed in our stepper driver wire and attach it to the stepper driver
now we need to hook up our usb power
now that our wiring is complete we're going to attach the lid and secure it with an m3 screw
now we'll feed the wires running to the stepper through this 3d print which will hold the esp32
i tied a knot in the signal cable to make sure that it doesn't pull back through the
3d printed part and disconnect from the esp32 this is pretty simple we'll start with the power
pin and the ground then we'll lay these out in the exact same order that we did on the stepper
with the exception of switching the last two in my case it was the green and the purple now that
our wiring is complete we'll insert this into the 3d printed part and secure it with some m3 screws
the stepper mount just pops on top and then is secured with some m3 screws
now we'll install the top plate
here we have our assembled project and this enclosure over here holds the esp32 cam
the stepper is in this base here and the rest of the electronics are right here now i want to
illustrate how this works so what's happening right now is that we have the camera looking
at the entire field of view and if i move my hand here to just catch the edge of the detection range
you'll see here that the skull points over to that direction and if i just catch the edge of the
detection range over here it will turn its head over to this side over here now if we wanted to
have something that's maybe moving in the middle and i catch that right here you can see the head
is going to then turn to the middle and now that we've got all this working let's go give this a
try out my yard now i used an inflatable for this and i used some magnets and some monofilament
line on the top and then some magnets and the plastic plate on the bottom to hold everything
in place but as you can see when someone walks in front of the camera the eye tracks their movement
now many of you may be thinking rob this project won't work at night
well i do have a fix for that what i've got here is an ir illuminator or an infrared flood light
and these run about thirty dollars they will flood an entire area with infrared light that the camera
is then able to pick up security cameras have used this but it allows you to work on this project
and then be able to use it at night now overall this project was really easy to put together and
honestly something you could probably knock out in a weekend the esp32 in my opinion this project
makes it a great alternative to other motion sensors and the small size really allows you
to put this in just about any location and with just a little bit more code you could
instead of just detecting motion either take a picture and upload that to a server or
you could uh use the onboard sd card to store everything now previously when i've used these
i had to buy a separate programmer but now they're including these shields
that allow you to just snap into place and then program with a regular usb cable and it just
makes the entire process that much simpler so with that is going to bring the end of today's
video if you liked it make sure you mash that like button and don't forget to share and subscribe so
you don't miss any of my upcoming videos now if you would like to help support the channel
consider checking out my patreon page or purchasing any of your parts from the links
down in the description below all of which help support the channel to produce future
videos so with that i want to say thanks again for watching we'll see you next time