 See that tiny thing right there on the screen that little module right here that I'm playing with with my fingers That's a photo interrupter module and we're going to go over that today And I'm going to show you everything from how it works to how to actually use it in a practical environment If you don't know any code at all or you don't understand electronics at all This is exactly the type of video for you if you do understand that stuff You'll be able to skip over some of the basic explanations that I'll go through But this video is really meant for people who just want to get started But don't know how hope this video helps you out And if it does please do give us a like and maybe subscribe to the channel if you want to see more So the way this module works is it has this u-shaped item in the front And what happens is light goes out from one side and light comes in through the other and it has this Circuit of light and the second the light is being dimmed or being extended or anything like that It throws that value into the computer and we can use that to decide if we think something's blocking the u-shape so if I was to go and take this piece of plastic and shove it right between The two sides of the center like this We should get a lower value of light because I'm actually blocking it like physically blocking it in between the u-shape So it should be recording that and sending that to us And then we can use that to decide if we want to do something Typically this type of technology is used in garage doors and things like that where they have a laser going from one side of the Door to the other and if you cross in front and lower the amount of laser that's touching the sensor It's going to decide that oh shit something might be in front of the garage door We should stop closing the garage door and retract it all the way out Here's a little video explaining what that looks like when the safety reversing sensors are misaligned The door will not close from the remote control and the garage door opener lights will flash Locate the receiving sensor which has a green LED The receiving sensor LED will be off dim or flickering Indicating the sensor is out of alignment when the receiving sensor LED is properly aligned it will glow steadily now We don't have an exact use case for this video, and I'm not going to go and build a whole machine Let's say like a 3d printer and tell it hey when the 3d printing tool is reaching its end You should tell it that this is the end what you're going to need is three cables I like to color code my cables so one power one ground and one signal an Arduino and an Arduino power cable Once you got those let's put everything together We got our sensor itself if you look at your sensors they always have symbols so here we have a minus and an s telling us It's a ground power in the middle and then signal on the end. So we're going to go and grab our Black cable and plug it into our ground and take our red cable and plug it into our power And then we're going to take our signal wire and plug it into the last signal port Now all we got to do is wire these three to our Arduino The way our dwinos work is you have power outputs ground inputs And then you have a bunch of inputs and output ports all over the board But you have some that have a next to them and some that just have a Line or nothing next to them the difference between these two is these are analog and these are digital Analog give you a lot more Detail in the response. So it'll tell you a number between zero and a thousand Comparing to digital which usually gives you like a zero or one So the first thing we're going to do is plug in into our five-fold which is right here We're going to plug into the ground which is right next to that And then we're going to plug this into our a zero since it's the first analog input Make sure everything's plugged in properly and always check this to make sure it's plugged in as well Check that s is the first one power and then ground and now you're good to go All you got to do is plug in your Arduino to your Arduino power cable and Then send that off into a USB port on your computer You should see that the Arduino flashes a couple times. That's meaning. It's actually connecting to your computer Your sensor should not have a light on it because it's not being turned on But when it is turned on it might have a light on it This one does not have an LED on it and now we're good to go on the computer and write some code when it comes to Writing code for arduinos. I tend to use the Arduino IDE. I know it's white theme I'm pretty sure I could change it but doesn't matter and This is probably the easiest program you can use when you're first starting off You can go and use other editors that you usually use for other types of development. This one works really well Inside every Arduino program you have a setup and a loop function These are this is how an Arduino works The first thing it does is set up a bunch of things and then it loops over and over and over Endlessly until you turn it off or tell it otherwise the first thing we're going to do is declare what port our Photo interrupter is being plugged in on which we as we showed earlier was a zero So we're going to just write that out quickly I'll just call it PI for photo interrupter and then we'll put a zero and go on the next line, which is where we're going to put a variable called Value you don't have to do this You can just print out the value straight out from when we look for it But I like to do this in case I want to use it somewhere else in my program It's just a good habit to have then in our setup We have a couple things to do first thing we have to do is set up our console So this isn't too complicated. You don't have to focus on this too much But setting up your serial dot begin pretty much tells the computer Hey when something happens or when I ask you to print something out, this is where you're going to print it So usually I just go to 9600 And that's it all we have to do right there Then our loop, which is the easiest but most important part we have to grab our value and set it to Analog Read and then the port we're using which in this case is already in a variable So we just put PI you could also just put a zero here and not do the original Value at the top after that we're going to do serial Print line which is just going to print on a line for us And we're going to tell it to print out the value. We just grabbed From the analog read for a digital module you would just use digital read for analog modules use analog read It's just telling it what kind of port it is and how to read it Then the last thing is we want to add a delay. So we're just going to do delay 50 This is 50 milliseconds long if you edit a thousand it'd be one second long And we're just going to verify it compile it make sure it works We don't got any errors. So we're good. Then we go and upload it and We uploaded it. So it seems uploading. I actually have an issue. It's stuck on loading So if you go to tools board, you should be choosing the board you have I have an Arduino Uno and then for port you should be choosing the one where your aduino is plugged in and it actually tells Me that our aduino is plugged in on six. So I'm just going to click on six I'm going to compile it and upload it again. And there we go. It worked Now if you go again tools serial monitor You'll open up this window right here where you'll see a bunch of numbers printing out These are the values every 50 milliseconds from our sensor. Now if we actually grab our sensor and Take a material which I have four different ones. I got plastic Tube types of paper and metal. Let's start with the thinnest paper Take that stick it in the middle keep an eye on the values They just went up like crazy. Look at that 940 930 all the way up there. Let's grab a different Now we're at 700. So the first paper seemed to block light easier than the second one here We got a nice stick of plastic Again this wow the paper was actually Less transparent than a piece of plastic and then the last one is a big piece of metal Which I want to make sure I don't touch on the terminals and look at that This one's obviously going to block the most with literally the highest number we can get to a thousand thousand something thousand 20 whatever it is So this shows you how this sensor works It's got again a u-shaped gate when something goes in between the gate like this big metal piece here We could see that light is being blocked and it's showing us a value in the console Now if we wanted to we can use that to activate an LED we can use it to open a garage door We can use it to do whatever we want. Hopefully you guys got a good explanation here of how to use this sensor and how everything works If you have any questions, please, please, please do comment below or hit me up in discord I'm always up to help people out I can't spend 10 hours with you But I can always answer a couple questions that you got or we got a bunch of cool people in discord Who can help you out as well? If you enjoyed this video give it a like maybe subscribe to the channel And we'll see you in tomorrow's stream