Placeholder Image

字幕列表 影片播放

  • please go to the line the computer guy dot com In order to view schematics, code and Maur for the projects that you are learning about, welcome back.

  • So in today's a video, I'm going to show you how to connect a p i.

  • R a passive infrared sensor to an Arduino and be able to measure when it detects motion.

  • So when you hear about P I.

  • R.

  • Sensors, these air generally called motion detection sensors in the real world.

  • And so basically, these sensors are a lot like the automatic lights security lights that you may have in your house.

  • So maybe on your garage or in your backyard, you have some big flood lights.

  • And under the flood lights is a little motion detector.

  • That motion detector is a P I.

  • R.

  • Sensors, so you can use a P I.

  • R sensor in order to detect movement within its range.

  • And then we can then trigger the art we know to do something.

  • So today, all we're going to be doing is we're going to be connecting the P I R sensor to the yard.

  • We know, and then we're going to be detecting when it sees motion and then simply printing out to the serial monitor that it sees motion.

  • So with that, let's go over the work, bitch.

  • So I can show you how to connect this to an Arduino, that I can show you the code and see how it all comes together.

  • So here's our little project for today.

  • So I have the P i.

  • R.

  • Sensor and this is connected to our standard.

  • Aren't we know?

  • You know, board and we don't have anything else connected because we're simply going be printing out the results to serial monitor.

  • Now, when you're sitting here looking at this, you may run into a problem where you're not sure where the wires should go.

  • So we have a ground we had a five volt.

  • But then you may be asking yourself, I don't know where the sensor wire plugs and to the P I.

  • R.

  • Well, all you have to do is actually just pop off this little housing here.

  • And if you pop off the little housing on this particular unit, you can see that ground is over here to the left, the output.

  • So that's a sensor output.

  • That's what we'll go to the digital pin is in the middle and then VCC is over to the right.

  • So if you get a P I R.

  • Sometimes the P i r.

  • The markings are on the back of it.

  • And then other times, basically all you have to do is peel off the cover and you'll see Okay, ground is to the left.

  • The sensor output is in the sensor in the center and in the V C.

  • C is over to the right.

  • So that's all you do again.

  • We got plugged into five old we gotta plug it into ground, and then we have the censor censor pen and that is plugged into digital pen number eight on this are you know, and that's all you have to dio to assemble this particular project.

  • So here's a coat for this project.

  • The first thing that we have to do is define the sensor pennants we're going to do pound and define.

  • And then I'm just simply going to call a p I R Sensor and attack that to digital pin number eight.

  • Then we're going to need a variable for the readings.

  • So basically, we're going to take a reading off of the P I.

  • R Sensor.

  • We need to store that value somewhere.

  • So we're going to create a variable call reading, and that is simply going to be an end.

  • Then we're going to go down and we're going to set up the environment.

  • So the first thing that we're going to do to set up the environment is we're going to use PIN mode.

  • We're gonna call P I R Sensor and we're going to set it to input.

  • So it's important.

  • Remember, whenever you're dealing with digital pens, it can be input or output output sends energy out.

  • Input receives readings.

  • So we need to make sure that's that input.

  • And then, of course, we're going to do cereal that began at 9600.

  • So this starts the serial monitor so that we can receive an output from the Arduino.

  • Then we're gonna go down.

  • We're simply going to go into the loop, and this is all the code we have.

  • So that reading a variable that were created, we're going to set the value of that to digital read function.

  • So this is a function digital read.

  • We're going to read what is coming in on the P I r Sensor so way bring in what's coming in on the P I.

  • R Sensor and we're going to set that value to the variable reading.

  • Then we're going to go down and we're simply going to do and if else statement.

  • So if reading.

  • And then we have equal equal signs so equals Hi.

  • So, basically, if the reading coming in from the minute motion detector is high, then we're going to serial dot print line.

  • We're simply going to say motion, so it's gonna print on a line motion and then go to the next line else.

  • So basically, if the reading is anything else, which would be a low, we're simply going to serial parent line zero.

  • So what'll happen is basically we're see.

  • We're seeing the stream go across a serial monitor when there's emotion.

  • Then we'll see that there's emotion, and then when there's not emotion, then it will go back to zero.

  • So this will give us kind of kind of a visual way of understanding when there's emotion and when there's not.

  • Now it is important, understand when you're using the P I.

  • R.

  • Sensors that you've only got high or low as faras.

  • The detection goes.

  • So a lot of the other sensors, when you're talking about the the ultrasonic, distant sensors, sometimes the infrared sensors you can actually bring in an analog value so you can get a variable so you can figure out like how far away something is.

  • You can get a little bit more information out of it.

  • One of things that you find with P.

  • I.

  • R Sensor is that either detects motion or doesn't detect motion.

  • Don't ask it anything else.

  • It is simply an on off sensor on DSO.

  • That's something that you have to be thinking about with your projects is it's a very, very crude sensor.

  • And so that may be good and things like turning on floodlights something like that.

  • But in other operations, you maybe you may want something that's a little bit more accurate, something that you can refine a little bit more.

  • So this is all the code that's required.

  • So let me upload this code into the yard.

  • We know and we'll show you how it works.

  • Okay, so I plugged in the artery.

  • No, I've uploaded the code, and I've also let the motion sensor, the P I.

  • R Sensor warm up for a little bit.

  • That's one of the quirks with the P I.

  • R Sensors is many times it actually takes a little while for their circuitry to warm up for them to do what they're supposed to.

  • D'oh.

  • So I would say, Whenever you're doing these projects, let the sensor warmup for atleast a minute before you start troubleshooting problems with your code.

  • It is very interesting again.

  • Ultrasonic sensors, infrared sensors, literally.

  • As soon as you plug them in, upload the code and they're working at No problem with P.

  • I.

  • R.

  • Sensors really, honestly, let them warm up for a least a minute because until they're warmed up, you're probably not going to be getting readings that are worth anything.

  • So with that, let's go over.

  • Go to tools.

  • Let's go to serial monitor and see what we got.

  • Okay, so we just got a stream of zeros right now, so it's not detecting any emotion.

  • I bring my hand down a detective motion.

  • There you go to text motion.

  • Stop detecting motion, detects motion stop to take it, and that's what you notice, right?

  • It's not infrared It's not detecting my hand, see, because right now my hand, my hand is right in front of it.

  • But it's not moving, so it's not detecting the hand.

  • It's actually detecting the motion.

  • So this is something to be thinking about when you're creating the code is it will only detect when there's motion when they're stops being motion.

  • Then it will stop detecting anything.

  • So this is where you're going to have something long like some kind of physical event happened.

  • You probably want a timer so that the timer will go off for 30 seconds or a minute, something like that, because think about it this way.

  • If you created a motion detection light that literally only turned on when the sensor detected movement, then somebody would move.

  • It would turn on.

  • They stopped moving, it turns off, they move, it would turn on.

  • Then they stopped moving and turn off.

  • So that's kind of thing that you have to think about with the code and the other thing that you will notice again with these P I R sensors because they have a good range.

  • Overall, they have a good distance, but they're not.

  • They're not the most accurate sensor you're ever going to deal with.

  • And so there you are.

  • That's an overview of a P I.

  • R.

  • A passive infrared sensor for the Arduino again, these were basically the good old generic she motion motion detection sensors.

  • So the good part about the sensors is they give you a good area of coverage.

  • They're pretty easy to use and may be able to implement into a project.

  • The bad thing about these sensors is that they're kind of just keep crappy sensors right again.

  • Think about it if you have.

  • If you have some kind of security light around your house, you know that these aren't the greatest sensors in the world for detecting motion.

  • Sometimes you'll walk right in front of it, and it doesn't detective.

  • Other times it goes spastic over leaves blowing in the wind, right?

  • So that's something that you have to think about with using one of these kinds of sensors.

  • So if you're looking for like a generic thing like again, like turning on lights, it's a motion detection for turning on lights.

  • That might be a valuable thing, maybe creating some kind of heat maps.

  • So so attaching this to a networked aren't we know?

  • And so being able to detect when people walk by an area and then be able to create a heat map?

  • So you know what?

  • Areas of your facility are being used more than others doing those types of things?

  • I think the P I R sensors make a lot of sense.

  • If you're doing anything where, like security really is important, accuracy is important.

  • Safety is important, that type of thing.

  • I would honestly look at using a different type of sensor.

  • I would probably say something like the ultrasonic distance sensors using an array of ultrasonic distance sensors, I think would probably give you better, more accurate results that one of these little guys.

  • But if you're just looking for a generic little motion sensor, this is definitely a little graphic in Eric Motion sensor For a dollar or two.

  • You could throw this into your project on.

  • You'll do pretty well.

  • So that's really all there is to these P i r sensors again you can you can attack this to an Arduino board and have you heard, we know attached to a relay again to be you have a turn on lights, that type of thing.

  • And so you can think about those types of projects when you're looking at the P I.

  • R.

  • Sensors.

  • As always, I enjoy doing this video and look forward to seeing it the next class.

please go to the line the computer guy dot com In order to view schematics, code and Maur for the projects that you are learning about, welcome back.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

Arduino上的PIR傳感器(HC-SR501) (PIR Sensor on Arduino (HC-SR501))

  • 1 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字